I'm trying to calculate rolling sum for a winows of 2 days for the Income column considering client ID & Category column wise.
import pandas as pd import datetime as dt table = pd.DataFrame(data = {'ClientID':[100,100,100,200,100,200,100,100,100,100], 'Date':['2017-10-01 13:11:24','2017-10-01 15:11:24','2017-10-02 09:11:24','2017-10-04 11:11:24','2017-10-04 13:11:24','2017-10-06 15:11:24','2017-10-06 13:11:24','2017-10-08 11:11:24','2017-10-08 13:11:24','2017-10-08 13:11:24'], 'Category':['A','A','A','B','A','B','A','A','A','B'], 'Income':[800,900,1000,900,1000,800,400,400,900,1000],},) table['Date'] = pd.to_datetime(table['Date'])So far i managed to calculate only a cumulative daily total of Income for the Client ID & Category grops.
# Client ID & Category wise daily cumulative total of Income table['Cum_Income'] = table.groupby(by = [table['ClientID'],table['Category'],table['Date'].dt.date]) ['Income'].cumsum()Highly apreciate if someone can help me to calculate rolling sum of Income column for a window of 2 days for the Client ID & Category groups.