Я пытаюсь использовать фильтр сезонных корректировок для набора данных, загружаемого из файла Excel. Один из столбцов - это дата в этом формате
, и я скопировал и вставил некоторый код, который отлично работал в другом проекте
path_to_x13 = "C:\\Program Files\\WinX13\\x13as\\"
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
plt.style.use(['seaborn-paper'])
import statsmodels.api as sm
from statsmodels.tsa.api import VAR
from statsmodels.tsa.base.datetools import dates_from_str
import datetime as dt
from rdflib import Graph
#!jt -t grade3 -nfs 11 -fs 11 -tfs 11 -cellw 1200
# We load the panel and do some data cleaning
mexico_pib = pd.read_excel("pib_trimestral_mexico1980_2020.xlsx")
mexico_imss_agregado = pd.read_excel("cubo_imss_asegurados_agregado.xlsx")
mexico_imss_pordel = pd.read_excel("cubo_imss_asegurados_pordel.xlsx")
Далее я * oop по словарю, в котором хранится скорректированная на сезонность продукция
seasonal_employment_agg = {}
seasonal_employment_pordel = {}
seasonal_pib = {}
seasonal_pib = {}
for var in variables_pib:
seasonal_pib[f'{var}sa'] = sm.tsa.x13_arima_analysis(endog =
mexico_pib[var].dropna(),
x12path = path_to_x13, prefer_x13 = True,
freq = "Q")
hp_pib = {}
for var in variables_pib:
x = seasonal_pib[f'{var}sa'].seasadj
temp_cycle, temp_trend = sm.tsa.filters.hpfilter(np.log(x).dropna(), lamb = 1600)
hp_pib[f'{var}sa_c'] = temp_cycle
, но я получаю следующее сообщение об ошибке
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
C:\ProgramData\Anaconda3\lib\site-packages\statsmodels\tsa\x13.py in pandas_to_series_spec(x)
295 try:
--> 296 period = _freq_to_period[x.index.freqstr]
297 except (AttributeError, ValueError):
AttributeError: 'Int64Index' object has no attribute 'freqstr'
During handling of the above exception, another exception occurred:
TypeError Traceback (most recent call last)
<ipython-input-314-4a26a77c7ec9> in <module>
9 mexico_pib[var].dropna(),
10 x12path = path_to_x13, prefer_x13 = True,
---> 11 freq = "Q")
12 hp_pib = {}
13 for var in variables_pib:
C:\ProgramData\Anaconda3\lib\site-packages\pandas\util\_decorators.py in wrapper(*args, **kwargs)
212 else:
213 kwargs[new_arg_name] = new_arg_value
--> 214 return func(*args, **kwargs)
215
216 return cast(F, wrapper)
C:\ProgramData\Anaconda3\lib\site-packages\statsmodels\tsa\x13.py in x13_arima_analysis(endog, maxorder, maxdiff, diff, exog, log, outlier, trading, forecast_periods, retspec, speconly, start, freq, print_stdout, x12path, prefer_x13)
421 periods=len(endog),
422 freq=freq))
--> 423 spec_obj = pandas_to_series_spec(endog)
424 spec = spec_obj.create_spec()
425 spec += "transform{{function={0}}}\n".format(_log_to_x12[log])
C:\ProgramData\Anaconda3\lib\site-packages\statsmodels\tsa\x13.py in pandas_to_series_spec(x)
297 except (AttributeError, ValueError):
298 from pandas.tseries.api import infer_freq
--> 299 period = _freq_to_period[infer_freq(x.index)]
300 start_date = x.index[0]
301 if period == 12:
C:\ProgramData\Anaconda3\lib\site-packages\pandas\tseries\frequencies.py in infer_freq(index, warn)
284 if isinstance(index, (pd.Int64Index, pd.Float64Index)):
285 raise TypeError(
--> 286 f"cannot infer freq from a non-convertible index type {type(index)}"
287 )
288 index = index.values
TypeError: cannot infer freq from a non-convertible index type <class 'pandas.core.indexes.numeric.Int64Index'>
Спасибо