# Detrending Seasonal Data

A quick Python Notebook to show you how to use statsmodels to detrend seasonal data.

CLEANING

# Detrending Seasonal Data

statsmodels is a comprehensive library for time series data analysis. And it has a really neat set of functions to detrend data. So if you see that your features have any trends that are time-dependent, then give this a try.

It’s essentially fitting the multiplicative model:

$y(t) = Level * Trend * Seasonality * Noise$

Below we have some data from the 1950’s showing the number of people (monthly, in thousands) flying with an airline. You can see that there is clearly some seasonal variation.

from pandas import Series
import matplotlib.pyplot as plt