-
-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Closed
Labels
BugMultiIndexReshapingConcat, Merge/Join, Stack/Unstack, ExplodeConcat, Merge/Join, Stack/Unstack, Explode
Milestone
Description
Code Sample
Next code fail to do unstack.
d = pd.DataFrame([[1,2,3],[2,2,3],[3,2,3],[4,2,3],[5,2,3]],
columns=pd.MultiIndex.from_tuples([[0, 0, 0], [0, 0, 1], [0, 0, 2]], names=['c1', 'c2', 'c3']),
index=pd.MultiIndex.from_tuples([[0, 0, 0, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 0, 1],
[0, 1, 0, 0, 0, 1, 0],
[0, 1, 1, 0, 0, 1, 1],
[1, 0, 0, 0, 1, 0, 0]
],
names=['i1', 'i2', 'i3', 'i4', 'i5', 'i6', 'i7']))
e = d.unstack(['i2', 'i3', 'i4', 'i5', 'i6', 'i7'])
It rise exception IndexError with message "Too many levels: Index has only 2 levels, not 3"
Problem description
The reason semms to mistyping in https://github.com/pandas-dev/pandas/blob/master/pandas/core/reshape/reshape.py#L366 :
clocs = [v if i > v else v - 1 for v in clocs]
I think it must be:
clocs = [v if val > v else v - 1 for v in clocs]
Metadata
Metadata
Assignees
Labels
BugMultiIndexReshapingConcat, Merge/Join, Stack/Unstack, ExplodeConcat, Merge/Join, Stack/Unstack, Explode