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
:
df.index.get_loc(index_value)
Out[67]: 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With