Pandas is a special tool that allows us to perform complex manipulations of data effectively and efficiently. In a DataFrame, each row is assigned with an index value ranging from 0 to n-1. The 0th is the first row and n-1th index is the last row. Pandas provides us the simplest way to convert the index into a column.
We will create a new column and assign the index value of each row with the help of using DataFrame.index() method.
pandas.DataFrame.index() Method
In Pandas DataFrame, both rows and columns have indexes, where each index value means that particular number of rows in a DataFrame. This method returns a list of all the index values which are assigned with each row.
Syntax:
DataFrame.index()
To work with Python Pandas, we need to import the pandas library. Below is the syntax,
import pandas as pd
Example:
Output:

need an explanation for this answer? contact us directly to get an explanation for this answer