Search code examples
pythonpandastime-seriesstatsmodels

How to access components of seasonal_decompose from statsmodels


I have two time series stored in data frames london and scotland of the same length and same columns. One column in date which spans from 2009 to 2019 and has a daily frequency for data of column yearly_cost. They look as such:

    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

I wish to compare the euclidean distance of only the seasonality components of yearly_cost in the time series. I have decomposed them using seasonal_decompose() from statsmodels, however I wish to take only the seasonality component from the object:

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

Is this possible to take and create into a time series in a new_df?

Any help would be appreciated. Thanks


Solution

  • I have worked this out. To obtain the seasonal component, you simply use

    new_df = result.seasonal

    This gives you only the seasonal result.