I am trying to use rolling().sum() to create a dataframe with 2-month rolling sums within each 'type'. Here's what my data looks like:
import pandas as pd
df = pd.DataFrame({'type': ['A', 'A', 'A', 'A', 'B', 'B', 'B', 'B', 'C', 'C', 'C', 'C'],
'date': ['2022-01-01', '2022-02-01', '2022-03-01', '2022-04-01',
'2022-01-01', '2022-02-01', '2022-03-01', '2022-04-01',
'2022-01-01', '2022-02-01', '2022-03-01', '2022-04-01'],
'value': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]})
and here is the expected result:
and here is what I have tried (unsuccessfully):
rolling_sum = df.groupby(['date', 'type']).rolling(2).sum().reset_index()
