How To Change the Index of a Dataframe in Python
Changing the index of a dataframe to pandas and its advantages.
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:
By importing the CSV file into pandas (as explained here ), we will have a dataframe like this:
Surprise! An untitled column with numbers has been created to the left of ‘Name’ column. This is the index column of our dataframe.