[英]Access the row number by its index
我正在尝试使用与该行相对应的索引值访问行号。
mydata = [{'name': 'John', 'age': 75, 'height':1.78},
{'name': 'Paul', 'age': 22, 'height':1.71}]
df = pandas.DataFrame(mydata)
df = df.set_index('name')
获取行号1的索引值
index_value = df.index[1]
有了该索引值,我该如何返回行号? 在这种情况下,1。
您也可以使用get_loc
:
df.index.get_loc(index_value)
Out[67]: 1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.