AttributeError:“ numpy.ndarray”对象没有属性“ rolling_mean”

时间:2018-09-25 09:57:29

标签: python pandas

使用以下代码:

def test_stationarity(ts_values):

    #Determing rolling statistics
    rolmean = pd.rolling_mean(ts_values, window=12)
    rolstd = pd.rolling_std(ts_values, window=12)

    #Plot rolling statistics:
    orig = plt.plot(ts_values, 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)
    #Perform Dickey-Fuller test:
    print('Results of Dickey-Fuller Test:')
    dftest = adfuller(ts_values, autolag='AIC')
    dfoutput = pd.Series(dftest[0:4], index=['Test Statistic','p-value','#Lags Used','Number of Observations Used'])
    for key,value in dftest[4].items():
        dfoutput['Critical Value (%s)'%key] = value
    print(dfoutput)

也完成了必要的导入。

相同的代码适用于pandas 0.23和Python 3.6.4,但是相同的代码在具有Python 3.6.5和pandas 0.23的另一台笔记本电脑中不起作用

感谢您的帮助!

0 个答案:

没有答案