Traceback (most recent call last): File "C:\Users\likun\pythonzz\Lib\site-packages\pandas\core\indexes\base.py", line 3652, in get_loc return self._engine.get_loc(casted_key) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "pandas\_libs\index.pyx", line 147, in pandas._libs.index.IndexEngine.get_loc File "pandas\_libs\index.pyx", line 176, in pandas._libs.index.IndexEngine.get_loc File "pandas\_libs\hashtable_class_helper.pxi", line 7080, in pandas._libs.hashtable.PyObjectHashTable.get_item File "pandas\_libs\hashtable_class_helper.pxi", line 7088, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 'names' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "D:\pythonzz\2.py", line 4, in <module> names=pd.read_excel('D:\pythonzz\y\\post.xlsx')['names']# 读取所有照片名字 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^ File "C:\Users\likun\pythonzz\Lib\site-packages\pandas\core\frame.py", line 3761, in __getitem__ indexer = self.columns.get_loc(key) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\likun\pythonzz\Lib\site-packages\pandas\core\indexes\base.py", line 3654, in get_loc raise KeyError(key) from err KeyError: 'names' Process finished with exit code 1
时间: 2023-07-28 13:13:08 浏览: 166
解决pandas read_csv 读取中文列标题文件报错的问题
这是一个 KeyError 异常,提示 'names' 这个键不存在于读取的 Excel 文件的列中。请检查 Excel 文件的列名是否正确或者是否存在。可能需要使用 `pd.read_excel('D:\pythonzz\y\\post.xlsx', usecols=['names'])` 明确指定使用的列。
阅读全文