If I've got a multi-level column and multi-level index for a dataframe
column_level1 a1 | a2
----+----|----+----
column_level2 b1 | b2 | b3 | b4
index1 | index2 | index3
-------+--------+--------+-----+----+----+-----
0 | c1 | d1 | 1 | 2 | 3 | 4 |
0 | c2 | d3 | 5 | 6 | 7 | 8 |
How can I reshape my dataframe to move one of my indexes on top of columns_level? Lets say that I want, my current index2 to be placed on column_level0.
Also I need some efficient solution for this problem.
My current solution is to use stack/unstack in the following way:
df.stack().stack().unstack(index2).unstack().unstack()
But using this kind of implementation on huge dataframes will end in consuming to much RAM and taking to much time.