Home > Net >  I need to compare one column in 2 csv file and find the missing values and print the missing in new
I need to compare one column in 2 csv file and find the missing values and print the missing in new

Time:06-14

CSV1:

Name Gender Sl_no
Abc     f     5
xyx     m     10
hhh     f     20 

csv2:

Sl_no Name Gender 
  10   bla   bla
   5   bla   bla  

Here I only care about the sl_no column, which is in a different index in both the tables and i only need the missing value in cs2 sl_no. How do i do this using python

CodePudding user response:

You could use loc with isin.

import pandas as pd

csv1 = pd.read_csv('path/to/csv1')
csv2 = pd.read_csv('path/to/csv2')

missing = csv1.loc[~csv1['Sl_no'].isin(csv2['Sl_no']), 'Sl_no']
print(missing)
  • Related