因此,我对问题answer使用了先前的答案和问题,但就我而言,我遇到了一些错误,我不知道该如何解决。
最初,我已将pandas
数据帧加载为df = pd.read_excel(fid_data)
,在下一个命令df.info()
中检查了它的内容,得到了以下内容:
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 118 entries, 0 to 117
Data columns (total 8 columns):
Date 118 non-null datetime64[ns]
MOEX 118 non-null float64
RTS 118 non-null float64
CAC40 118 non-null float64
DAX 118 non-null float64
FTSe100 118 non-null float64
nikkei 118 non-null float64
sp500 118 non-null float64
dtypes: datetime64[ns](1), float64(7)
memory usage: 7.5 KB
当我尝试使用此命令moex = df.MOEX
分解res = sm.tsa.seasonal_decompose(moex, model='additive')
时,出现以下错误:
Traceback (most recent call last):
File "Main.py", line 106, in <module>
res = sm.tsa.seasonal_decompose(moex, model='additive')
File "/home/arvaldez/anaconda3/lib/python3.6/site-packages/statsmodels/tsa/seasonal.py", line 68, in seasonal_decompose
_pandas_wrapper, pfreq = _maybe_get_pandas_wrapper_freq(x)
File "/home/arvaldez/anaconda3/lib/python3.6/site-packages/statsmodels/tsa/filters/_utils.py", line 46, in _maybe_get_pandas_wrapper_freq
freq = index.inferred_freq
AttributeError: 'RangeIndex' object has no attribute 'inferred_freq'
答案 0 :(得分:0)
非常感谢@QuangHoang,在加载熊猫df
对象之后,您必须使用df.set_index('Date', inplace=True)
定义时间标度,并且变量定义现在不包含Date
数组。 / p>
之前:
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 118 entries, 0 to 117
Data columns (total 8 columns):
Date 118 non-null datetime64[ns]
MOEX 118 non-null float64
RTS 118 non-null float64
CAC40 118 non-null float64
DAX 118 non-null float64
FTSe100 118 non-null float64
nikkei 118 non-null float64
sp500 118 non-null float64
dtypes: datetime64[ns](1), float64(7)
memory usage: 7.5 KB
之后:
<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 118 entries, 2019-02-01 to 2009-05-01
Data columns (total 7 columns):
MOEX 118 non-null float64
RTS 118 non-null float64
CAC40 118 non-null float64
DAX 118 non-null float64
FTSe100 118 non-null float64
nikkei 118 non-null float64
sp500 118 non-null float64
dtypes: float64(7)
memory usage: 7.4 KB
一切正常。现在,我不需要解析Date数组,因为它已插入每个数组中。
再次感谢。-