简体   繁体   English

使用 python 计算 excel 中的单元格时出现错误,但我不知道为什么?

[英]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.确保您正确编写了列名称。

  • check if there is a space in the column name检查列名中是否有空格

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我不知道为什么,但我在 Image_url 中没有得到任何东西。我正在使用scrapy - I dont know why but I am not getting anything in Image_url.I am using scrapy 我不知道为什么,但我收到海龟导入错误,我需要帮助 - i dont know why but i am getting a turtle import error and i need assistance 我正在尝试从另一个模块获取 API 一切都正确我不知道为什么会出现此错误? - I am trying to get the API from another module everything is corrects i dont know why i am getting this error? 如何在 replit.com 中使用 Python 一起打印带有表情符号的文本,我不知道为什么会出现此错误 - How to print a text with an emoji together using Python in replit.com and I don't know why I am getting this error 为什么在Python中使用“设置”会出错? - Why am I getting an error using 'set' in Python? 为什么在python函数中使用.map会出错 - Why am I getting error using .map in python function 我在 Visual Studio Code 上使用 Python 来导入 excel 文件,但出现导入错误 - I am using Python on Visual Studio Code to import an excel file but I am getting an import error 我正在尝试使用 Python 从 Excel 检索内容。 我收到投资未定义错误 - I am trying to retrieve the content from an Excel using Python. I am getting Investment undefined error 不知道为什么我收到 StopIteration 错误 - Don't know why I am getting StopIteration error 为什么会出现此python串联错误? - Why am I getting this python concatenation error?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM