在DataFrame索引中查找标签位置 [英] Finding label location in a DataFrame Index
本文介绍了在DataFrame索引中查找标签位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个熊猫数据框:
import pandas as pnd
d = pnd.Timestamp('2013-01-01 16:00')
dates = pnd.bdate_range(start=d, end = d+pnd.DateOffset(days=10), normalize = False)
df = pnd.DataFrame(index=dates, columns=['a'])
df['a'] = 6
print(df)
a
2013-01-01 16:00:00 6
2013-01-02 16:00:00 6
2013-01-03 16:00:00 6
2013-01-04 16:00:00 6
2013-01-07 16:00:00 6
2013-01-08 16:00:00 6
2013-01-09 16:00:00 6
2013-01-10 16:00:00 6
2013-01-11 16:00:00 6
我有兴趣找到其中一个标签的标签位置,例如
I am interested in find the label location of one of the labels, say,
ds = pnd.Timestamp('2013-01-02 16:00')
看看索引值,我知道这是标签1的整数位置.如何使熊猫知道该标签的整数值是什么?
Looking at the index values, I know that is integer location of this label 1. How can get pandas to tell what the integer value of this label is?
推荐答案
您正在寻找索引方法get_loc
:
In [11]: df.index.get_loc(ds)
Out[11]: 1
这篇关于在DataFrame索引中查找标签位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文