Python: Pandas Rename Columns with List Example

import pandas as pd

df = pd.DataFrame({
    'Col1': ['2023-01','2023-02', '2023-03'],
    'Col2': ['Delhi', 'New York','Tokyo'],
    'Col3': [31,19,22]

new_column_names = ['Date', 'City', 'Temp']

df.rename(columns=dict(zip(df.columns, new_column_names)), inplace=True)

      Date      City  Temp
0  2023-01     Delhi    31
1  2023-02  New York    19
2  2023-03     Tokyo    22
Python - Pandas Rename Columns with List Example



Facing issues? Have Questions? Post them here! I am happy to answer!

Author: Rakesh
Author Info:

Rakesh is a seasoned developer with over 10 years of experience in web and app development, and a deep knowledge of operating systems. Author of insightful How-To articles for Code2care.

Follow him on: X

Copyright © Code2care 2023 | Privacy Policy | About Us | Contact Us | Sitemap