How To Change the Index of a Dataframe in Python

Changing the index of a dataframe to pandas and its advantages.

Harish Maddukuri
6 min readAug 9, 2021
Photo by ThisIsEngineering from Pexels

When we generate a dataframe or import a dataset with pandas, it automatically creates a column that acts as an “index”. In this short article, we will see together how to attribute the index function to another column (or to more columns) and above all what are the advantages of this operation.

The Index column

Let’s take a simple example by importing a CSV file into pandas that contain a list of some people with their data. Our data set looks like this:

Image by Author

By importing the CSV file into pandas (as explained here ), we will have a dataframe like this:

Image by Author

Surprise! An untitled column with numbers has been created to the left of ‘Name’ column. This is the index column of our dataframe.

Changing the column that acts as an index

--

--