To perform a time series decomposition, we can use automated procedures. The stats models library provides an implementation of the naive, or classical, decomposition method in a function called seasonal_decompose(). Additive or multiplicative methods are available.
We start importing the stats models library:
from statsmodels.tsa.seasonal import seasonal_decompose
In particular, we imported the seasonal_decompose module to perform seasonal decomposition using MAs. We perform the decomposition by applying the additive method:
DecompDataAdd = seasonal_decompose(data, model='additive', freq=1)
The seasonal component is first removed by applying a convolution filter to the data. The average of this smoothed series for each period ...