-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: DataFrame.unstack() does not properly sort list of levels #9514
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
cc: @behzadnouri |
As an aside,
|
Agreed, this looks inconsistent to me. |
Any thoughts on what the behavior should be? At the very least, I think:
|
I just hit this, +1 |
NOTE: the latest docs no longer state 'The level involved will automatically get sorted..' https://pandas.pydata.org/pandas-docs/version/1.1.0/reference/api/pandas.DataFrame.unstack.html
the ordering of the index levels should maybe be preserved (effectively unstacking each row in turn) in which case the expected output would be
see also #15105 |
The documentation currently says:
I guess this is just ambiguous enough to mean that the index's levels will be sorted in some way, but |
In 0.15.2 (and I believe this remains the case), the docstring for
DataFrame.unstack()
statesThe level involved will automatically get sorted.
. This is not necessarily the case whenlevel
is a list of levels.Note that the pivoted tuples are ordered as
[(A, y), (A, x), (B, x), (B, y)]
, which is not sorted.I would expect the result to be the same as the following:
In fact, there seems to be a problem even when
level
is a list containing just a single level. Compare the following:The text was updated successfully, but these errors were encountered: