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!
I would prefer a more straightforward approach with index.month_name:
df.groupby(df.index.month_name()).sum()
In your case , this can help you out
out = df.groupby(df.index.strftime('%b')).sum()
output:
Value
Date
Apr 4
Jan 3
Mar 8
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With