Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (17.6k points)

Sorry just getting into Pandas, this seems like it should be a very straight forward question. How can I use the isin('X') to remove rows that are in the list X? In R I would write !which(a %in% b).

1 Answer

0 votes
by (41.4k points)

You can use numpy.logical_not to invert the boolean array returned by isin:

s = pd.Series(np.arange(10.0))

x = range(4, 8)

mask = np.logical_not(s.isin(x))

 S[mask]

Output: 

0    0

1    1

2    2

3    3

8    8

9    9

Browse Categories

...