waitingkuo
waitingkuo

Reputation: 93804

Is there a `in` like statement for a Pandas Series?

I can easily check whether each is equal to a number:

In [20]: s = pd.Series([1, 2, 3])                                                                                                                

In [21]: s == 1
Out[21]: 
0     True
1    False
2    False

My problem is, is there a function like s._in([1, 2]) and output something like

0     True
1     True
2     False    

Upvotes: 1

Views: 119

Answers (1)

BrenBarn
BrenBarn

Reputation: 251378

Yes, it is called isin. Do s.isin([1, 2]).

Upvotes: 4

Related Questions