0

我正在尝试使用 pandas 和 matplotlib 比较年度支出(9 月到 9 月)。

目前,我基本上使用这种方法(但它只适用于日历年):

pivoted = data.pivot_table(index=data.index.dayofyear, columns=data.index.year, values='expenditure')
pivoted = pivoted.fillna(0)
for year in pivoted:
    plt.plot(pivoted[year].cumsum(), label=f"Year {year}")
plt.show()

很好,我得到了这样的结果(我在上面的代码片段中删除了一些演示代码):

年度支出比较,使用累计金额

我现在要做的,就是有同样的情节,但是从一年的九月开始,到次年的九月结束。

我想知道最好的方法是什么:我尝试拆分数据,例如使用 `data['2017-09-01':'2018-09-01'],然后绘制它,但我缺乏“忘记”关于这一年(只关心这一天)。

关于如何做到这一点的任何提示?

4

0 回答 0