0

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    |
+-----+-----------+

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    |
+-----+-----------+
Aercheon
  • 101
  • 5
  • See [this answer](https://stackoverflow.com/a/55554709/4909087) as well. Search for "# `not in` operation". – cs95 May 14 '19 at 20:16

1 Answers1

1

Using isin

df2=df2[~df2.ID.isin(df1.ID)].copy()
BENY
  • 317,841
  • 20
  • 164
  • 234