使用不带DatetimeIndex但频率已知的statsmodels.seasonal_decompose()

Max*_*wer 5 python time-series statsmodels

我有一个要在Python中分解的时间序列信号,因此我转向statsmodels.seasonal_decompose()。我的数据频率为48(半小时)。我遇到了与该发问者相同的错误,其中的解决方案是将Int索引更改为DatetimeIndex。但是我不知道数据的实际日期/时间。

这个github线程中,其中一个statsmodels贡献者说

“在0.8中,您应该能够将freq指定为关键字参数以覆盖索引。”

但这对我而言并非如此。这是说明我的问题的最小代码示例:

import statsmodels.api as sm
dta = pd.Series([x%3 for x in range(100)])
decomposed = sm.tsa.seasonal_decompose(dta, freq=3)

AttributeError: 'RangeIndex' object has no attribute 'inferred_freq'
Run Code Online (Sandbox Code Playgroud)

版本信息:

import statsmodels
print(statsmodels.__version__)
0.8.0
Run Code Online (Sandbox Code Playgroud)

有没有一种方法可以分解具有指定频率但没有DatetimeIndex的statsmodels中的时间序列?

如果没有,是否有在Python中执行此操作的首选方法?我签出了Seasonal软件包,但是它的github列出了每月0次下载,一个贡献者以及9个月前的最后一次提交,因此我不确定我想在我的项目中依靠它。

Max*_*wer 8

感谢josef-pkt在github上回答这个问题。statsmodels 0.8.0中存在一个错误,该错误始终尝试通过DatetimeIndex(如果传递了Pandas对象)来计算推断的频率。

使用Pandas系列时的解决方法是将numpy数组中的值传递给seasonal_decompose()。例如:

import statsmodels.api as sm

my_pandas_series = pd.Series([x%3 for x in range(100)])
decomposed = sm.tsa.seasonal_decompose(my_pandas_series.values, freq=3)
Run Code Online (Sandbox Code Playgroud)

(没有错误)