pandas提示“Keyerror”

Posted naixil

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了pandas提示“Keyerror”相关的知识,希望对你有一定的参考价值。

pandas excel报错

Traceback (most recent call last):
File "D:SoftwaresPython3.6.8libsite-packagespandascoreindexesase.py", line 2646, in get_loc
    return self._engine.get_loc(key)
File "pandas\_libsindex.pyx", line 111, in pandas._libs.index.IndexEngine.get_loc
File "pandas\_libsindex.pyx", line 138, in pandas._libs.index.IndexEngine.get_loc
File "pandas\_libshashtable_class_helper.pxi", line 1619, in pandas._libs.hashtable.PyObjectHashTable.get_item
File "pandas\_libshashtable_class_helper.pxi", line 1627, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: ‘xxx‘

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "d:CodesPython_projpandas_excelXXX.py", line 16, in <module>
    not_at_school_notfinish = not_at_school_notfinish.loc[data[‘xxx‘]]
File "D:SoftwaresPython3.6.8libsite-packagespandascoreframe.py", line 2800, in __getitem__
    indexer = self.columns.get_loc(key)
File "D:SoftwaresPython3.6.8libsite-packagespandascoreindexesase.py", line 2648, in get_loc
    return self._engine.get_loc(self._maybe_cast_indexer(key))
File "pandas\_libsindex.pyx", line 111, in pandas._libs.index.IndexEngine.get_loc
File "pandas\_libsindex.pyx", line 138, in pandas._libs.index.IndexEngine.get_loc
File "pandas\_libshashtable_class_helper.pxi", line 1619, in pandas._libs.hashtable.PyObjectHashTable.get_item
File "pandas\_libshashtable_class_helper.pxi", line 1627, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: ‘xxx‘

解决办法

可能是对原始文件进行了排序,导致找不到列名

以上是关于pandas提示“Keyerror”的主要内容,如果未能解决你的问题,请参考以下文章

Pandas Python:KeyError 日期

在 Pandas 中使用 groupby 函数时如何解决“keyerror”?

KeyError:“[['','']] 中没有一个在 [columns] 中”pandas python

pandas报错:KeyError:

如何在 pandas Dataframe KeyError: False 中索引出数字的值

在 Spyder 中打开数据帧时出现 KeyError('pandas._libs.interval')