Reputation: 85
Trying to apply seasonal_decompose on timeseries data whose freq is irregular. It looks something like this:
modal_price
Period
2014-11-01 1469
2015-01-01 1258
2015-03-01 1112
2015-04-01 1373
2015-06-01 1370
2015-07-01 1406
2015-08-01 1520
2015-09-01 1860
2015-10-01 1436
2015-11-01 1455
freq comes out to be None when I use df.index.freq
When I use seasonal_decompose function like this:
seasonal_decompose(x, model = 'additive')
it shows an error
ValueError: You must specify a freq or x must be a pandas object with a timeseries index with a freq not set to None.
Need help.
Upvotes: 3
Views: 4631
Reputation: 13582
Statsmodel requires the frequency to decompose the series.
Usually, that frequency is in the metadata of the index (be it daily, weekly, mothly,...). However, yours doesn't have and that it why it gives you that error.
There at least two ways to solve it (let's consider the df
named x
):
• The one @A.Abs mentions, where you will pass freq
in the seasonal_decompose, such as seasonal_decompose(x['Price'], freq=365)
.
• Setting the frequency to one's index column as x.index.adfreq(freq='d')
, where 'd'
corresponds to the day (daily frequency).
For more information on the frequency strings (or offset aliases) that can be passed into freq keyword arguments, check this answer or this Pandas Documentation page.
Upvotes: 0
Reputation: 470
I have faced the same problem and fixed it by specifying the frequency argument.
seasonal_decompose(Ts, model = 'additive', freq=1)
I hope this help. I found https://www.analyticsvidhya.com/blog/2016/02/time-series-forecasting-codes-python/ helpful.
Upvotes: 4