pandas相关报错:pandas/_libs/hashtable_class_helper.pxi...
程序员文章站
2022-03-26 21:02:47
...
问题记录
return self._engine.get_loc(key)
File "pandas/_libs/index.pyx", line 107, in pandas._libs.index.IndexEngine.get_loc
File "pandas/_libs/index.pyx", line 131, in pandas._libs.index.IndexEngine.get_loc
File "pandas/_libs/hashtable_class_helper.pxi", line 1607, in pandas._libs.hashtable.PyObjectHashTable.get_item
File "pandas/_libs/hashtable_class_helper.pxi", line 1614, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: 0
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "E:/python_workspace/Air/renew.py", line 106, in <module>
time.append(X_test[i][2])
File "C:\Users\ani\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\core\frame.py", line 2995, in __getitem__
indexer = self.columns.get_loc(key)
File "C:\Users\ani\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\core\indexes\base.py", line 2899, in get_loc
return self._engine.get_loc(self._maybe_cast_indexer(key))
File "pandas/_libs/index.pyx", line 107, in pandas._libs.index.IndexEngine.get_loc
File "pandas/_libs/index.pyx", line 131, in pandas._libs.index.IndexEngine.get_loc
File "pandas/_libs/hashtable_class_helper.pxi", line 1607, in pandas._libs.hashtable.PyObjectHashTable.get_item
File "pandas/_libs/hashtable_class_helper.pxi", line 1614, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: 0
打算将数据分布用图形表现出来,从dataframe中提取数据,并将数据追加到列表中。原先用归一化处理后是没报错的,但后来想用真实数据来显示,就出现如上的错误了。
看了代码半天,也没觉得哪里有问题,然后把数据打印出来看了下,才晓得,没有处理的真实数据还保留了行名称(各个特征名),这个时候就不能用数字索引去取值了(当时以为行名称不存在了,就直接用类似a[i][2]来取值==),直接用特征名就行了,类似:a[“time”]
上一篇: 这七盆绿萝是谁点的
下一篇: PostgreSQL 9.3 正式发布
推荐阅读
-
Python+pandas计算数据相关系数的实例
-
解决pandas中读取中文名称的csv文件报错的问题
-
解决pandas read_csv 读取中文列标题文件报错的问题
-
Pandas 基础(7) - Group By 分组的相关知识
-
pandas将表格第一行作为列表名 和 plt.savefig保存图片 和 数据相关性分析
-
pandas.DataFrame.corr——计算列之间相关性
-
pandas数据相关性分析_使用Pandas,SciPy和Seaborn进行探索性数据分析
-
Pandas数据的相关性分析
-
Python+pandas计算数据相关系数的实例
-
关于Python 解决Python3.9 pandas.read_excel(‘xxx.xlsx‘)报错的问题