Consider in a data frame I have the following values:
Date,Value
2017-01-01,1
2017-01-02,2
2017-01-03,3
2017-01-04,3
2017-01-05,2
2017-01-06,2
...
2017-01-31,30
So after reading them to a data frame, I would like to create a dataframe with the 5-day lagged average. That means for 2017-01-05
the reading is 2.2 and for 2017-01-06
the reading is 2.4. Other than looping, is there an easier way to do so? Let's say
df = pd.DataFrame.from_csv("data.csv")
for i in range(4, len(df)-5):
sum_df = df[i:i+4]
...