{"action":"created","issue":{"url":"https://api.github.com/repos/pandas-dev/pandas/issues/19978","repository_url":"https://api.github.com/repos/pandas-dev/pandas","labels_url":"https://api.github.com/repos/pandas-dev/pandas/issues/19978/labels{/name}","comments_url":"https://api.github.com/repos/pandas-dev/pandas/issues/19978/comments","events_url":"https://api.github.com/repos/pandas-dev/pandas/issues/19978/events","html_url":"https://github.com/pandas-dev/pandas/issues/19978","id":301934404,"number":19978,"title":"API: Allow dictionary argument in rename_axis to change some names of MultiIndex","user":{"login":"Dr-Irv","id":15113894,"avatar_url":"https://avatars0.githubusercontent.com/u/15113894?v=4","gravatar_id":"","url":"https://api.github.com/users/Dr-Irv","html_url":"https://github.com/Dr-Irv","followers_url":"https://api.github.com/users/Dr-Irv/followers","following_url":"https://api.github.com/users/Dr-Irv/following{/other_user}","gists_url":"https://api.github.com/users/Dr-Irv/gists{/gist_id}","starred_url":"https://api.github.com/users/Dr-Irv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Dr-Irv/subscriptions","organizations_url":"https://api.github.com/users/Dr-Irv/orgs","repos_url":"https://api.github.com/users/Dr-Irv/repos","events_url":"https://api.github.com/users/Dr-Irv/events{/privacy}","received_events_url":"https://api.github.com/users/Dr-Irv/received_events","type":"User","site_admin":false},"labels":[{"id":76812,"url":"https://api.github.com/repos/pandas-dev/pandas/labels/Enhancement","name":"Enhancement","color":"4E9A06","default":false},{"id":71268330,"url":"https://api.github.com/repos/pandas-dev/pandas/labels/MultiIndex","name":"MultiIndex","color":"207de5","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":11,"created_at":"2018-03-02T23:08:52Z","updated_at":"2018-03-08T22:03:34Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"#### Code Sample, a copy-pastable example if possible\r\n\r\n```python\r\nmi = pd.MultiIndex.from_product([['a','b','c'],[1,2]], names=['ll','nn'])\r\ndf = pd.DataFrame({'x': [i for i in range(len(mi))], 'y' : [i*10 for i in range(len(mi))]}, index=mi)\r\ndf.rename(columns={'x':'z'})  # This works to change name of one column\r\ndf.rename_axis({'x' : 'z'}, axis='columns')  # This also works to change name of one column (but you get a deprecation warning)\r\ndf.rename(index={'nn':'zz'}) # This does not work to change name of one level of a MultiIndex\r\ndf.rename_axis({'nn' : 'zz'}, axis='index') # This does not work to change name of one level of a MultiIndex\r\n```\r\n#### Problem description\r\n\r\nIdeally, if you call `df.rename_axis(dict, axis='index')`, only the names specified in the dictionary would be changed in the corresponding `MultiIndex`\r\n\r\n\r\n#### Expected Output\r\nFor the expression\r\n```\r\ndf.rename_axis({'nn' : 'zz'}, axis='index')\r\n```\r\nthe output should be:\r\n```\r\n       x   y\r\nzz ll       \r\n1  a   0   0\r\n   b   1  10\r\n   c   2  20\r\n2  a   3  30\r\n   b   4  40\r\n   c   5  50\r\n```\r\n\r\n#### Output of ``pd.show_versions()``\r\n\r\n<details>\r\n\r\nINSTALLED VERSIONS\r\n------------------\r\ncommit: None\r\npython: 3.6.4.final.0\r\npython-bits: 64\r\nOS: Windows\r\nOS-release: 10\r\nmachine: AMD64\r\nprocessor: Intel64 Family 6 Model 60 Stepping 3, GenuineIntel\r\nbyteorder: little\r\nLC_ALL: None\r\nLANG: None\r\nLOCALE: None.None\r\n\r\npandas: 0.22.0\r\npytest: 3.3.2\r\npip: 9.0.1\r\nsetuptools: 38.4.0\r\nCython: 0.27.3\r\nnumpy: 1.14.0\r\nscipy: 1.0.0\r\npyarrow: None\r\nxarray: None\r\nIPython: 6.2.1\r\nsphinx: 1.6.6\r\npatsy: 0.5.0\r\ndateutil: 2.6.1\r\npytz: 2017.3\r\nblosc: None\r\nbottleneck: 1.2.1\r\ntables: 3.4.2\r\nnumexpr: 2.6.4\r\nfeather: None\r\nmatplotlib: 2.1.2\r\nopenpyxl: 2.4.10\r\nxlrd: 1.1.0\r\nxlwt: 1.3.0\r\nxlsxwriter: 1.0.2\r\nlxml: 4.1.1\r\nbs4: 4.6.0\r\nhtml5lib: 1.0.1\r\nsqlalchemy: 1.2.1\r\npymysql: 0.7.11.None\r\npsycopg2: None\r\njinja2: 2.10\r\ns3fs: None\r\nfastparquet: None\r\npandas_gbq: None\r\npandas_datareader: None\r\nIn [ ]:\r\n\r\n​\r\n</details>\r\n"},"comment":{"url":"https://api.github.com/repos/pandas-dev/pandas/issues/comments/371640070","html_url":"https://github.com/pandas-dev/pandas/issues/19978#issuecomment-371640070","issue_url":"https://api.github.com/repos/pandas-dev/pandas/issues/19978","id":371640070,"user":{"login":"Dr-Irv","id":15113894,"avatar_url":"https://avatars0.githubusercontent.com/u/15113894?v=4","gravatar_id":"","url":"https://api.github.com/users/Dr-Irv","html_url":"https://github.com/Dr-Irv","followers_url":"https://api.github.com/users/Dr-Irv/followers","following_url":"https://api.github.com/users/Dr-Irv/following{/other_user}","gists_url":"https://api.github.com/users/Dr-Irv/gists{/gist_id}","starred_url":"https://api.github.com/users/Dr-Irv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Dr-Irv/subscriptions","organizations_url":"https://api.github.com/users/Dr-Irv/orgs","repos_url":"https://api.github.com/users/Dr-Irv/repos","events_url":"https://api.github.com/users/Dr-Irv/events{/privacy}","received_events_url":"https://api.github.com/users/Dr-Irv/received_events","type":"User","site_admin":false},"created_at":"2018-03-08T22:03:34Z","updated_at":"2018-03-08T22:03:34Z","author_association":"CONTRIBUTOR","body":"@jorisvandenbossche I implemented your suggestion in my pull request #20046"}}
{"actor":{"display_login":"Dr-Irv"}}