My data frame is -
id score
1 50
2 88
3 44
4 77
5 93
I want my data frame looks like -
id score is_good
1 50 low
2 88 high
3 44 low
4 77 medium
5 93 high
i have done the following code -
def selector(row):
if row['score'] >= 0 and row['score'] <= 50 :
return "low"
elif row['score'] > 50 and row['score'] <=80 :
return "medium"
else:
return "high"
x['is_good'] = x.apply(lambda row : selector(x), axis=1)
I think logic is fine but code is not working. May be we can use map function.