from statsmodels.tsa.stattools import adfuller
def test_stationarity(timeseries):
#Determing rolling statistics
rolmean = pd.rolling_mean(timeseries, window=24) # 24 hours on each day
rolstd = pd.rolling_std(timeseries, window=24)
#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)
from matplotlib.pylab import rcParams
rcParams['figure.figsize'] = 20,10
test_stationarity(train_original['Count'])
Asked
Active
Viewed 1.1k times
-2

martineau
- 119,623
- 25
- 170
- 301

Aashay Bane
- 11
- 1
- 1
- 1
-
2Could you please elaborate on what the problem is and what you've tried so far? – HermanTheGermanHesse Oct 05 '18 at 13:02
-
1Might want to check out the how to ask a good question faq.: https://meta.stackexchange.com/help/how-to-ask – tnknepp Oct 05 '18 at 13:07
-
What version of pandas you are using? – Karn Kumar Oct 05 '18 at 13:27
-
pd.__version__ Out[3]: '0.23.0' – Aashay Bane Oct 05 '18 at 19:52
3 Answers
4
I'm going to assume that the title error should be AttributeError: module 'pandas' has no attribute 'rolling_mean'
as I believe it was deprecated and then removed. Also, pd.rolling
is not in the provided code. In which case you SHOULD use rolling
. Assuming timeseries
is a pd.Series
:
def test_stationarity(timeseries):
#Determing rolling statistics
rolmean = timeseries.rolling(window=24).mean() # 24 hours on each day
rolstd = timeseries.rolling(window=24).std()

Ian Thompson
- 2,914
- 2
- 18
- 31
-
Why did you import adfuller from statsmodels.tsa.stattools, if you're not using it? – Marlon Henrique Teixeira Jun 26 '20 at 15:52
-
1@MarlonHenriqueTeixeira Probably out of laziness when I copied the `def` line. I'll remove it to avoid confusion – Ian Thompson Jun 26 '20 at 16:09
1
Try doing conda install -c conda-forge statsmodels, based on the earlier syntax, the adfuller was not recognized by the notebook.Then try pip uninstall pandas and do pip install pandas. For similar cases, may try the instructions in the link Numpy is installed but still getting error

Navi
- 11
- 1
0
from statsmodels.tsa.stattools import adfuller
def test_stationarity(timeseries):
#determine rolling statistics
rolmean = pd.Series(timeseries).rolling(window=24).mean()#24 hours on each day
rolstd = pd.Series(timeseries).rolling(window=24).std()
#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 and standard deviation')
plt.show(block = False)
#perform dickey fuller test
print('result of dickey fuller test:')
dftest = adfuller(timeseries,autolag = 'AIC')
dfoutput = pd.Series(dftest[0:4],index = ['Test statistics', 'p-value', '#lags used', 'number of observation used'])
for key,value in dftest[4].items():
dfoutput['critical value (%s)'%key] = value
print(dfoutput)
from matplotlib.pylab import rcParams
rcParams['figure.figsize'] = 20,10
test_stationarity(train_original['Count'])

Darshika Verma
- 81
- 1
- 8