How to Get the Index of a Pandas DataFrame ?

Spread the love

To get the index of a Pandas DataFrame we can use the DataFrame index method (pandas.DataFrame.index ). The method returns the index of the DataFrame.

Let’s read a dataset to illustrate it.

import pandas as pd

url = ''
df = pd.read_csv(url)

Now, to get the index of the dataframe we can use

RangeIndex(start=0, stop=100, step=1)

To get the index as a list we can use


This will return the index in a list.

We can also use a for loop to iterate over the index.

for i in df.index:

Rating: 1 out of 5.

Leave a Reply