Error in code for Time Series Forecast (in Python)

time_series

#1

Hello I am read the article below:

Time Series Forecast (with Codes in Python)

When I am trying to the same code on my spyder or jupyter I am getting the same error when I run the function
from statsmodels.tsa.stattools import adfuller
def test_stationarity(timeseries):

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

#Plot rolling statistics:
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

File “”, line 1, in
runfile(’/Users/apple/Python/Job_Exer/TS_test/TS_test.py’, wdir=’/Users/apple/Python/Job_Exer/TS_test’)

File “/Users/apple/anaconda/lib/python3.6/site-packages/spyder/utils/site/sitecustomize.py”, line 866, in runfile
execfile(filename, namespace)

File “/Users/apple/anaconda/lib/python3.6/site-packages/spyder/utils/site/sitecustomize.py”, line 102, in execfile
exec(compile(f.read(), filename, ‘exec’), namespace)

File “/Users/apple/Python/Job_Exer/TS_test/TS_test.py”, line 106, in
test_stationarity(data)

File “/Users/apple/Python/Job_Exer/TS_test/TS_test.py”, line 100, in test_stationarity
dftest = adfuller(timeseries, autolag=‘AIC’)

File “/Users/apple/anaconda/lib/python3.6/site-packages/statsmodels/tsa/stattools.py”, line 220, in adfuller
xdall = lagmat(xdiff[:, None], maxlag, trim=‘both’, original=‘in’)

File “/Users/apple/anaconda/lib/python3.6/site-packages/statsmodels/tsa/tsatools.py”, line 375, in lagmat
nobs, nvar = xa.shape

ValueError: too many values to unpack (expected 2)

Any idea why?

I would like to thank you for your time