Pandas:获取Series对象中值的标签

18

如何从Pandas Series对象中检索特定值的标签名称:

例如:

labels = ['a', 'b', 'c', 'd', 'e']
s = Series (arange(5) * 4 , labels)

生成该系列的方法为:

a     0
b     4
c     8
d    12
e    16
dtype: int64

如何获取值为'12'的标签?谢谢。

1个回答

19

您可以通过以下方式获取子序列:

In [90]: s[s==12]
Out[90]: 
d    12
dtype: int64

此外,您可以通过

In [91]: s[s==12].index
Out[91]: Index([d], dtype=object)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接