DEV Community

Nilotpal Choudhury
Nilotpal Choudhury

Posted on

Answer: Remove rows not .isin('X') [duplicate]

You have many options. Collating some of the answers above and the accepted answer from this post you can do:
1. df[-df["column"].isin(["value"])]
2. df[~df["column"].isin(["value"])]
3. df[df["column"].isin(["value"]) == False]
4. df[np.logical_not(df["column"].isin(["value"]))]

Note: for option 4 for you'll need to import numpy as np

Update: You can also use the .query method…

Top comments (0)