Reputation: 1
sp500['42d']=np.round(pd.rolling_mean(sp500['Close'],window=42),2)
~\Anaconda3\lib\site-packages\pandas\__init__.py in __getattr__(name)
212
213 return Panel
--> 214 raise AttributeError("module 'pandas' has no attribute '{}'".format(name))
215
216
AttributeError: module 'pandas' has no attribute 'rolling_mean'
Upvotes: 0
Views: 188
Reputation: 184
You can use rolling()
followed by mean()
import numpy as np
import pandas as pd
df = pd.DataFrame(np.random.randint(0,100, size=(100, 1)), columns=['close_price'])
df['rolling_mean_42d'] = df['close_price'].rolling(window=42).mean()
df
Please change your question title to highlight 'rolling mean in pandas'
Upvotes: 1