You can change the column names in a data frame one or two at a time using the rename() function or all at once using the columns attribute as well.
Rename a few columns
In the below example, two of the column names are changed. Notice the use of argument inplace=True, it means, change the original dataset itself
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
# Defining Department Data import pandas as pd DepartmentData=pd.DataFrame({'Dep': ['BI','QA','DEV','DEV','QA'], 'id': [101,102,103,104,105], 'DOJ': ['12-Mar-2020','2-Feb-2020','15-Jan-2020','23-Apr-2019','14-Sep-2019'] }) # Priting data print(DepartmentData) # Changing multiple column names using rename() function DepartmentData.rename(columns={'DOJ':'DateOfJoining', 'Dep':'Department'}, inplace=True) # Priting data after name change print(DepartmentData) |
Sample Output:

Rename all the columns at once
You can change all the column names in a data frame by providing a list of names in the same order of columns and assigning it to the columns attribute of a data frame.
1 2 3 4 5 |
# Changing all the column names together DepartmentData.columns=['Department','id','DOJ'] # printing the data print(DepartmentData) |
Sample Output:

Author Details
Lead Data Scientist
Farukh is an innovator in solving industry problems using Artificial intelligence. His expertise is backed with 10 years of industry experience. Being a senior data scientist he is responsible for designing the AI/ML solution to provide maximum gains for the clients. As a thought leader, his focus is on solving the key business problems of the CPG Industry. He has worked across different domains like Telecom, Insurance, and Logistics. He has worked with global tech leaders including Infosys, IBM, and Persistent systems. His passion to teach inspired him to create this website!