pandas相关报错:pandas/_libs/hashtable_class_helper.pxi...

吃可爱长大的小学妹 提交于 2020-01-16 05:27:58

问题记录

    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”]

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!