def adf(ts):
# Determing rolling statistics
rolmean = pd.rolling_mean(ts, window=12)
rolstd = pd.rolling_std(ts, window=12)
#Plot rolling statistics:
orig = plt.plot(ts, color='blue',label='Original')
mean = plt.plot(rolmean, color='red', label='Rolling Mean')
std = plt.plot(rolstd, color='black', label = 'Rolling Std')
plt.legend(loc='best')
plt.title('Rolling Mean & Standard Deviation')
plt.show(block=False)
# Calculate ADF factors
adftest = adfuller(ts, autolag='AIC')
adfoutput = pd.Series(adftest[0:4], index=['Test Statistic','p-value','# of Lags Used',
'Number of Observations Used'])
for key,value in adftest[4].items():
adfoutput['Critical Value (%s)'%key] = value
return adfoutput**
上面我创建了计算MA窗口5的函数。但是当我运行下面的代码时,我得到了错误。
df['priceModLogMA12'] = pd.rolling_mean(df.priceModLog, window = 5)**
AttributeError: module 'pandas' has no attribute 'rolling_mean'
https://stackoverflow.com/questions/51728070
复制相似问题