I want to create a new column which gives every row a category based on their value in one specific column. Here is the function:
def assign_category(df):
if df['AvgVAA'] >= -4:
return 'Elite'
elif df['AvgVAA'] <= -4 and df['AvgVAA'] > -4.5:
return 'Above Average'
elif df['AvgVAA'] <= -4.5 and df['AvgVAA'] > -5:
return 'Average'
elif df['AvgVAA'] <= -5 and df['AvgVAA'] > -5.5:
return 'Below Average'
elif df['AvgVAA'] <= -5.5:
return 'Mediocre'
I get this error message in the second line: ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
This is the code to create the new column:
df_upd['VAA Category'] = df_upd.apply(assign_category(df_upd), axis = 1)
I did some research on it, but the explanation did not help me because it was mainly about and operators, which are not used in that line.
I do not know why, but the error message did not come up when I first ran the code. But even at that time, the function did not work. Every row in that new column was filled with 'Unknown'.
Can someoen help me out here?