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?
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With