我正在尝试构建一个用于异常检测的ARIMA.我需要找到时间序列图的移动平均线我试图使用pandas 0.23
import pandas as pd
import numpy as np
from statsmodels.tsa.stattools import adfuller
import matplotlib.pylab as plt
from matplotlib.pylab import rcParams
rcParams['figure.figsize'] = 15, 6
dateparse = lambda dates: pd.datetime.strptime(dates, '%Y-%m')
data = pd.read_csv('AirPassengers.csv', parse_dates=['Month'], index_col='Month',date_parser=dateparse)
data.index
ts = data['#Passengers']
ts.head(10)
plt.plot(ts)
ts_log = np.log(ts)
plt.plot(ts_log)
moving_avg = pd.rolling_mean(ts_log,12) # here is the error
pd.rolling_mean
plt.plot(ts_log)
plt.plot(moving_avg, color='red')
error:Traceback (most recent call last): File “C:\Program
Files\python36\lastmainprogram.py”, line 74, in
moving_avg = pd.rolling_mean(ts_log,12) AttributeError: module ‘pandas’ has no attribute ‘rolling_mean’
解决方法:
我认为需要改变:
moving_avg = pd.rolling_mean(ts_log,12)
至:
moving_avg = ts_log.rolling(12).mean()
因为老熊猫的版本代码低于pandas 0.18.0
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。