Time series decomposition is a method that separates a time-series data set into three (or more) components. For example:
x(t) = s(t) + m(t) + e(t)
where
t is the time coordinate
x is the data
s is the seasonal component
e is the random error term
m is the trend
In R I would do the functions decompose
and stl
. How would I do this in python?
I've been having a similar issue and am trying to find the best path forward. Try moving your data into a Pandas DataFrame and then call StatsModels tsa.seasonal_decompose
. See the following example:
import statsmodels.api as sm
dta = sm.datasets.co2.load_pandas().data
# deal with missing values. see issue
dta.co2.interpolate(inplace=True)
res = sm.tsa.seasonal_decompose(dta.co2)
resplot = res.plot()
You can then recover the individual components of the decomposition from:
res.resid
res.seasonal
res.trend
I hope this helps!