时间序列Python

时间:2018-06-06 15:47:27

标签: python pandas

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:模块'pandas'没有属性'rolling_mean'

你可以帮助我吗?

0 个答案:

没有答案