Skip to content

rename doesn't work with mutliindex #26498

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

Closed
pjadzinsky opened this issue May 22, 2019 · 2 comments
Closed

rename doesn't work with mutliindex #26498

pjadzinsky opened this issue May 22, 2019 · 2 comments
Labels
Duplicate Report Duplicate issue or pull request

Comments

@pjadzinsky
Copy link

pjadzinsky commented May 22, 2019

Code Sample, a copy-pastable example if possible

# Your code here
mi = pd.MultiIndex.from_product([['A','B'], [0, 1]])
df1 = pd.DataFrame(np.ones((1,4)), columns=mi)
df2 = df1.rename(columns={df1.columns[1]: ('C', 3)})
print(df1)
print(df2)

Currently both df1 and df2 are:

     A         B     
     0    1    0    1
0  1.0  1.0  1.0  1.0

Problem description

I was expecting df.columns[1] to change to ('C', 3) but it remains ('A', 1)

Expected Output

     A    C    B     
     0    3    0    1
0  1.0  1.0  1.0  1.0
@shantanu-gontia
Copy link
Contributor

Can you post the expected output?

@WillAyd WillAyd added the Duplicate Report Duplicate issue or pull request label May 28, 2019
@WillAyd
Copy link
Member

WillAyd commented May 28, 2019

Closing as a duplicate of #4160

@WillAyd WillAyd closed this as completed May 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate Report Duplicate issue or pull request
Projects
None yet
Development

No branches or pull requests

3 participants