I'd like to take some data that is currently in rows, and transform it into columns. The idea here is to have a single row for every value of x1
in df
, and to split the data in x3
into two columns on the basis of a unique x1
and x2
combination.
> df
x1 x2 x3
1 A 0 4
2 A 1 2
3 B 1 1
4 C 0 5
5 C 1 2
6 D 0 1
7 D 1 1
8 E 0 3
This may involve a multi-step cleanup process, but eventually I'd like to get something like the below table, df_rev
. Note the missing combinations of B0
and E1
have been replaced with 0 values.
> df_rev
x1 x3_0 x3_1
1 A 4 2
3 B 0 1
4 C 5 2
6 D 1 1
8 E 3 0
Right now I've been trying to fit this answer to my situation, but without much luck. Any help would be much appreciated.