Pandas: Get label for value in Series Object

Andy picture Andy · May 8, 2013 · Viewed 18.6k times · Source

How is it possible to retrieve the labe of a particular value in a pandas Series object:

For example:

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

Which produces the Series:

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

How is it possible to get the label of value '12'? Thanks

Answer

waitingkuo picture waitingkuo · May 8, 2013

You can get the subseries by:

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

Moreover, you can get those labels by

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