第一次在Pandas上工作,我正在尝试使用CSV文件。
1) The CSV file has 4 columns, namely `Employee Name,Gross_Salary,Deduction,Net_Salary`
2) My motive is to find the difference between "Gross_Salary" and "Deduction", and compare it to "Net_Salary".
3) If the results matches, then "pass", or "fail".
因此,据我所知,我编写了以下代码,但我认为它需要修改,因为它无法正常工作。下面是示例程序。
import pandas as pd
# Reading the CSV file
df = pd.read_csv(r'xl1.csv')
# Summation pf the two columns and giving results
sum1 = df['Gross_Salary'].sum()
sum2 = df['Deduction'].sum()
diff = sum1 - sum2
if diff == df['Net_salary']:
print("pass")
else:
print("Fail")
执行它时,出现错误:KeyError: 'Net_salary'
有帮助吗?
谢谢