user6162407 user6162407 - 1 year ago 106
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.

Answer Source

You can also use get_loc:

Out[67]: 1
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download