Python Forum
Check DataFrames with different sorting in columns and rows - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Check DataFrames with different sorting in columns and rows (/thread-38746.html)



Check DataFrames with different sorting in columns and rows - Foxyskippy - Nov-19-2022

Hi,

I got multiple excel file which needs to be need if OLD data is matching NEW data. Normally I use dataframe.equals but since the NEW data is containing additional columns this doesn't work anymore.

Very excel file contains two tabs with OLD and NEW data. I have to check if the OLD data is matching per record in NEW. The issue of NEW is that columns aren't in the same order, additional columns plus record aren't in the same order.

The key of this is table is the combination of column 4 and column 8.

How can I print the record those aren't matching?

import os
import pandas as pd

TargetFolder = os.listdir('Dir')

for file in TargetFolder:
  
    df = pd.ExcelFile('TargetFolder' + file)

    dfPrep = pd.read_excel(df, 'OLD')
    dfCE = pd.read_excel(df, 'NEW')
    
    Checkdf = dfPrep.equals(dfCE)
[attachment=2106][attachment=2105]