File "C:\Users\是小雨子呀\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\core\indexes\base.py", line 3653, 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: '行业' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "c:\Users\是小雨子呀\Desktop\测试题\测试题\test2.py", line 7, in <module> df['行业'].fillna('新上市股票', inplace=True) ~~^^^^^^ File "C:\Users\是小雨子呀\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\core\frame.py", line 3761, in __getitem__ indexer = self.columns.get_loc(key) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\是小雨子呀\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\core\indexes\base.py", line 3655, in get_loc raise KeyError(key) from err KeyError: '行业'
时间: 2023-07-21 16:02:11 浏览: 161
Python_Matplotlib_Numpypandas_ML:用Python完成的程序,实现Matplotlib,numpy,pandas,datetime,parquet,json,read_csv,openpyxl,机器学习概念和更多程序
根据您提供的错误信息,看起来在您的代码中出现KeyError异常。该异常表明在DataFrame找不到名为'行业'的列。
可能的因是列名'行业'在DataFrame中。请确保您的DataFrame包含名为'行业'的列,并且名的大小写与代码一致。
另外,您使用`df.columns`属性来查看DataFrame中的所有列名,以确保列名正确无误。
如果问题仍然存在,请检查您的数据源,确保数据源中包含名为'行业'的列。
阅读全文