Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Seasonal adjustment in Python and Scipy

Tags:

python

scipy

I am looking to seasonally adjust monthly data, using Python. As you can see from these series: www.emconfidential.com, there is a high seasonal component to the data. I would like to adjust for this so that I can better guage if the series trend is rising or falling. Anybody know how to do this easily using scipy or other Python library?

like image 581
Thomas Browne Avatar asked Jan 14 '10 19:01

Thomas Browne


People also ask

How does Python determine seasonality?

seasonal_decompose() tests whether a time series has a seasonality or not by removing the trend and identify the seasonality by calculating the autocorrelation(acf). The output includes the number of period, type of model(additive/multiplicative) and acf of the period.

How does X12 seasonal adjustment work?

The X12 procedure seasonally adjusts monthly or quarterly time series. The procedure makes additive or multiplicative adjustments and creates an output data set containing the adjusted time series and intermediate calculations.

How do you deal with seasonal data?

A simple way to correct for a seasonal component is to use differencing. If there is a seasonal component at the level of one week, then we can remove it on an observation today by subtracting the value from last week.


1 Answers

Statsmodels can do this. They have a basic seasonal decomposition and also a wrapper to Census X13 adjustment. You could also use rpy2 to access some of R's excellent SA libraries. Here is statsmodels seasonal decomp:

import pandas as pd
import statsmodels.api as sm
import matplotlib.pyplot as plt
pd.options.display.mpl_style = 'default'
%matplotlib inline

dta = sm.datasets.co2.load_pandas().data.resample("M").fillna(method="ffill")

res = sm.tsa.seasonal_decompose(dta)

fig = res.plot()
fig.set_size_inches(10, 5)
plt.tight_layout()

http://statsmodels.sourceforge.net/0.6.0/release/version0.6.html

like image 82
user2113095 Avatar answered Sep 25 '22 06:09

user2113095