I have a multiindexed (3 column levels) pandas. Dataframe which is something like this:
t1 t2
p1 p2 p1 p2
v1 v2 v1 v2 v1 v2 v1 v2
A B C D E F G H
I need to rearrange it to:
t1 t2
v1 v2 v1 v2
p1 A B E F
p2 C D G H
But when I try:
df.stack(level=1)
I get:
ValueError: cannot reindex from a duplicate axis
This implies that the repetition of labels makes this operation impossible, but that doesn't make sense to me, because otherwise there would be no reason to run .stack().
- Why do I get this error? I imagine I'm not understanding the linked answer.
- How can I achieve the desired outcome?