Leto
Leto

Reputation: 39

How to check if value is in another column

I have this dataFrame:

df

How can I filter column G, to exclude rows that the value is in column C? The result should look like this:

df_updated

Upvotes: -2

Views: 55

Answers (2)

Celius Stingher
Celius Stingher

Reputation: 18367

You can use a mask in this case:

df_filtered = df[~df['G'].isin(df['C'])]

Upvotes: 2

Anna Semjén
Anna Semjén

Reputation: 787

Try df.loc with isin + ~ which negates it

df.loc[~df['G'].isin(df['C'].unique())]

Upvotes: 3

Related Questions