Skip to content

reindex multi-index at level with reordered labels #9019

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

Merged
merged 1 commit into from
Dec 7, 2014

Conversation

behzadnouri
Copy link
Contributor

closes #4088

on branch:

>>> df
                     vals
first second third       
mid   3rd    992     1.96
             562    12.06
      1st    73     -6.46
             818   -15.75
             658     5.90
btm   2nd    915     9.75
             474    -1.47
             905    -6.03
      1st    717     8.01
             909   -21.12
      3rd    616    11.91
             675     1.06
             579    -4.01
top   1st    241     1.79
             363     1.71
      3rd    677    13.38
             238   -16.77
             407    17.19
      2nd    728   -21.55
             36      8.09
>>> df.reindex(['top', 'mid', 'btm'], level='first')
                     vals
first second third       
top   1st    241     1.79
             363     1.71
      3rd    677    13.38
             238   -16.77
             407    17.19
      2nd    728   -21.55
             36      8.09
mid   3rd    992     1.96
             562    12.06
      1st    73     -6.46
             818   -15.75
             658     5.90
btm   2nd    915     9.75
             474    -1.47
             905    -6.03
      1st    717     8.01
             909   -21.12
      3rd    616    11.91
             675     1.06
             579    -4.01
>>> df.reindex(['1st', '2nd', '3rd'], level='second')
                     vals
first second third       
mid   1st    73     -6.46
             818   -15.75
             658     5.90
      3rd    992     1.96
             562    12.06
btm   1st    717     8.01
             909   -21.12
      2nd    915     9.75
             474    -1.47
             905    -6.03
      3rd    616    11.91
             675     1.06
             579    -4.01
top   1st    241     1.79
             363     1.71
      2nd    728   -21.55
             36      8.09
      3rd    677    13.38
             238   -16.77
             407    17.19
>>> df.reindex(['top', 'btm'], level='first').reindex(['1st', '2nd'], level='second')
                     vals
first second third       
top   1st    241     1.79
             363     1.71
      2nd    728   -21.55
             36      8.09
btm   1st    717     8.01
             909   -21.12
      2nd    915     9.75
             474    -1.47
             905    -6.03

@@ -1138,6 +1138,27 @@ def row_bool_subset_object(ndarray[object, ndim=2] values,

return out

@cython.boundscheck(False)
@cython.wraparound(False)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, something like this doesn't already exist in groupy.py (e.g. in the sortlevel section). (doesn't look like it via casual glance).

@jreback jreback added Bug MultiIndex Reshaping Concat, Merge/Join, Stack/Unstack, Explode labels Dec 6, 2014
@jreback
Copy link
Contributor

jreback commented Dec 6, 2014

looks good. just need a release note (bug fixes).

@behzadnouri
Copy link
Contributor Author

added the release notes; all green

@jreback jreback added this to the 0.15.2 milestone Dec 7, 2014
jreback added a commit that referenced this pull request Dec 7, 2014
reindex multi-index at level with reordered labels
@jreback jreback merged commit e51eb9e into pandas-dev:master Dec 7, 2014
@jreback
Copy link
Contributor

jreback commented Dec 7, 2014

@behzadnouri cool thanks!

was a bit more complicated that first glance....!

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

Successfully merging this pull request may close these issues.

Reording a multiindex by only specifiying the order on level 0
2 participants