我想根据他们在数据框中的头衔来识别医生,并创建一个新的列来指明他们是否是医生,但我正在努力使用我的代码
doctorcriteria = ['Dr', 'dr']
def doctor(x):
if doctorcriteria in x:
return 'Doctor'
else:
return 'Not a doctor'
df['doctorcall'] = df.caller_name
df.doctorcall.fillna('Not a doctor', inplace=True)
df.doctorcall = df.doctorcall.apply(doctor)
要使用函数创建新列,可以使用
apply
:但更直接的答案是在
Title
列上使用map
相关问题 更多 >
编程相关推荐