I have a pandas dataframe with data from a supermarket cashier system that lists every Customer ("ID") and each individual item ("Item") they purchased. I want to enumerate each item within a customer buy ("Item_e").
ID = [1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3]
Item = ["Apple", "Orange", "Apple", "Apple", "Orange", "Orange", "Banana", "Banana", "Apple", "Pumpkin", "Apple", "Banana"]
Item_e = ["Apple_1", "Orange_1", "Apple_2", "Apple_3", "Orange_1", "Orange_2", "Banana_1", "Banana_2", "Apple_1", "Pumpkin_1", "Apple_1", "Banana_1"]
"ID" and "Item" are the existing columns in the dataframe and I want to generate "Item_e" as a new column.
If customer 1 buys three apples I want the one scanned first to become Apple_1, the second (whenever in the whole purchase it appears) to become Apple_2 and so on. If customer 2 also buys two apples, the first in the dataset becomes Apple_1 again, the second Apple_2.