如何解决python中被攻击csv的key错误



这是我作为管理员登录程序的代码

import pandas as pd
import numpy as np
import csv
import matplotlib.pyplot as plt
print("-:-:-:-:-Welcome to Oum Cloth Store-:-:-:-:-")
m=1
while(m==1):
print("1.Admin")
print("2.User")
a=int(input("Enter your choice"))
if(a==1):
ad=input("Enter Admin Name")
pa=input("Enter Password")
df=pd.read_csv('Admin.csv')
print(df)
df1=df[(df['Admin']==ad) & (df['Password']==pa)]
if(df1.empty):
print("Admin Not Exists")
print("Please Enter Correct Details")
m=1

这里是CSV FILE

Admin   Password
Diya      Di

在运行时显示'Password'列的关键字错误。

Traceback (most recent call last):
File "C:/Users/admin/Desktop/Diya/code.py", line 16, in <module>
df1=df[(df['Admin']==ad) & (df['Password']== pa)]
File "C:UsersadminAppDataLocalProgramsPythonPython38libsite-packagespandascoreframe.py", line 2902, in __getitem__
indexer = self.columns.get_loc(key)
File "C:UsersadminAppDataLocalProgramsPythonPython38libsite-packagespandascoreindexesbase.py", line 2893, in get_loc
raise KeyError(key) from err
KeyError: 'Password'

csv文件为comma separated values文件。由于您没有用逗号分隔值,因此我会检查pd.read_csv()

中的sep参数。

相关内容

  • 没有找到相关文章

最新更新