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

Change names of MultiIndex Index of a Dataframe #5273

Closed
cancan101 opened this issue Oct 20, 2013 · 4 comments
Closed

Change names of MultiIndex Index of a Dataframe #5273

cancan101 opened this issue Oct 20, 2013 · 4 comments
Milestone

Comments

@cancan101
Copy link
Contributor

How do I change the names of the various levels on a MultiIndex? How do I do so NOT in place (i.e returning a new Dataframe)?

For example I have:

                   d1  d2  d3  d4
u1          u2 u3                
Good Things C       1   1   1   1
            R       1   1   1   1
Bad Things  C       1   1   1   1
            T       1   1   1   1
Okay Things N  B    1   1   1   1
               D    1   1   1   1
            B       1   1   1   1
            D       1   1   1   1

and I want to change the u1, u2, u3.

Currently I can change the names in place using:

df.index.names = ['a1', 'a2', 'a3']
@jtratner
Copy link
Contributor

Copy the dataframe, then set names.

@jtratner
Copy link
Contributor

If you want to get a new dataframe, it has to copy all the underlying data anyways...

@cancan101
Copy link
Contributor Author

Yea, I was just wondering if there was something like swaplevel or reorder_levels that did the copy, etc for me.

@jreback
Copy link
Contributor

jreback commented Apr 9, 2014

dupe of #4160

@jreback jreback closed this as completed Apr 9, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants