I want to replace the string value in the Python list with a specific number value. For example:
l = ["orange", "lemon", "apple", "orange", "apple","orange", "lemon","lemon", "apple", "grape", "grape", "lemon", "grape"]
I want to get:
l = [1, 2, 3, 1, 3, 2, 2, 3, 4, 4, 2, 4]
I know that it can be done using the pandas and map functions. But what if I have 50 different categories? It would be stupid to write a different case for each category? Is there the way to do this automatically?