时间序列Python

2024-09-28 01:30:40 发布

您现在位置:Python中文网/ 问答频道 /正文

from statsmodels.tsa.stattools import adfuller

def test_stationarity(timeseries):
    #Determinacion de variable estadistica
    rolmean = pd.rolling_mean(timeseries, window=12)
    rolstd = pd.rolling_std(timeseries, window=12)
    orig = plt.plot(timeseries, 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(timeseries, 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)

test_stationarity(ts)

我有这个错误

AttributeError: module 'pandas' has no attribute 'rolling_mean'

你能帮帮我吗?在


Tags: testplotvaluepltmeanlabelcolorpd

热门问题