Python equivalent of the R operator "%in%"
FWIW: without having to call pandas, here's the answer using a for loop
and list compression
in pure python
x = [2, 3, 5]
y = [1, 2, 3]
# for loop
for i in x: [].append(i in y)
Out: [True, True, False]
# list comprehension
[i in y for i in x]
Out: [True, True, False]
Pandas comparison with R docs are here.
s <- 0:4
s %in% c(2,4)
The isin
method is similar to R %in% operator:
In [13]: s = pd.Series(np.arange(5),dtype=np.float32)
In [14]: s.isin([2, 4])
Out[14]:
0 False
1 False
2 True
3 False
4 True
dtype: bool