-3

from statsmodels.tsa.stattools import adfuller def test_stationarity(timeseries):

#Determining rolling statistics
rolmean = timseseries.rolling(window=9).mean()
rolstd = timeseries.rolling(window=9).std()

#Plotting 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)

#Performing 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].itema():
    dfoutput['Critical Value(%s)'%key] = value
print (dfoutput,'\n')

After running the above code, I wrote this

test_stationarity(df['Rose'])

which gave me the error

-
NameError                                 Traceback (most recent call last)
<ipython-input-111-bf44787a5c70> in <module>
----> 1 test_stationarity(df['Rose'])

<ipython-input-108-3ec6841fed27> in test_stationarity(timeseries)
      3 
      4     #Determining rolling statistics
----> 5     rolmean = timseseries.rolling(window=9).mean()
      6     rolstd = timeseries.rolling(window=9).std()
      7 

NameError: name 'timseseries' is not defined

Please help

buran
  • 13,682
  • 10
  • 36
  • 61

2 Answers2

0
rolmean = timseseries.rolling(window=9).mean()

It's timeseries.

i_rutke
  • 11
  • 2
0

First line, you have to change this

rolmean = timseseries.rolling(window=9).mean()

to this:

rolmean = timeseries.rolling(window=9).mean()
southernegro
  • 384
  • 4
  • 20