我正在尝试绘制一个季节性分解模型,以便使用代码来描述时间序列趋势和季节性,这给了我一个错误,上面写着
AttributeError:“Int64Index”对象没有属性“inferred_freq”
from plotly.plotly import plot_mpl
from statsmodels.tsa.seasonal import seasonal_decompose
result = seasonal_decompose(series, model='multiplicative')
fig = result.plot()
plot_mpl(fig)
我正在关注此链接中的模型
我的数据框看起来像这样:
date Name Count
1 2018-09-04 MALX 198
2 2018-09-06 MALX 200
3 2018-09-11 MALX 203
4 2018-09-16 MALX 215
5 2018-09-17 MALX 401
我正在使用以下软件包:
import pandas as pd
import numpy as np
from pandas import Series
from matplotlib import pyplot
import matplotlib.pyplot as plt
series = pd.read_csv('Malx_data.csv', low_memory=False, usecols= ['date', 'Name', 'Count'])
series = series.loc[series['Name'] == 'MALX'].sort_values(by = 'day', ascending = True)
series['date'] = pd.to_datetime(series['date'])
series
回溯错误信息如下:
AttributeError Traceback (most recent call last)
<ipython-input-43-4e5d5e1e2756> in <module>()
1 from plotly.plotly import plot_mpl
2 from statsmodels.tsa.seasonal import seasonal_decompose
----> 3 result = seasonal_decompose(series, model='multiplicative')
4 fig = result.plot()
5 plot_mpl(fig)
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\statsmodels\tsa\seasonal.py in seasonal_decompose(x, model, filt, freq, two_sided, extrapolate_trend)
106 """
107 if freq is None:
--> 108 _pandas_wrapper, pfreq = _maybe_get_pandas_wrapper_freq(x)
109 else:
110 _pandas_wrapper = _maybe_get_pandas_wrapper(x)
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\statsmodels\tsa\filters\_utils.py in _maybe_get_pandas_wrapper_freq(X, trim)
43 index = X.index
44 func = _get_pandas_wrapper(X, trim)
---> 45 freq = index.inferred_freq
46 return func, freq
47 else:
AttributeError: 'Int64Index' object has no attribute 'inferred_freq'