Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
ENH/BUG: Rename of MultiIndex DataFrames does not work #4160
Comments
|
what are you trying to accomplish, that doesn't make sense, renaming a 2-level to a single-level You can select out the level however; is this what you are after?
|
aschilling
commented
Jul 8, 2013
|
Hi everybody, Sorry, the example ist not the best. Actually, I did some trend generation today and after updating to pandas current branch a lot of my code didn't work anymore because that rename function used to work as described above.
|
|
I favour xs here, bit more explicit:
The fact that replace was working before smells like a bug, as @jreback says, it doesn't really make any sense to rename like that... |
|
renaming doesn't work for multiindexes period, whether it makes sense or not:
|
|
Now that is a bug/feature request :) Maybe you ought to be able to replace on each level for a MultiIndex, say using
not sure... |
|
need to add |
|
not sure level argument works/makes sense since rename allows you to change both index and columns at the same time:s |
|
Although perhaps my suggestion doesn't either (if want to replace same things as the level name/number)... |
waitingkuo
added a commit
to waitingkuo/pandas
that referenced
this issue
Aug 5, 2013
|
|
waitingkuo |
3c69575
|
jtratner
was assigned
Sep 9, 2013
This was referenced Dec 6, 2013
jreback
referenced
this issue
Apr 9, 2014
Closed
Change names of MultiIndex Index of a Dataframe #5273
jreback
modified the milestone: 0.15.0, 0.14.0
Apr 22, 2014
jreback
modified the milestone: 0.15.0, 0.15.1
Jul 6, 2014
jreback
modified the milestone: 0.15.1, 0.15.0
Sep 8, 2014
jtratner
was unassigned
by jreback
Sep 8, 2014
8one6
commented
Nov 18, 2014
|
I think this is still an open issue. It would be great to be able to treat the column labels as tuples and just use rename in the "natural" (at least natural to me) way. For example:
|
|
@8one6 this is an open issue currently. this still waiting for an API to deal with the multi-level API. I am not sure I like the stringifying idea. But haven't thought too much about this. Maybe an actual example would help |
8one6
commented
Nov 18, 2014
gives
So now I want to do this:
but that doesn't do what I expect, it just gives back the unmodified frame. To accomplish what I want here, I would do:
which gives the desired result:
Basically, in the multi-index context, I was expecting |
|
a multi-index renam at the moment does not work at all. The issue is how do you rename only part of a level e.g.
but no way to do this (well it doesn't work), but does make sense
|
8one6
commented
Nov 18, 2014
|
Ah, ok. So that last code block in your comment, is that a reasonable thing to hope will work at some point? I.e. is there a reason that would be a bad API for doing fully general multilevel renaming? (I think that's what I had tried to achieve with my dict comprehension in my And the other two lines...
is that the current working proposal? Or already implemented? Or up for debate? |
|
I think the prior dont work (but prob don't need much). The last is a proposed API. I think their is a pull-requests somewhere which does most of this but wasn't finished IIRC. |
jreback
modified the milestone: 0.16.0, Next Major Release
Mar 6, 2015
jreback
added Difficulty Intermediate Effort Medium
labels
Apr 6, 2015
This was referenced Dec 10, 2015
denfromufa
commented
Apr 1, 2016
|
+1 on this feature, I found very obscure renaming/replacing multi-index labels. What is the current state @jreback ? |
|
@denfromufa its open. |
jreback
modified the milestone: 0.18.1, Next Major Release
Apr 1, 2016
jreback
modified the milestone: 0.18.1, 0.18.2
Apr 26, 2016
jreback
modified the milestone: 0.18.2, 0.19.0
Jul 6, 2016
jorisvandenbossche
referenced
this issue
Jul 23, 2016
Merged
ENH: level keyword in rename (GH4160) #13766
eronlloyd
commented
Aug 26, 2016
|
In the meanwhile, could someone point to a recommended work-around? I'm dealing with some SurveyMonkey data that exports with unnecessary white space in the resulting MultiIndex and there doesn't seem to be an easy way to clean up the DataFrame. |
geoffrey-eisenbarth
commented
Feb 14, 2017
•
|
@eronlloyd: Looks like passing
When I need to do something similar, I just drop the index and replace the values using |
jreback
modified the milestone: 0.20.0, Next Major Release
Mar 23, 2017
jreback
added Prio-high and removed Prio-medium
labels
Mar 29, 2017
jreback
modified the milestone: Next Minor Release, Next Major Release
Mar 29, 2017
jreback
referenced
this issue
Apr 7, 2017
Merged
DEPR: deprecate relableling dicts in groupby.agg #15931
jreback
modified the milestone: 0.20.0, Next Minor Release
Apr 9, 2017
jreback
closed this
in #15931
Apr 13, 2017
|
This was closed automatically by github, but that was not the intention (#15931 is not related to this) |
jorisvandenbossche
reopened this
Apr 15, 2017
jorisvandenbossche
referenced
this issue
Apr 15, 2017
Closed
Renaming MultiIndex values does not work at all (doesn't update values, or raise an exception) #16008
|
hahah had a reference with the word fix in it! |
aschilling commentedJul 8, 2013
•
edited by jreback
xref #14139 for empty MI
Hi everybody,
in the current version renaming of MultiIndex DataFrames does not work. Lets take the following example:
and the following query:
Now, the following renaming does not work
Thanks in advance
Andy