identify present element in dataframe pandas?

  dataframe, pandas, python, python-3.x

i have a first dataframe :

 id ;  name ; job
 AAA1; reacher; doctor
 ZZZ2; pete; nurse
 SSS3; wilson; prof

and second dataframe :

 pk ;  name ; job
 AAA1; reacher; Doctor
 MOIU8; pete; Nurse
 HYA1; wilson; Prof

we suppose that code = pk = id

i want to identify code which exist in dataframe1 and not in the dataframe2 and which code exists in dataframe 2 and not in dataframe 1 with pandas

import pandas as pd 
    


# List1 
lst = [['AAA1', 'reacher', "doctor"], ['ZZZ2', 'pete', "nurse"],
       ['SSS3', 'wilson', "prof"], ]
    
df1 = pd.DataFrame(lst, columns =['id', 'name', 'job'], dtype = float)

# List1 
lst = [['AAA1', 'reacher', "doctor"], ['MOIU8', 'koko', "nurse"],
       ['HYA1', 'andray', "prof"], ]
    
df2 = pd.DataFrame(lst, columns =['pk', 'name', 'job'], dtype = float)

Source: Python-3x Questions

LEAVE A COMMENT