-1

I have two dataframes:

df1

  Person     Date Company Name Symbol   ID
0   Dale  2019 Q4       A Corp    AAA   10
1   Bill  2019 Q4       B Corp    NaN   20
2   Hank  2019 Q4       C Corp    NaN   30
3  Rusty  2019 Q4       C Corp    CCC   30
4  Peggy  2019 Q4       X Corp    NaN  100
5   John  2019 Q4       Y Corp    NaN  200
6   Kahn  2019 Q4       Z Corp    NaN  300
7   Mihn  2019 Q4       Z Corp    NaN  300

df2

  Company Name Symbol  ID
0       A Corp    AAA  10
1       B Corp    BBB  20
2       C Corp    CCC  30
3       D Corp    DDD  40
4       E Corp    EEE  50
5       F Corp    FFF  60
6       G Corp    GGG  70
7       H Corp    HHH  80
8       I Corp    III  90

And I want to create a new df3 which is made up of IDs that are in df1, but not in df2,so that the output would look like:

df3

  Company Name Symbol  ID
1       X Corp        100
2       Y Corp        200
3       Z Corp        300

How would I achieve this?

user53526356
  • 934
  • 1
  • 11
  • 25
  • What is the issue, exactly? Have you tried anything, done any research? Stack Overflow is not a free code writing service. See: [tour], [ask], [help/on-topic], https://meta.stackoverflow.com/questions/261592/how-much-research-effort-is-expected-of-stack-overflow-users. – AMC Feb 16 '20 at 04:15

1 Answers1

1

Index based on 'ID' of both dataframes

df1[~df1['ID'].isin(df2['ID'])]
busybear
  • 10,194
  • 1
  • 25
  • 42