Suppose I have a dataframe, df, below.
Date | ID | Name | Order Code |
---|---|---|---|
10/10/2022 | 736535 | James Smith | 7361LH |
10/10/2022 | 736535 | James Smith | 7374GY |
10/10/2022 | 736535 | James Smith | 2739TG |
12/12/2021 | 974633 | Henry Jones | 2287TT |
12/12/2021 | 974633 | Henry Jones | 4487TE |
11/11/2020 | 397495 | Markus Barry | 3464TG |
The Date, ID, Name columns contain duplicates. I want to remove the duplicates and create new rows for each Order Code for each person. I want to transform the dataframe to look like below:
Date | ID | Name | Order Code 1 | Order Code 2 | Order Code 3 |
---|---|---|---|---|---|
10/10/2022 | 736535 | James Smith | 7361LH | 7374GY | 2739TG |
12/12/2021 | 974633 | Henry Jones | 2287TT | 4487TE | |
11/11/2020 | 397495 | Markus Barry | 3464TG |
How does one do this in pandas?