Python Forum
Check DataFrames with different sorting in columns and rows
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Check DataFrames with different sorting in columns and rows
#1
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)

.xlsx   AA_Table002.xlsx (Size: 15.61 KB / Downloads: 115)
.xlsx   AA_Table001.xlsx (Size: 14.71 KB / Downloads: 95)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to check multiple columns value within range SamLiu 2 1,168 Mar-13-2023, 09:32 AM
Last Post: SamLiu
  Converting a json file to a dataframe with rows and columns eyavuz21 13 4,558 Jan-29-2023, 03:59 PM
Last Post: eyavuz21
  How to properly format rows and columns in excel data from parsed .txt blocks jh67 7 1,900 Dec-12-2022, 08:22 PM
Last Post: jh67
  Appending Dataframes along columns MBhuvaneshwari 1 714 Sep-25-2022, 06:32 PM
Last Post: deanhystad
  The code I have written removes the desired number of rows, but wrong rows Jdesi1983 0 1,637 Dec-08-2021, 04:42 AM
Last Post: Jdesi1983
  making variables in my columns and rows in python kronhamilton 2 1,632 Oct-31-2021, 10:38 AM
Last Post: snippsat
  rows from sql query need to write to a file as columns sjcsvatt 6 2,411 Oct-09-2021, 12:45 AM
Last Post: snippsat
  Merging spreadsheets with the same columns and extracting rows with matching entries johnbernard 3 9,943 Aug-19-2021, 03:08 PM
Last Post: johnbernard
  Summing up rows and columns plumberpy 3 2,286 Aug-18-2021, 05:46 AM
Last Post: naughtyCat
  Pandas DataFrame combine rows by column value, where Date Rows are NULL rhat398 0 2,127 May-04-2021, 10:51 PM
Last Post: rhat398

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020