I ended up understanding this by writing out this question, so I will just send a message and answer my question if someone needs a little help.
Problem
Suppose that we have DataFrame
, df
that contain the data.
import pandas as pd
from io import StringIO
data = StringIO(
"""\
date spendings category
2014-03-25 10 A
2014-04-05 20 A
2014-04-15 10 A
2014-04-25 10 B
2014-05-05 10 B
2014-05-15 10 A
2014-05-25 10 A
"""
)
df = pd.read_csv(data,sep="\s+",parse_dates=True,index_col="date")
purpose
For each line, summarize spendings
for each line that is within one month , ideally using DataFrame.rolling
, since this is a very clean syntax.
What i tried
df = df.rolling("M").sum()
But this throws an exception
ValueError: <MonthEnd> is a non-fixed frequency
version: pandas==0.19.2
source
share