我正在尝试绘制一个季节性分解模型,以便使用给我一个错误的代码来描述时间序列趋势和季节性。
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)
我正在使用this link
中的模型我的数据框看起来像这样:
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'
答案 0 :(得分:0)
您正在分解的系列似乎没有时间序列索引。您可以通过以下方式添加它:
error: unexpected type
str.charAt(j)=str.charAt(j+1);
^
required: variable
found: value
1 error