How to rename column names in pandas DataFrame

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

Sample Output:

Changing multiple column names in data


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.

Sample Output:

Renaming all the columns in data
Renaming all the columns in data

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!

Leave a Reply!

Your email address will not be published. Required fields are marked *