#python #pandas #dataframe #facebook-prophet
#python #pandas #фрейм данных #facebook-prophet
Вопрос:
#Covnvert the dataframe into the prophet expected format.
apple.rename(columns={'close': 'y', 'date': 'ds'},inplace=True)
apple['ds'] = pd.to_datetime(apple['ds'])
apple['y']=apple['y'].astype(float)
Вывод ошибки ниже:
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
2888 try:
-> 2889 return self._engine.get_loc(casted_key)
2890 except KeyError as err:
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
KeyError: 'ds'
The above exception was the direct cause of the following exception:
KeyError Traceback (most recent call last)
<ipython-input-5-67265c944d5c> in <module>
1 #Covnvert the dataframe into the prophet expected format.
2 apple.rename(columns={'close': 'y', 'date': 'ds'},inplace=True)
----> 3 apple['ds'] = pd.to_datetime(apple['ds'])
4 apple['y']=apple['y'].astype(float)
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/core/frame.py in __getitem__(self, key)
2897 if self.columns.nlevels > 1:
2898 return self._getitem_multilevel(key)
-> 2899 indexer = self.columns.get_loc(key)
2900 if is_integer(indexer):
2901 indexer = [indexer]
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
2889 return self._engine.get_loc(casted_key)
2890 except KeyError as err:
-> 2891 raise KeyError(key) from err
2892
2893 if tolerance is not None:
KeyError: 'ds"*
Комментарии:
1. Столбец
ds
не существует в df, распечатайтеdf.columns
после переименования.2. Проблема с «ds» исправлена, но теперь такая же ошибка возникает для «y». Есть предложения?