Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
146 views
in Technique[技术] by (71.8m points)

python - NameError: name 'timseseries' is not defined

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,'
')

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

question from:https://stackoverflow.com/questions/65836048/nameerror-name-timseseries-is-not-defined

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
rolmean = timseseries.rolling(window=9).mean()

It's timeseries.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...