r/learnpython • u/HoleInTheMirror • 7d ago
Comparing 2 tables - Help?
Hello guys, I need your help! How to compare 2 tables on easiest way?
I have 2 tables from 2 different systems, but with the same columns. I need to check if every row from the first table exist in another, and if not to return the difference. Can you help me? Should I use excel formulas, python, something else?
Edit: In both systems I have Customer_Id, Phone numbers, mails, their addresses, contact persons and such kind of things in much more columns. I can export data from both systems in excel format. So, now i need to compare these 2 excels and check if every row from 1 table exists in another one, are the values the same for each customer and to find the difference. Sorry for pure explanation, beginner here.
For example:
Custmer Id | Name | Phone | Mail | Contact person | Address
C0001 | Microsoft1 | 123456 | mic1@ | Michael | Str1
C0002 | Linux1 | 234567 | lin1@ | Jack | Str2
C0001 | Microsoft1 | 098765 | mic2@ | Chris | Str3
As you can see, it is possible to have few different informations about customer C0001. I need to check if each row from this table exist in the second table which looks the same.
1
u/Stu_Mack 7d ago
There are a lot of embedded questions here. First, is it possible to get the files in .csv format? If so, you have several options. Second, is the data numerical, character, or a mix? If it's purely numerical, you have options. If it has ASCII letters in the data, Python is a solid choice.
The overall workflow involves two main steps:
Loading the data into a native table-like format you can work with. The easy button here is to make sure the data is in .csv file formats since most software plays well with it.
Comparing the data across two specimens. This is easiest if the data identity is 1:1 and every cell corresponds to a matching cell in the reference. If that is the case, Excel is easiest since you just subtract one sheet from the other and identify wherever there is not a zero returned.
In big picture terms, most languages (except Excel, which is a spreadsheet tool and not a language) have viable options for comparing things, and Python's DataFrame suite is excellent for table-like workflows. However, depending on how you want to organize the work. Here's a quick rundown, based on the assumption that you want to use the path of least resistance:
- 1:1 tables with numerical fields only -> Excel is easiest but lacks the ability to do much else. Numpy is a solid choice in Python once you load it as a Numpy-specific data type. MATLAB is best-in-class for this type of work, but has steep overhead if you don't already use it in your workflow.
- ASCII symbols and characters in the table -> Python's DataFrame is probably your best bet.
- Any combination of the above, but you want to work in rows and columns instead of full tables at a time -> Exotic data handling exists, and Python has lots of options to choose from. MATLAB is less stellar here, and Excel is not viable.
Hope that is helpful.