Python | Excel File Comparison
Last Updated :
01 Nov, 2023
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
import pandas as pd
sheet1 = pd.read_excel(r 'Book1.xlsx' )
sheet2 = pd.read_excel(r 'Book2.xlsx' )
for i,j in zip (sheet1,sheet2):
a,b = [],[]
for m, n in zip (sheet1[i],sheet2[j]):
a.append(m)
b.append(n)
a.sort()
b.sort()
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))
|
Share your thoughts in the comments
Please Login to comment...