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

标签 python time-series statsmodels

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

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中执行此操作的首选方法?我 checkout 了Seasonal软件包,但是its github列出了每月0次下载,一名贡献者和9个月前的最后一次提交,因此我不确定我的项目是否要依靠它。

最佳答案

感谢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)

(没有错误)

关于python - 使用不带DatetimeIndex但已知频率的statsmodels.seasonal_decompose(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42425774/

相关文章:

python - emacs 上自动 header 的模板

r - 动态时间序列预测和rollapply

c# - HighCharts 时间序列缺失点?

r - 使用 R 对数据框中的成对变量进行格兰杰因果关系分析

python - 在 Statsmodels RegressionResults 中调用对数似然?

python - 拟合模型时出现 ValueError

python - 升级 Python 模块的最佳实践

python - 如何使用 CircleCI 在后台运行服务器?

python - 为什么生成的 Python 子进程会在脚本中最后执行的行之后执行?

python - Pandas 按值分组并合并行