Get Started

Seasonal decompose

You can think of a time series as being composed of trend, seasonal and residual components. This can be a good way to think about the data when you go about modeling it. If you know the period of the time series you can decompose it into these components.

In this exercise you will decompose a time series showing the monthly milk production per cow in the USA. This will give you a clearer picture of the trend and the seasonal cycle. Since the data is monthly you will guess that the seasonality might be 12 time periods, however this won't always be the case.

The milk production time series has been loaded in to the DataFrame milk_production and is available in your environment.

This is a part of the course

“ARIMA Models in Python”

View Course

Exercise instructions

  • Import the seasonal_decompose() function from statsmodels.tsa.seasonal.
  • Decompose the 'pounds_per_cow' column of milk_production using an additive model and period of 12 months.
  • Plot the decomposition.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Import seasonal decompose
from ____ import ____

# Perform additive decomposition
decomp = seasonal_decompose(___, 
                            period=____)

# Plot decomposition
____
plt.show()
Edit and Run Code