Pandas:获取Series Object中的值标签

And*_*ndy 16 python series pandas

如何在pandas Series对象中检索特定值的labe:

例如:

labels = ['a', 'b', 'c', 'd', 'e']
s = Series (arange(5) * 4 , labels)
Run Code Online (Sandbox Code Playgroud)

哪个系列产品:

a     0
b     4
c     8
d    12
e    16
dtype: int64
Run Code Online (Sandbox Code Playgroud)

如何获得价值'12'的标签?谢谢

wai*_*kuo 15

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

In [90]: s[s==12]
Out[90]: 
d    12
dtype: int64
Run Code Online (Sandbox Code Playgroud)

而且,你可以通过这些标签获得

In [91]: s[s==12].index
Out[91]: Index([d], dtype=object)
Run Code Online (Sandbox Code Playgroud)