# Different Ways to Compare Two Columns From Two Different Files Using Pandas

## Finding common values between two columns

Published in

3 min readJan 5, 2023

During file processing, we might have encountered many situations to compare two columns from two different files. In this article, let’s look at different methods to find common values between two columns in two different files using pandas dataframe.

**Let’s find the matching values between two columns in two different files using pandas.**

First, Convert the excel file to pandas dataframe.

`df1=pd.read_excel("example1.xlsx")`

df2=pd.read_excel("example3.xlsx")

Let’s compare the “** Number”** column from the “

**with the “**

*example1”***column in “**

*Num”*

*example3”***Method 1: Using the set intersection method**

Set intersection method — will find the unique common values between two sets.

`common_values_1 = set(df1['Number'].values).intersection(set(df2['Num'].values))`

Result: {1, 2, 3, 4, 5}