全部
我在下面的数据框里,我试图找到我的“工作”列中存在的独特职业,并根据用户输入,我需要打印输出说“客户合格”,否则“客户不合格”。我下面的代码只是去else语句。我不确定是什么错误。任何输入表示赞赏!
到目前为止,我的代码。...
df=pd.read_csv('bank-data.csv')
uniq_job_set=list(set(df['job'])) #Set of unique jobs
prof=input('Enter Profession') #Input from user
if prof==uniq_job_set:
print('Yes, Client is eligible')
else:
print('No, Client is Not-eligible')
使用的数据框:
age job marital y
0 20 student single yes
1 32 management single yes
2 49 technician married yes
3 32 blue-collar married yes
4 33 management married yes
5 61 admin. married yes
6 45 blue-collar divorced yes
7 34 technician married yes
8 37 management married yes
9 27 admin. divorced yes
答案 0 :(得分:1)
问题出在if
语句中。您正在将列表与字符串进行比较,该字符串将始终为False
。请改用if prof in uniq_job_set
:
uniq_job_set=list(set(df['job']))
prof=input('Enter Profession')
if prof in uniq_job_set:
print('Yes, Client is eligible')
else:
print('No, Client is Not-eligible')