1

I have two Dataframes

df1:

A   B   C   D   E   F   G
1   2   3   4   5   6   7
8   9   0   1   2   3   4
5   6   7   8   9   0   1

df2:

A   B   C   D   E   F   G
5   6   7   8   9   0   1

how would I remove the rows that are in df2 so that:

output:

A   B   C   D   E   F   G
1   2   3   4   5   6   7
8   9   0   1   2   3   4

I have looked at other examples and most of them join based off one column, how do you do this with multiple columns?

  • 1
    https://stackoverflow.com/questions/53645882/pandas-merging-10. You want the left-excluding merge, in the top rated answer – ALollz Jan 22 '21 at 19:21

1 Answers1

3

Try merge

out = df1.merge(df2,how='left',indicator=True).loc[lambda x : x['_merge']=='left_only']
Out[128]: 
   A  B  C  D  E  F  G     _merge
0  1  2  3  4  5  6  7  left_only
1  8  9  0  1  2  3  4  left_only
BENY
  • 317,841
  • 20
  • 164
  • 234