在没有 DatetimeIndex 的情况下使用 statsmodels.seasonal_decompose() 但频率已知

Using statsmodels.seasonal_decompose() without DatetimeIndex but with Known Frequency

我有一个时间序列信号,我想在 Python 中分解,所以我求助于 statsmodels.seasonal_decompose()。我的数据频率为 48(半小时)。我遇到了与 相同的错误,解决方案是将 Int 索引更改为 DatetimeIndex。但我不知道我的数据来自 dates/times。

this github thread 中,一位 statsmodels 贡献者说

"In 0.8, you should be able to specify freq as keyword argument to override the index."

但这对我来说似乎不是这样。这是说明我的问题的最小代码示例:

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'

版本信息:

import statsmodels
print(statsmodels.__version__)
0.8.0

有没有办法在没有 DatetimeIndex 的情况下以指定频率分解 statsmodels 中的时间序列?

如果没有,在 Python 中是否有更好的选择?我检查了 Seasonal 包,但 its github 列出了 0 downloads/month,一个贡献者,最后一次提交是在 9 个月前,所以我不确定我的项目是否要依赖它。

感谢 josef-pkt 在 github 上回答这个问题。 statsmodels 0.8.0 中有一个错误,如果传递 Pandas 对象,它总是尝试根据 DatetimeIndex 计算推断频率。

使用 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)

(无错误)