获取数据框中的整数行索引,其中列与特定值匹配 [英] Get integer row-index in dataframe where column matches specific value
本文介绍了获取数据框中的整数行索引,其中列与特定值匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给定一个Pandas数据帧,其中一列是这样的:
Given a Pandas dataframe, where one of the columns looks like this:
Date
2016-04-15
2016-04-14
2016-04-13
2016-04-12
2016-04-11
2016-04-08
如果值是唯一的,我如何得到特定值的行索引?
How do I get the row-index of a particular value assuming that values are unique?
例如,2016-04-13将返回2
For example, "2016-04-13" would return 2
推荐答案
使用 df.index.get_loc('2016-04-14')
获取所请求标签的整数位置。这将返回 1
,因为intital从 0
开始。所以你可以添加一个来获得索引值 2
Use df.index.get_loc('2016-04-14')
to get the integer location for requested label. This will return 1
as intital starts from 0
. So you can add one to get the index value as 2
这篇关于获取数据框中的整数行索引,其中列与特定值匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文