[英]I am getting error for calculating cells in excel using python but i dont know why?
This is the code:这是代码:
import pandas as pd
file_name = "C:/Users/jains/Downloads/Python/Python/SA.xlsx"
df = pd.read_excel(file_name)
df['Sum'] = df['data']*df['petha']+df['leta']*df['deta']
df.to_excel("C:/Users/jains/Downloads/Python/Python/SA.xlsx")
this is excel file Excel File这是 excel 文件Excel 文件
I am getting this error我收到这个错误
Traceback (most recent call last):
File "C:\Users\jains\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\core\indexes\base.py", line 3361, in get_loc
return self._engine.get_loc(casted_key)
File "pandas\_libs\index.pyx", line 76, in pandas._libs.index.IndexEngine.get_loc
File "pandas\_libs\index.pyx", line 108, in pandas._libs.index.IndexEngine.get_loc
File "pandas\_libs\hashtable_class_helper.pxi", line 5198, in pandas._libs.hashtable.PyObjectHashTable.get_item
File "pandas\_libs\hashtable_class_helper.pxi", line 5206, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: 'leta'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "c:/Users/jains/Downloads/Python/Python/SCreatefile2.py", line 5, in <module>
df['Sum'] = df['data']*df['petha']*df['leta']*df['deta']
File "C:\Users\jains\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\core\frame.py", line 3455, in __getitem__
indexer = self.columns.get_loc(key)
File "C:\Users\jains\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\core\indexes\base.py", line 3363, in get_loc
raise KeyError(key) from err
KeyError: 'leta'
why?this error.I cant understand why the error is coming?为什么?这个错误。我不明白为什么会出现错误?
As noted there is a KeyError: 'leta'.如前所述,有一个 KeyError: 'leta'。 Make sure you are writing the column name correctly.确保您正确编写了列名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.