Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Change Excel column name with Python

After several code attempts, I can’t change the name of the columns on my excel documents.

import pandas as pd

FichierCible = r'C:\Users\User\Desktop\User\stack.xlsx'

df = pd.read_excel(FichierCible)
df.rename(columns={'a': 'A', 'b': 'B'}, inplace=True)
df

print(df)

Empty DataFrame

Columns: [A, B, c, d, e]

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Index: []

The change is displayed correctly on the command prompt but on the Excel document the change is not applied.
Do you have an idea ?

Thank you

>Solution :

You need to write back your DataFrame to a new/the same Excel.

df.to_excel(FichierCible)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading