I have a dataframe which looks like this:
X1 X2 X3 Y Z
x1 x2 x3 A C
x4 x5 x6 A D
x7 x8 x9 B C
x10 x11 x12 B D
where X1, X2, X3, Y and Z are the column headers.
I want to convert the values in column Z (so C and D) into sub-columns. At the same time, I want to group the resulting dataframe on the basis of the values in column Y (so A and B). The resulting dataframe should look like this:
| X1 | X2 | X3
|C D|C D|C D
| | |
A |x1 x4|x2 x5|x3 x6
B |x7 x10|x8 x11|x9 x12
Does anyone know how to achieve this in Pandas?
I tried using the pandas.multiindex() function but to no avail.