Reputation: 125
I have one dataframe (df) with a column called "id". I have another dataframe (df2) with only one column called "id". I want to drop the rows in df that have the same values in "id" as df2.
How would I go about doing this?
Upvotes: 1
Views: 39
Reputation: 294198
isin
method.Note that the tilde ~
indicates that I take the negation of the boolean series returned by df['id'].isin(df2['id'])
df[~df['id'].isin(df2['id'])]
query
Using a query string we refer df2
using the @
symbol.
df.query('id not in @df2.id')
Upvotes: 2