I’ve had this problem before, but I didn’t write down the solution, so now I’m in trouble again!
I have a dataframe like the following:
Date Product Qty Income
201001 0001 1000 2000
201002 0001 1500 3000
201003 0001 1200 2400
.
.
201001 0002 3500 2000
201002 0002 3200 1900
201003 0002 3100 1850
In words, I have one line for each combination of Date/Product, and the information of Quantity and Income for each combination.
I want to rearrange this dataframe so it looks like the following:
Date Qty.0001 Income.0001 Qty.0002 Income.0002
201001 1000 2000 3500 2000
201002 1500 3000 3200 1900
201003 1200 2400 3100 1850
In words, I want to have one line for each date, and one column for each combination of Product/Information(Qty, Income).
How can I achieve this? Thanks in advance!
Use
reshape: