如何从ID不存在的pandas数据框中查找记录? [英] How to find the records from a pandas dataframe which ID’s doesn’t exist?
本文介绍了如何从ID不存在的pandas数据框中查找记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有2个如下所示的pandas数据框. 我想合并它们,以便在第二个数据框中找到不存在的ID.
I got 2 pandas dataframes like below. I want to merge them so I can find the ID's in the second dataframe who doesn't exist.
+----+---------+
| ID | Name |
+----+---------+
| 1 | Henk |
| 2 | Jon |
| 3 | Sjord |
| 4 | Bjorn |
| 5 | Margita |
| 6 | Marry |
| 7 | John |
| 8 | Sam |
| 9 | Hertog |
+----+---------+
+-----+-----------+
| ID | Feature_1 |
+-----+-----------+
| 1 | 1.1 |
| 1 | 2.2 |
| 2 | 4.4 |
| 2 | 100.10 |
| 4 | 0.1 |
| 4 | 13.2 |
| 7 | 18.2 |
| 82 | 19.21 |
| 100 | 992.21 |
+-----+-----------+
如何搜索第二组中不存在的ID,并将其放置在如下所示的另一个数据框中?
How can I search which ID in the second set doesn’t exist and place them in another dataframe like below?
+-----+-----------+
| ID | Feature_1 |
+-----+-----------+
| 82 | 19.21 |
| 100 | 992.21 |
+-----+-----------+
推荐答案
使用isin
df2=df2[~df2.ID.isin(df1.ID)].copy()
这篇关于如何从ID不存在的pandas数据框中查找记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文