1

I have a time series with 1hr time interval, which I'm trying to decompose - with seasonality of a week.

Time                    Total_request
2018-04-09 22:00:00     1019656 
2018-04-09 23:00:00     961867  
2018-04-10 00:00:00     881291  
2018-04-10 01:00:00     892974  

import pandas as pd
import statsmodels as sm

d.reset_index(inplace=True)
d['env_time'] = pd.to_datetime(d['env_time'])
d = d.set_index('env_time')
s=sm.tsa.seasonal_decompose(d.total_request, freq = 24*7)

This gives me a resulting graphs of Seasonal, Trend, Residue - https://i.stack.imgur.com/DVAuR.jpg

But on trying to extract the residual values using s.resid I get this -

env_time
2018-04-09 20:00:00   NaN
2018-04-09 21:00:00   NaN
2018-04-09 22:00:00   NaN

I get values when I modify it to a lower frequency. What's strange is why I can't derive the values, when it's being plotted. I have found similar questions being asked, none of the answers were relevant to this case.

tobsecret
  • 2,442
  • 15
  • 26
dj007
  • 11
  • 4
  • Please provide a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve). There is a particularly helpful guide for how to create such an example for a pandas question, [here](https://stackoverflow.com/a/32536193/7480990). – tobsecret May 23 '18 at 22:44
  • @tobsecret I hope this is better! Thank you – dj007 May 23 '18 at 23:08
  • Can you please make it copy-pasteable? i.e. use df.to_dict() in your console and copy it so it looks something like this: `d = pd.DataFrame.from_dict({'your':'dictionary', 'goes':'here'})`. – tobsecret May 23 '18 at 23:23
  • Also, this may be a naive question but isn't it expected that you do not get residuals and trend for the beginning and end of your time period as an effect of the window size? i.e. you do not get those values at the beginning and end of your time series for the length of one window size. – tobsecret May 23 '18 at 23:29
  • Yes it is, I'm checking after 156 values, and still get a NA. – dj007 May 23 '18 at 23:35
  • Are there any non-nan values in s.resid? You can check by using `s.resid.dropna()`. – tobsecret May 24 '18 at 15:47

0 Answers0