Python Forum

Full Version: Check DataFrames with different sorting in columns and rows
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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]