Friday, September 26, 2025
HomeLanguagesPython | Excel File Comparison

Python | Excel File Comparison

Given Two Excel Files, We want to compare the values of each column row-wise after sorting the values and print the changed column name and row number and values change.

Input : 
Two Excel files

Output :
Column name : 'location' and Row Number : 0
Column name : 'location' and Row Number : 3
Column name : 'date' and Row Number     : 1

Code : Python code for comparing two excel files




# Write Python3 code here
# importing Pandas
  
import pandas as pd
  
#Reading two Excel Sheets
  
sheet1 = pd.read_excel(r'Book1.xlsx')
sheet2 = pd.read_excel(r'Book2.xlsx')
  
# Iterating the Columns Names of both Sheets
for i,j in zip(sheet1,sheet2):
     
    # Creating empty lists to append the columns values    
    a,b =[],[]
  
    # Iterating the columns values
    for m, n in zip(sheet1[i],sheet2[j]):
  
        # Appending values in lists
        a.append(m)
        b.append(n)
  
    # Sorting the lists
    a.sort()
    b.sort()
  
    # Iterating the list's values and comparing them
    for m, n in zip(range(len(a)), range(len(b))):
        if a[m] != b[n]:
            print('Column name : \'{}\' and Row Number : {}'.format(i,m))


RELATED ARTICLES

Most Popular

Dominic
32321 POSTS0 COMMENTS
Milvus
84 POSTS0 COMMENTS
Nango Kala
6690 POSTS0 COMMENTS
Nicole Veronica
11857 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11911 POSTS0 COMMENTS
Shaida Kate Naidoo
6802 POSTS0 COMMENTS
Ted Musemwa
7073 POSTS0 COMMENTS
Thapelo Manthata
6761 POSTS0 COMMENTS
Umr Jansen
6768 POSTS0 COMMENTS