开发者社区 问答 正文

时间序列数据帧。用相对起点绘制两个不同的时间范围

我有一个包含时间序列的数据框(单个股票的每日价格)。我想采用两个不同的时间范围,并将它们叠加在绘图上,相对起点为0而不是日期。

在下面的示例中,如果我绘制1962和2018,它将日期用作x轴而不是相对起点。

SPY = pd.read_csv('GSPC.csv', parse_dates=['dDate'], index_col='dDate')

SPY1962 = SPY['1962']
SPY2018 = SPY['2018']

firstprice62 = SPY1962['nAdjClose'].iloc[0]
firstprice18 = SPY2018['nAdjClose'].iloc[0]

normal62 = SPY1962['nAdjClose'].div(firstprice62).mul(100)
normal18 = SPY2018['nAdjClose'].div(firstprice18).mul(100)

展开
收起
一码平川MACHEL 2019-01-22 11:48:30 1695 分享
分享
版权
举报
1 条回答
写回答
取消 提交回答
  • normal18 = normal18.reset_index()
    normal62 = normal62.reset_index()

    normal62['nAdjClose'].plot()
    normal18['nAdjClose'].plot()

    plt.show()

    2019-07-17 23:26:13 举报
    赞同 评论

    评论

    全部评论 (0)

    登录后可评论
问答地址:
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等