I want to return a value (1,2,3,4 or 5) based on the range a number falls in. I want to define a function and apply the function to a column in a DataFrame using .apply().
In the code below, amount is a hypothetical column in a DataFrame. However, I get the error SyntaxError: invalid syntax on line elif >= 40 amount < 60: (I believe it will raise the same error on all other lines).
amount = pd.Series([20, 25, 65, 80])
def miles(amount):
if 20 >= amount < 40:
return 1
elif >= 40 amount < 60:
return 2
elif >= 60 amount < 80:
return 3
elif >= 80 amount < 100:
return 4
elif >= 100 amount < 120:
return 5
else:
pass
Any help is appreciated. Thank you!