[英]AttributeError: module 'pandas' has no attribute 'rolling'
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'])
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.我将假设标题错误应该是
AttributeError: module 'pandas' has no attribute 'rolling_mean'
因为我相信它已被弃用然后被删除。 Also, pd.rolling
is not in the provided code.此外,
pd.rolling
不在提供的代码中。 In which case you SHOULD use rolling
.在这种情况下,您应该使用
rolling
。 Assuming timeseries
is a pd.Series
:假设
timeseries
是一个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()
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.尝试执行 conda install -c conda-forge statsmodels,根据之前的语法,笔记本无法识别 adfuller。然后尝试 pip uninstall pandas 并执行 pip install pandas。 For similar cases, may try the instructions in the link Numpy is installed but still getting error
对于类似情况,可以尝试链接Numpy is installed 但仍然出现错误中的说明
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'])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.