You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Unable to perform seasonal decomposition in latest release of statsmodels #3225
import numpy as np # Version: 1.11.2+mk
import pandas as pd # Version: 0.19.0
import statsmodels.api as sm # statsmodels-0.8.0rc1-cp27-cp27m-win32.whl
dateparse = lambda dates: pd.datetime.strptime(dates, '%Y-%m')
# Get AirPassengers.csv from: https://www.analyticsvidhya.com/wp-content/uploads/2016/02/AirPassengers.csv
data = pd.read_csv('AirPassengers.csv', parse_dates=[0], dayfirst=False, date_parser=dateparse)
ts = data["#Passengers"]
decomposition = sm.tsa.seasonal_decompose(ts)
Gives error:
AttributeError: 'RangeIndex' object has no attribute 'inferred_freq'
File "d:\PythonCode\statsmodels_Test_02.py", line 11, in
decomposition = sm.tsa.seasonal_decompose(ts)
File "C:\Python27\Lib\site-packages\statsmodels\tsa\seasonal.py", line 68, in seasonal_decompose
_pandas_wrapper, pfreq = _maybe_get_pandas_wrapper_freq(x)
File "C:\Python27\Lib\site-packages\statsmodels\tsa\filters_utils.py", line 46, in _maybe_get_pandas_wrapper_freq
freq = index.inferred_freq
In 0.8, you should be able to specify freq as keyword argument to override the index.
Without that there is no way to infer the length of a season if the index is not a datetime index with the freq information.
Thanks josef-pkt for your prompt response to my problem. I have been working on my code and looking into the module(s) that are involved in the generation of this error. However, I have yet to find a solution. Perhaps you could elaborate on how to force (or over ride the index) to make it a datetime index with freq information. Or if you have a simple example or if you have a link to code that illustrates your suggestion. Best :-)
Activity
josef-pkt commentedon Oct 5, 2016
In 0.8, you should be able to specify freq as keyword argument to override the index.
Without that there is no way to infer the length of a season if the index is not a datetime index with the freq information.
virsto commentedon Oct 6, 2016
Thanks josef-pkt for your prompt response to my problem. I have been working on my code and looking into the module(s) that are involved in the generation of this error. However, I have yet to find a solution. Perhaps you could elaborate on how to force (or over ride the index) to make it a datetime index with freq information. Or if you have a simple example or if you have a link to code that illustrates your suggestion. Best :-)
virsto commentedon Oct 6, 2016
One suggestion --- a more informative error message would be helpful.
bashtage commentedon Jul 22, 2019
This works as expected now, and provides a useful error message. Closing.