user6162407 user6162407 - 4 months ago 10x
Python Question

Access the row number by its index

I'm trying to access the row number with an index value corresponding to that row.

mydata = [{'name': 'John', 'age': 75, 'height':1.78},
{'name': 'Paul', 'age': 22, 'height':1.71}]

df = pandas.DataFrame(mydata)
df = df.set_index('name')

Get index value of row number 1

index_value = df.index[1]

With having that index value, how do I go about returning a row number? In this case, 1.


You can also use get_loc:

Out[67]: 1