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

问题记录

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

你可能感兴趣的:(日常问题)