Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pandas: Get label for value in Series Object

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

like image 665
Andy Avatar asked May 08 '13 08:05

Andy


People also ask

How do I access pandas series values?

Accessing Element from Series with Position In order to access the series element refers to the index number. Use the index operator [ ] to access an element in a series. The index must be an integer. In order to access multiple elements from a series, we use Slice operation.

What are labels in pandas series?

Pandas series is a One-dimensional ndarray with axis labels. The labels need not be unique but must be a hashable type. The object supports both integer- and label-based indexing and provides a host of methods for performing operations involving the index.

Does ILOC work on series?

iloc attribute enables purely integer-location based indexing for selection by position over the given Series object. Example #1: Use Series. iloc attribute to perform indexing over the given Series object.

How do you use LOC in series?

loc attribute is used to access a group of rows and columns by label(s) or a boolean array in the given Series object. Example #1: Use Series. loc attribute to select some values from the given Series object based on the labels.


1 Answers

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)
like image 83
waitingkuo Avatar answered Oct 06 '22 06:10

waitingkuo