I am totally beginner in Python and after using seasonal_decompose for time series decomposition result=seasonal_decompose(series, model='additive', freq=365) I got plotted results with commands result.plot() and pyplot.show(), but I cannot understand how to print this results values on screen or how to see decomposed time series values? I have plot, but I need to have values in console or some data file.

Complete code:

from pandas import read_csv
series=read_csv('B.csv', header=0, parse_dates=[0], index_col=0, squeeze=True)
from random import randrange
from matplotlib import pyplot
from statsmodels.tsa.seasonal import seasonal_decompose
result=seasonal_decompose(series, model='additive', freq=365)

1 Answer 1


seasonal_decompose returns an 'object with seasonal, trend, and resid attributes.' We can access the data by calling the object:

res = seasonal_decompose(series, model='additive', freq=365)
residual = res.resid
seasonal = res.seasonal 
trend = res.trend
print trend


  • $\begingroup$ Seasonal and trend works for me, but with residual = res.residual I got answer Attribute Error: 'DecomposeResult' object has no attribute 'residual' $\endgroup$
    – nick_name
    Jul 26, 2017 at 16:24
  • 2
    $\begingroup$ Try res.resid (inconsistent API) $\endgroup$
    – Emre
    Jul 26, 2017 at 16:40
  • 1
    $\begingroup$ My bad, as it is in the docs, res.resid should work. Thanks @Emre. statsmodels.org/dev/generated/… $\endgroup$
    – Hobbes
    Jul 26, 2017 at 16:42
  • $\begingroup$ It works now. But I have some other problem, I got NaN values for trend and resid. Besides that, on plot I got some real values for trend and residuals, I can't understand what is different here in console output? $\endgroup$
    – nick_name
    Jul 26, 2017 at 16:48
  • 2
    $\begingroup$ Are NaN at beginning and end of the arrays? This is probably because of the moving average filtering method. For example, a two week moving average will result in two weeks of NaNs initially. $\endgroup$
    – Hobbes
    Jul 26, 2017 at 16:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.