Skip to content
Advertisement

Find unique column values out of two different Dataframes

How to find unique values of first column out of DF1 & DF2

DF1

67      Hij
14      Xyz 
87      Pqr

DF2

43      Def
67      Lmn
14      Xyz

Output

87      Pqr
43      Def

This is how Read

import pandas as pd
df1 = pd.read_csv('Sample1.csv', sep='|')
df2 = pd.read_csv('sample2.csv', sep='|')

Advertisement

Answer

TRY:

unique_df = pd.concat([df1, df2]).drop_duplicates(subset=[0], keep=False)

NOTE : Replace 0 in subset= [0] with the first column name.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement