0

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.

User123
  • 29
  • 9
  • 2
    That's not a pandas Series; but for pandas Series, try: `a.index[a.eq(2)].tolist()` –  Feb 17 '22 at 21:40

1 Answers1

0

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

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