Pandas analogue to SQL MINUS / EXCEPT operator, using multiple columns

后端 未结 5 1757
离开以前
离开以前 2020-11-30 15:35

I\'m looking for the fastest and idiomatic analog to SQL MINUS (AKA EXCEPT) operator.

Here is what I mean - given two Pandas DataFrames as follows:

I         


        
5条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-30 16:04

    I am thinking a little bit like excel here:

    d1[~d1[['a','b']].astype(str).sum(axis=1).isin(d2[['a','b']].astype(str).sum(axis=1))]
    

       a  b  c
    1  0  1  2
    2  1  0  3
    6  2  2  7
    

提交回复
热议问题