-
-
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
API: Allow dictionary argument in rename_axis to change some names of MultiIndex #19978
Comments
duplicate of #4160 a pull-request is welcome. MI rename is entirely broken. |
This is another issue. #4160 is about renaming labels in a MultiIndex (with |
@jorisvandenbossche Yes, this is about changing the level names, but using |
So in order to allow this functionality (using a mapper to change some names of a Otherwise, I can't see how to add this functionality until some future version where we can officially remove the deprecated behavior. Comments from @jorisvandenbossche and @jreback welcome. |
@Dr-Irv you can just do this. this is quite idiomatic and should be used more anyhow. |
@jreback Yes, but then I can't do the renaming inline, which is the capability that I'd like to have. With the current
produces the desired result, but then you have to specify all of the names, rather than just the ones you want to change. Just like |
sure you can, use |
I am -1 on changing this and why I closed it. |
@jreback I'm looking at this from having some cleanliness and symmetry in the API's. Let's say that I have a |
@jreback Here's an example that illustrates the need for rename_axis with an argument dictionary. In this example, there are 2 DataFrames, (df3 and df2) and the contents of the indexes are exactly the same, except that one of the names of the index in df2 is different. So if try to add the 2 Series, I get an error because the names of the indexes are different. But if I change that single name, I can then do the add.
So now I change the name of the mismatched column:
The example is convoluted, but what is happening in my application is that I have two Series. In my application, the first Series
or
I wouldn't have to permanently change the index of |
Jeff, you closed it as a duplicate (which it wasn't after further thought) @Dr-Irv I am personally in general fine with the idea. But, I don't really like the introduction of a temporary keyword like @jreback the reason I am fine with this is because it feels consistent with how we do things in other places in pandas. Eg rename with a dict let's you rename specific values of the columns/index without needing to specify them all, here it would be very similar but for the columns/index level names. |
@jorisvandenbossche I implemented your suggestion in my pull request #20046 |
Code Sample, a copy-pastable example if possible
Problem description
Ideally, if you call
df.rename_axis(dict, axis='index')
, only the names specified in the dictionary would be changed in the correspondingMultiIndex
Expected Output
For the expression
the output should be:
Output of
pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 3.6.4.final.0
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 60 Stepping 3, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None
pandas: 0.22.0
pytest: 3.3.2
pip: 9.0.1
setuptools: 38.4.0
Cython: 0.27.3
numpy: 1.14.0
scipy: 1.0.0
pyarrow: None
xarray: None
IPython: 6.2.1
sphinx: 1.6.6
patsy: 0.5.0
dateutil: 2.6.1
pytz: 2017.3
blosc: None
bottleneck: 1.2.1
tables: 3.4.2
numexpr: 2.6.4
feather: None
matplotlib: 2.1.2
openpyxl: 2.4.10
xlrd: 1.1.0
xlwt: 1.3.0
xlsxwriter: 1.0.2
lxml: 4.1.1
bs4: 4.6.0
html5lib: 1.0.1
sqlalchemy: 1.2.1
pymysql: 0.7.11.None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
In [ ]:
The text was updated successfully, but these errors were encountered: