Skip to Main Content
It looks like you're using Internet Explorer 11 or older. This website works best with modern browsers such as the latest versions of Chrome, Firefox, Safari, and Edge. If you continue with this browser, you may see unexpected results.

Python for Basic Data Analysis: PD.8 Renaming data

Get started on your learning journey towards data science using Python. Equip yourself with practical skills in Python programming for the purpose of basic data manipulation and analysis.

Renaming data

There are scenarios in which data is presented to us with names or headers which do not suit or accurately describe the data, as such we may use pandas functions to change the name to a more appropriate one.

This function is rename(), which lets you change index names and/or column names. Here we can change the net_sales column in our dataset to profit, doing:

df.rename(columns={'profit': 'net_sales'})

rename() allows you to change index or column headers by issuing a index or column parameter.


df=df.rename(index={0:'wave 1', 1: 'wave 2'})



Activity: Renaming data

Try these out!

1. Rename  cost_of_sales to cost

2. Rename the first index to start and the last index to end

Answers for Activity: Renaming Data

import pandas as pd
df=pd.read_csv("Retail dataset.csv")




Video Guides

Further Readings