如何从 statsmodels 访问 seasonal_decompose 的组件

How to access components of seasonal_decompose from statsmodels

我有两个时间序列存储在相同长度和相同列的数据帧 londonscotland 中。 date 中的一列从 2009 年到 2019 年并且具有列 yearly_cost 数据的每日频率。它们看起来是这样的:

    Date        Yearly_cost
0   2009-01-01  230
1   2009-01-02  460
2   2009-01-03  260
3   2009-01-04  250
4   2009-01-05  320
5   2009-01-06  430

我想比较时间序列中 yearly_cost 的季节性成分的欧氏距离。我已经使用来自 statsmodels 的 seasonal_decompose() 分解了它们,但是我希望只从对象中获取季节性成分:

result = <statsmodels.tsa.seasonal.DecomposeResult at 0x2b5d7d2add8>

是否可以在 new_df 中创建时间序列?

如有任何帮助,我们将不胜感激。谢谢

我已经解决了。要获得季节性成分,您只需使用

new_df = result.seasonal

这只为您提供季节性结果。