-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
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
sort_index doesn't work after concat #15622
Comments
Thanks for the report. xref #14015 There are two issues here. The first, which is the linked issue above is that df = pd.DataFrame(index=pd.MultiIndex(levels=[[0.8, 0.5], ['a', 'b']], labels=[[0, 1], [0, 1]]))
df.index
Out[105]:
MultiIndex(levels=[[0.8, 0.5], ['a', 'b']],
labels=[[0, 1], [0, 1]])
df.sort_index()
Out[106]:
Empty DataFrame
Columns: []
Index: [(0.8, a), (0.5, b)] The specific problem here (which could be changed) - is that |
Is there another method which re-orders a level of a multi-index? I've tried >>> df = pd.DataFrame(index=pd.MultiIndex(levels=[[0.8, 0.5], ['a', 'b']], labels=[[0, 1], [0, 1]]))
>>> df.sortlevel(0).index
MultiIndex(levels=[[0.8, 0.5], ['a', 'b']],
labels=[[0, 1], [0, 1]]) |
You can call df.reindex(index=df.index.sort_values())
Out[156]:
Empty DataFrame
Columns: []
Index: [(0.5, b), (0.8, a)] |
The sort_index method does not seem to work properly if the dataframe was created with concat. See this example:
The 0.5 tuples should come before the 0.8 ones. Everything works fine if I create the multi-index from a product:
I'm on pandas version 0.18.1.
The text was updated successfully, but these errors were encountered: