當日期列中的“月份”相同時,累積資料值的最佳方法是什么?這可以使用 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
謝謝!
uj5u.com熱心網友回復:
我更喜歡更直接的方法index.month_name:
df.groupby(df.index.month_name()).sum()
uj5u.com熱心網友回復:
在你的情況下
out = df.groupby(df.index.strftime('%b')).sum()
Value
Date
Apr 4
Jan 3
Mar 8
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/389664.html
