I have a dataframe products. Products looks this:
Cust_ID Prod Time_of_Sale
A Bat 1
A Ball 2
A Lego 3
B Lego 3
B Lego 9
B Ball 11
B Bat 11
B Bat 13
C Bat 2
C Lego 2
I want to change it so that it becomes like this:
Cust_ID Bat Bat Ball Lego Lego
A 1 NaN 2 3 NaN
B 11 13 11 3 9
C 2 NaN NaN 2 NaN
I have been playing around with products.groupby()
and it is not really leading me anywhere. Any help is appreciated.
The aim is to 'visualize' the order in which each item was purchased by each customer. I have more than 1000 unique Customers.
Edit: I see that a user suggested that I go through How to pivot a dataframe. But this doesn't work because my columns have duplicate values.