how to do forward rolling sum in pandas?
Simple as:
df['B'] = df['A'].rolling(3).sum().shift(-3)
I believe need change ordering by iloc[::-1]
:
df1 = (df.iloc[::-1]
.groupby('A', sort=False)
.rolling(7, on='B',min_periods=0).C
.sum()
.iloc[::-1])