python pandas: how to find rows in one dataframe but not in another?

前端 未结 3 1956
醉话见心
醉话见心 2020-12-08 17:47

Let\'s say that I have two tables: people_all and people_usa, both with the same structure and therefore the same primary key.

How can I g

3条回答
  •  遥遥无期
    2020-12-08 17:50

    Here is another similar to SQL Pandas method: .query():

    people_all.query('ID not in @people_usa.ID')
    

    or using NumPy's in1d() method:

    people_all.[~np.in1d(people_all, people_usa)]
    

    NOTE: for those who have experience with SQL it might be worth to read Pandas comparison with SQL

提交回复
热议问题