I have a pandas dataframe with column "Code" (categorical) with more than 100 unique values. I have multiple rows for same "Name" and would like to capture all of information pertaining to a unique "Name" in one row. Therefore, I'd like to transpose the column "Code" with the values from "Counter". How do I transpose "Code" in such a way that the following table:
Name | Col1 | Col2 | Col3 | Code | Counter |
---|---|---|---|---|---|
Alice | a1 | 4 | |||
Alice | a2 | 3 | |||
Bob | b1 | 9 | |||
Bob | c2 | 1 | |||
Bob | a2 | 4 |
becomes this:
Name | Col1 | Col2 | Col3 | a1 | a2 | b1 | c2 |
---|---|---|---|---|---|---|---|
Alice | 4 | 3 | 0 | 0 | |||
Bob | 0 | 4 | 9 | 1 |