Compare two excel files and generate a new one that contains all columns

12 visualizaciones (últimos 30 días)
Hello everyone,
I have two excel files. They are filled out with numbers and text. The first file has 6 columns, say (a, b, c, d, e, f), while the second file has one column called "g" in addition to some similar columns like (a, b, c) , i.e, second files has 4 columns (a, b, c, g).
I would like to go through each row of the second file, figure out it is equivalent with which row of the first file (which row in the first file has the same values in columns (a, b, c)), and then add the value in column "g" to the first file and generate a new excel with 7 columns (a,b,c,d,e,f,g).
Any input would be greatly appreciated! Thanks!
  2 comentarios
dpb
dpb el 6 de Mayo de 2020
By any chance are the columns named and are the names consistent between workbooks? That would be the simplest and most convenient. If not and have to match data, then it gets a little more complex if aren't all numeric or text.
Perhaps attaching a couple of small sample files to illustrate the content would be easiest for folks to work with rather than just taking a stab at it...
Susan
Susan el 7 de Mayo de 2020
Editada: Susan el 7 de Mayo de 2020
Thanks for your reply. Yes, the columns are named and the names consist between workbooks. I have attached 2 files to illustrate the content.
1st file has several columns, among those 3 of them are common between 2 files. The second file has only 4 columns and I would like to add the 4th column to the first file accordingly.
There is a chance that in one row, we cannot match the data in 3 coulmns of two files and I would like to figure out in which row it may happen.
Any help would be greatly appreciated. Thanks!

Iniciar sesión para comentar.

Respuesta aceptada

Cris LaPierre
Cris LaPierre el 7 de Mayo de 2020
Editada: Cris LaPierre el 7 de Mayo de 2020
Sounds like you want to join tables using a,b, and c as your key variables. I would use readtable to import the two spreadsheets into MATLAB (or the import tool) as tables, and then use the interactive Join Tables task in a live script to generate the correct output.
  6 comentarios
Cris LaPierre
Cris LaPierre el 7 de Mayo de 2020
Editada: Cris LaPierre el 8 de Mayo de 2020
It runs quickly for me. You have about 2000 extra rows of data in this file (delimited, but no entries). Perhaps it is struggling with that? Try removing various lines to see if you can identify which one is causing the problem.
The only real options are the 1st, 4th and 6th. You might not need the 4th anyway. The last line just gets rid of the extra rows added to the table.
Susan
Susan el 8 de Mayo de 2020
Thanks for the info. Sure, I will. Thanks again!

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by