Python Forum
Need help working with two excel file with different formats
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help working with two excel file with different formats
#1
Like many one here I am new to python and would greatly appreciate any help.
I need some guidance on how to create an excel output off of two different excel files, but the files I am working with have different formats.

Input Files:
File 1 is "Holdings" and has 30 columns - ID column is in Column E, Quantity Column is in Column H

File 2 is "Tax Lot Holdings" and has 20 columns - ID column is in Column U, Quantity Column is in Column D

Output File:
4 columns are needed: ID Column, Holdings Quantity, Tax Lot Holdings Quantity, and Difference between Holdings Quantity and Tax Lot Holdings Quantity.

Where the ID column matches between the two files is where each of the holdings for each fiel would pull in and show a difference. If there is an ID on one file that is not on another, I would expect it to pull in on one side but show zero on other and show a difference in difference column.

Below is what I have code wise but the middle part of how to get different columns to intersect and get and output that has columns I need and output I am lost. If anyone can provide some direction, I would greatly appreciate it as I am just lost. I found code online that shows differences if the format of the files are the same, but that doesn't help me since these files are different formats.

Thank you

import pandas as pd
import numpy as np
import os

##os.getcwd() + '\\' + is for current working directory where python file is saved
df1=pd.read_excel(os.getcwd() + '\\' + 'Holdings.xlsx')
df2=pd.read_excel(os.getcwd() + '\\' + 'Tax Lot Holdings.xlsx')

###NEED CODE TO RECONCILE TWO FILES


df1.to_excel(os.getcwd() + '\\' + 'Excel_diff.xlsx',index=False,header=True)
Reply
#2
For simplicity sake, i propose a giant detour :
a) sort both spreadsheets on ID
b) read the 2 business columns of each one into two 2D python lists
c) Iterate over list 1[id] and seek a match in list 2[id] -> calculate or put zero if not found -> print or store in list 3
d) you'll need a trick to remember the items in list 2 that were omitted, e.g. you could set the ones that matched to -1.
e) just list the ones from list 2 that did not match

All this if i understood your problem correctly :-)
Paul
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Excel isnt working properly after python function is started IchNar 3 193 Yesterday, 10:27 AM
Last Post: lillydalson
  Python openyxl not updating Excel file MrBean12 1 365 Mar-03-2024, 12:16 AM
Last Post: MrBean12
  Excel from SAP - dealing with formats and VBA MasterOfDestr 7 637 Feb-25-2024, 12:23 PM
Last Post: Pedroski55
  Copy Paste excel files based on the first letters of the file name Viento 2 473 Feb-07-2024, 12:24 PM
Last Post: Viento
  Search Excel File with a list of values huzzug 4 1,287 Nov-03-2023, 05:35 PM
Last Post: huzzug
  Updating sharepoint excel file odd results cubangt 1 889 Nov-03-2023, 05:13 PM
Last Post: noisefloor
  Reading data from excel file –> process it >>then write to another excel output file Jennifer_Jone 0 1,134 Mar-14-2023, 07:59 PM
Last Post: Jennifer_Jone
  Save and Close Excel File avd88 0 3,118 Feb-20-2023, 07:19 PM
Last Post: avd88
  Trying to access excel file on our sharepoint server but getting errors cubangt 0 837 Feb-16-2023, 08:11 PM
Last Post: cubangt
  Working with Excel and Word, Several Questions Regarding Find and Replace Brandon_Pickert 4 1,597 Feb-11-2023, 03:59 PM
Last Post: Brandon_Pickert

Forum Jump:

User Panel Messages

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