Reputation: 128
I have data:
date count
2015-09-01 5
2015-09-02 4
2015-09-03 8
2015-09-04 8
2015-09-05 3
2015-09-06 5
2015-09-07 9
2015-09-08 7
2015-09-09 5
2015-09-10 7
...
I need to get moving average over the last 5 days.
How can I do it on python and pandas?
Upvotes: 1
Views: 1000
Reputation: 393973
IIUC you want rolling_mean
:
In [136]:
df.set_index('date', inplace=True)
pd.rolling_mean(df['count'], window=5)
Out[136]:
date
2015-09-01 NaN
2015-09-02 NaN
2015-09-03 NaN
2015-09-04 NaN
2015-09-05 5.6
2015-09-06 5.6
2015-09-07 6.6
2015-09-08 6.4
2015-09-09 5.8
2015-09-10 6.6
dtype: float64
Upvotes: 4