'How to find the indices of a certain value in pandas series [duplicate]

Suppose I have a pandas series:

a = [1 ,2 ,4 ,2 ,7 , 2 ,8]

How to tell Python to return the indices that have values equals to 2?

Thanks.



Solution 1:[1]

I think this should work. Assumiming a is a pandas series.

f = a==2
indices = f[f].index

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Kristianfkt