当日期列中的“月份”相同时,获得累计数据值的最佳方法是什么?这可以使用 resample() + sum() 来完成吗?
我想我可以在 python 中使用现成的东西而不是创建自定义函数。
想要:
Input:
Value
Date
2015-01-01 1
2014-01-01 2
2017-03-01 3
2015-04-01 4
2016-03-01 5
Output:
Value
Month
January 3
March 8
April 4
谢谢!
最佳答案
我更喜欢使用 index.month_name
的更直接的方法:
df.groupby(df.index.month_name()).sum()
关于python - 同月累计,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70444466/