0

所以我已经使用了以前的答案和问题来回答我的问题,但就我而言,我遇到了一些错误,我不知道如何解决它。

最初我已经加载了一个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'
4

1 回答 1

0

非常感谢@QuangHoang,在加载熊猫df对象后,您必须使用 定义时间尺度df.set_index('Date', inplace=True),并且变量定义现在不包含Date数组。

前:

<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 数组,因为它插入到每个数组中......

再次感谢。-

于 2019-04-11T01:31:07.377 回答