Anti-Join Pandas

前端 未结 6 1080
梦谈多话
梦谈多话 2020-12-25 10:36

I have two tables and I would like to append them so that only all the data in table A is retained and data from table B is only added if its key is unique (Key values are u

6条回答
  •  甜味超标
    2020-12-25 11:16

    Easiest answer imaginable:

    tableB = pd.concat([tableB, pd.Series(1)], axis=1)
    mergedTable = tableA.merge(tableB, how="left" on="key")
    
    answer = mergedTable[mergedTable.iloc[:,-1].isnull()][tableA.columns.tolist()]
    

    Should be the fastest proposed as well.

提交回复
热议问题