Skip to content
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

Add method to sort *within* a single MultiIndex level #739

Closed
wesm opened this issue Feb 2, 2012 · 6 comments
Closed

Add method to sort *within* a single MultiIndex level #739

wesm opened this issue Feb 2, 2012 · 6 comments
Labels
Enhancement MultiIndex Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Milestone

Comments

@wesm
Copy link
Member

wesm commented Feb 2, 2012

No description provided.

@cpcloud
Copy link
Member

cpcloud commented Aug 12, 2013

@hayd
Copy link
Contributor

hayd commented May 29, 2014

I think this is fixed by #6135

@hayd hayd closed this as completed May 29, 2014
@dragoljub
Copy link

So did we implement sorting a column MultiIndex by specific subset of levels?
For example: df.sortlevel(axis=1, level=[2,1], sort_remaining=True) to sort only by level 2 then 1 ignoring all other levels?

Does column indexing work correctly if the column multindex is not fully lexsorted? I know this is a limitation of the row multiindex.

@jreback
Copy link
Contributor

jreback commented Nov 6, 2014

#8526 is going to be in 0.15.2 but you in General should always fully lexsort

@toasteez
Copy link

toasteez commented Sep 13, 2016

Is there a way to custom sore the level for example for a normal dataframe you can create a list in the custom order and use something like:

def sort_df(df, sort_list, column): df[column] = pd.Categorical(df[column], sort_list) df = df.sort_values(column) return df

@jorisvandenbossche
Copy link
Member

@toasteez #3942 is an issue about adding a keys kwarg to be able to do something like this. WIth 0.19.0 (which preserves Categoricals in a MultiIndex), you will also be able to do something similar as your workaround for columns.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement MultiIndex Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

No branches or pull requests

7 participants