Skip to content

Renaming MultiIndex values does not work at all (doesn't update values, or raise an exception) #16008

Closed
@gregsifr

Description

@gregsifr

Code Sample, a copy-pastable example if possible

df = pd.DataFrame({'First': ['A', 'A', 'A', 'B', 'B'], 'Last': ['C', 'D', 'E', 'E', 'F'], 'C':[1, 1, 2, 1, 1]})
df.set_index(['Last','First'], inplace=True)

# rename1
df.rename(index={('C','A'):('C','NEWFIRST')})

# rename2
df.rename(index={('C','A'):('NEWLAST','A')})

Problem description

Renaming Muiltiindex values does nothing, not even raise an Exception.

Expected Output

rename1 = pd.DataFrame({'First': ['NEWFIRST', 'A', 'A', 'B', 'B'], 'Last': ['C', 'D', 'E', 'E', 'F'], 'C':[1, 1, 2, 1, 1]})
rename1.set_index(['Last','First'], inplace=True)

rename2 = pd.DataFrame({'First': ['A', 'A', 'A', 'B', 'B'], 'Last': ['NEWLAST', 'D', 'E', 'E', 'F'], 'C':[1, 1, 2, 1, 1]})
rename2.set_index(['Last','First'], inplace=True)

Output of pd.show_versions()

``` INSTALLED VERSIONS ------------------ commit: None python: 3.5.2.final.0 python-bits: 64 OS: Linux OS-release: 4.8.0-46-generic machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_AU.UTF-8 LOCALE: en_AU.UTF-8

pandas: 0.19.2+0.g825876c.dirty
nose: 1.3.7
pip: 9.0.1
setuptools: 27.2.0
Cython: 0.25.2
numpy: 1.11.2
scipy: 0.18.1
statsmodels: 0.6.1
xarray: None
IPython: 5.1.0
sphinx: 1.5.1
patsy: 0.4.1
dateutil: 2.6.0
pytz: 2016.10
blosc: None
bottleneck: 1.1.0
tables: 3.3.0
numexpr: 2.6.1
matplotlib: 1.5.3
openpyxl: 2.4.0
xlrd: 1.0.0
xlwt: 1.1.2
xlsxwriter: 0.9.6
lxml: None
bs4: 4.5.1
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 1.1.4
pymysql: None
psycopg2: 2.6.2 (dt dec pq3 ext lo64)
jinja2: 2.8
boto: 2.45.0
pandas_datareader: None

</details>

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions