What is the best way to have a cumulative total of data values when the "month" in the date column is the same? Can this be done using resample() sum()?
I'm thinking I can probably use something off the shelf in python instead of creating a custom function.
Want:
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
Thanks!
CodePudding user response:
I would prefer a more straightforward approach with index.month_name
:
df.groupby(df.index.month_name()).sum()
CodePudding user response:
In your case do
out = df.groupby(df.index.strftime('%b')).sum()
Value
Date
Apr 4
Jan 3
Mar 8