So I have a Pandas dataframe with the following structure:
ClientId | Product | Quantity |
---|---|---|
01 | Apples | 2 |
01 | Oranges | 3 |
01 | Bananas | 1 |
02 | Apples | 4 |
02 | Bananas | 2 |
and would like to get this df to look like:
ClientId | Product_Apples | Quantity_Apples | Product_Oranges | Quantity_Oranges | Product_Bananas | Quantity_Bananas |
---|---|---|---|---|---|---|
01 | 1 | 2 | 1 | 3 | 1 | 1 |
02 | 1 | 4 | 0 | 0 | 1 | 2 |
where the columns starting with Product are binary variables.
What would be the Python code for this transformation?