1 year ago

#388965

test-img

dot py

key of type tuple not found and not a MultiIndex

I am trying a code in this site: https://www.analyticsvidhya.com/blog/2021/07/stock-market-forecasting-using-time-series-analysis-with-arima-model

import statsmodels.api as sm
model = sm.tsa.arima.ARIMA(train_data, order=(1,1,2))
fitted = model.fit()
print(fitted.summary())
fc, se, conf = fitted.forecast(321, alpha=0.05), fitted.forecast(321, alpha=0.05), fitted.forecast(321, alpha=0.05)
fc_series = pd.Series(fc, index=test_data.index)
lower_series = pd.Series(conf[:, 0], index=test_data.index)
upper_series = pd.Series(conf[:, 1], index=test_data.index)

i did not find a solution for the below error, any solution for that?

KeyError                                  Traceback (most recent call last)
c:\Users\admin\Documents\Python Scripts\test.ipynb Cell 15' in <cell line: 2>()
      1 fc_series = pd.Series(fc, index=test_data.index)
----> 2 lower_series = pd.Series(conf[:, 0], index=test_data.index)
      3 upper_series = pd.Series(conf[:, 1], index=test_data.index)
      4 # Plot

File ~\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas\core\series.py:984, in Series.__getitem__(self, key)
    981     key = np.asarray(key, dtype=bool)
    982     return self._get_values(key)
--> 984 return self._get_with(key)

File ~\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas\core\series.py:999, in Series._get_with(self, key)
    994     raise TypeError(
    995         "Indexing a Series with DataFrame is not "
    996         "supported, use the appropriate DataFrame column"
    997     )
    998 elif isinstance(key, tuple):
--> 999     return self._get_values_tuple(key)
   1001 elif not is_list_like(key):
   1002     # e.g. scalars that aren't recognized by lib.is_scalar, GH#32684
   1003     return self.loc[key]

File ~\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas\core\series.py:1034, in Series._get_values_tuple(self, key)
   1031     return result
   1033 if not isinstance(self.index, MultiIndex):
-> 1034     raise KeyError("key of type tuple not found and not a MultiIndex")
   1036 # If key is contained, would have returned by now
   1037 indexer, new_index = self.index.get_loc_level(key)

KeyError: 'key of type tuple not found and not a MultiIndex'

python

python-3.x

pandas

time-series

0 Answers

Your Answer

Accepted video resources