I want to convert a string to a specific int value in Python i.e. "red" I want to be 1, "blue" to 2, etc. I am currently using if-else statements. I have a dataset of strings with common strings that I want to associate with a number. Please help.
def discretize_class(x):
if x == 'first':
return int(1)
elif x == 'second':
return int(2)
elif x == 'third':
return int(3)
elif x == 'crew':
return int(4)