#find rolling mean of previous 5 sales periods
df['rolling_sales_5'] = df['sales'].rolling(5).mean()
#view first 10 rows
df.head(10)
period leads sales rolling_sales_5
0 1 11.427457 61.417425 NaN
1 2 14.588598 64.900826 NaN
2 3 12.452504 66.698494 NaN
3 4 11.352780 64.927513 NaN
4 5 9.049441 73.720630 66.332978
5 6 13.271988 77.687668 69.587026
6 7 9.314157 78.125728 72.232007
7 8 17.943687 75.280301 73.948368
8 9 19.309592 73.181613 75.599188
9 10 8.285389 85.272259 77.909514
ddf.groupby("x").rolling("1h", closed= "left")["y"].sum()