df = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]})
cols= {"A": "a", "B": "c"}
>>> df.rename(columns=cols)
a c
0 1 4
1 2 5
2 3 6
# import pandas
import pandas as pd
# create data frame
df = pd.DataFrame({'First Name': ["Mukul", "Rohan", "Mayank",
"Vedansh", "Krishna"],
'Location': ["Saharanpur", "Rampur", "Agra",
"Saharanpur", "Noida"],
'Pay': [56000.0, 55000.0, 61000.0, 45000.0, 62000.0]})
# print original data frame
display(df)
# create a dictionary
# key = old name
# value = new name
dict = {'First Name': 'Name',
'Location': 'City',
'Pay': 'Salary'}
# call rename () method
df.rename(columns=dict,
inplace=True)
# print Data frame after rename columns
display(df)