zoukankan      html  css  js  c++  java
  • 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'
    

    解决办法

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

  • 相关阅读:
    牛客网在线编程:不要二
    牛客网在线编程:素数对
    剑指offer5:用两个栈实现队列
    剑指offer4:重建二叉树
    剑指offer3:从尾到头打印链表
    剑指offer2:替换空格
    剑指offer1:二维数组中的查找
    牛客网在线编程:藏宝图
    已知两个链表head1 和head2 各自有序,请把它们合并成一个链表依然有序
    回文函数的编写
  • 原文地址:https://www.cnblogs.com/naixil/p/13286087.html
Copyright © 2011-2022 走看看