Python 3.x 属性错误:';范围指数';对象没有属性';推断频率';

Python 3.x 属性错误:';范围指数';对象没有属性';推断频率';,python-3.x,forecasting,Python 3.x,Forecasting,我正试图在Python3.x中进行预测。所以我写了下面的代码 from statsmodels.tsa.seasonal import seasonal_decompose decomposition = seasonal_decompose(ts_log) trend = decomposition.trend seasonal = decomposition.seasonal residual = decomposition.resid 但我收到了错误信息 AttributeError:

我正试图在Python3.x中进行预测。所以我写了下面的代码

from statsmodels.tsa.seasonal import seasonal_decompose
decomposition = seasonal_decompose(ts_log)

trend = decomposition.trend
seasonal = decomposition.seasonal
residual = decomposition.resid
但我收到了错误信息

AttributeError: 'RangeIndex' object has no attribute 'inferred_freq'

你能帮我解决这个问题吗?你需要确保你的Panda Series对象有一个带有推断频率的日期时间索引

例如:

ts_log.index
>>> DatetimeIndex(['2014-01-01', ... '2017-12-31'],
              dtype='datetime64[ns]', name='Date', length=1461, freq='D')
注意到有一个属性
freq='D'
,它意味着Pandas推断Pandas系列每天都被索引(D=Daily)

现在,为了实现这一点,我假设您的系列有一个列名“Date”。下面是执行此操作的代码:

#将每日栏目从字符串转换为日期时间(如果已经完成,则跳过)
ts_日志['Date']=pd.to_日期时间(ts_日志['Date'])
#将列“Date”设置为索引(如果已完成,则跳过)
ts_log=ts_log.set_索引(“日期”)
#指定日期时间频率
ts_log=ts_log.asfreq('D')
有关每日以外的频率,请参阅此处: