Home > Blockchain >  Compare two columns from two dataframes and delete rows in one if values are equal
Compare two columns from two dataframes and delete rows in one if values are equal

Time:05-17

I have two pandas dataframes:

df1:

  ... id  ...
0     123
1     231
2     321

df2:

  ... id  ...
4     122
13    231
75    323

I need to loop over id column in df2 and if value from that column exists in df1['id'] this row should be deleted from df1. So I get:

  ... id  ...
0     123
2     321

df2:

  ... id  ...
4     122
13    231
75    323

Dataframes shapes are different so I can't concat them.

CodePudding user response:

You can check isin

out = df1[~df1['id'].isin(df2['id'])]
  • Related