python - 试图将数据框转换为预言机预期的格式。ds的问题
问题描述
#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"*
解决方案
推荐阅读
- php - 如何从 $_POST 中获取我可以在我的 php 电子邮件脚本中使用的字符串
- kubernetes - 安全运行 kiam 服务器
- r - 我似乎无法导入我的 csv 文件并将字符串设置为导入时的因素
- python - pyodbc IM002 数据库连接
- python - 如果我需要遍历所有映射器值,我应该如何创建 reduce?
- javascript - 淘汰赛自定义验证:如何检查 observable 是否等于特定值?
- java - 找不到泽西 MessageBodyReader
- reactjs - 使用 babel-plugin-react-css-modules 找不到类名
- python-3.x - 如何拒绝一些与 Scrapy 应该解析的链接相似的链接?
- php - Sql Loader 未通过 HTTP 请求完成