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)) |
chevron_right
filter_none
Recommended Posts:
- Reading an excel file using Python
- Python | Split given list and insert in excel file
- Python | Trigonometric operations in excel file using openpyxl
- Python | Arithmetic operations in excel file using openpyxl
- Python | Writing to an excel file using openpyxl module
- Python | Reading an excel file using openpyxl module
- Python | Create and write on excel file using xlsxwriter module
- Python | Adjusting rows and columns of an excel file using openpyxl module
- reStructuredText | .rst file to HTML file using Python for Documentations
- Writing to an excel sheet using Python
- Python Object Comparison : "is" vs "=="
- Python | How to copy data from one excel sheet to another
- Python | Convert an HTML table into excel
- Chaining comparison operators in Python
- Python | Data Comparison and Selection in Pandas
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



