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

后端 未结 5 1755
离开以前
离开以前 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条回答
  •  旧时难觅i
    2020-11-30 15:57

    I had similar question, I tried your idea

    (
    In [65]: tmp1 = d1.reset_index().set_index(["a", "b"])
    
    In [66]: idx = tmp1.index.difference(d2.set_index(["a","b"]).index)
    
    In [67]: res = d1.loc[tmp1.loc[idx, "index"]]
    
    )
    

    for test and it works.

    However, I use the way in my sqlite, tow databases that have the same Structure,that means its tables and tables' columns are the same, and it occurred some mistakes, it shows that this two df seems don't have the same shap.

    if u r happy to give me a hand and want more details, we can have a further conversation thanks a lot

提交回复
热议问题