April 2019
Intermediate to advanced
426 pages
11h 13m
English
Decomposing involves modeling both the trend and seasonality, and then removing them. We can use the statsmodel.tsa.seasonal module to model a non-stationary time series dataset using moving averages and remove its trend and seasonal components.
By reusing our df_log variable containing the logarithm of our dataset from the previous section, we get the following:
In [ ]: from statsmodels.tsa.seasonal import seasonal_decompose decompose_result = seasonal_decompose(df_log.dropna(), freq=12) df_trend = decompose_result.trend df_season = decompose_result.seasonal df_residual = decompose_result.resid
The seasonal_decompose() method of statsmodels.tsa.seasonal requires a parameter, freq, which is an integer value specifying ...
Read now
Unlock full access