1

I have one csv file with following data

code
AAA
BBA
CCC

and another csv file with different structure but common column:

code
AAA
BBA
CCF

I want to find what code in first does not exist in the second dataframe. In this case CCC.

How can i do that?

Thanos
  • 2,472
  • 1
  • 16
  • 33
nnnnmmm
  • 233
  • 2
  • 6
  • 17

1 Answers1

2

Since you are using the pandas tag, I will assume you are after a solution involving pandas. If you had read both CSV files in two different dataframes, then assuming that the first CSV is read in df_1 and the second one in df_2, you could do this:

>> df_1[~df_1['code'].isin(df_2['code'])][['code']]

or

>> set(df_1['code'].values.tolist()) - set(df_2['code'].values.tolist())

or

>> set(list(df_1['code'])) - set(list(df_2['code']))

I hope this helps!

Thanos
  • 2,472
  • 1
  • 16
  • 33