For example, if I have a column in a csv file which contains the following:
EmployeeID
ABC-10
DEF-70
GHI-20
BCD-70
...
where if the EmployeeID contains 10 = New York, 20 = Paris, 70 = London
Can an IF function statement like the one below be used? But changed to allow for 'contains 10/20/70' rather than exactly equalling the value.
def applyFunc(x):
if x == '10':
return 'New York'
elif x == '20:
return 'Paris'
elif x == '70:
return 'London'
return ''
df['NewColumn'] = df['EmployeeID'].apply(applyFunc)
print(df.NewColumn)
Aucun commentaire:
Enregistrer un commentaire