# Merge csv files with different and same headers

**URL:** <https://forum.knime.com/t/merge-csv-files-with-different-and-same-headers/13271>\
**Category:** KNIME Analytics Platform\
**Created:** [January 24, 2019, 7:13pm UTC](https://forum.knime.com/t/merge-csv-files-with-different-and-same-headers/13271 "2019-01-24T19:13:02Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hugo](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/h/b38774/32.png) [@Hugo](https://forum.knime.com/u/Hugo)\
**Post date:** [January 24, 2019, 7:13pm UTC](https://forum.knime.com/t/merge-csv-files-with-different-and-same-headers/13271/1 "2019-01-24T19:13:02Z")

</div>

Hi all !

After a lot of research in your forum, I can’t find a solution for my problem…  
I’m using Knime 3.7.0.

I’ve a lot of .csv files like that :

 ![Data](https://forum-cdn.knime.com/uploads/default/original/2X/9/9f1a9430a9dad7452f8dcd1029c7f41a4f9a198c.png)

All csv have same A to F columns.  
But from G to the end, sometimes there are same columns, sometimes not.  
Each lines of each csv files are unique.

I’ve try column combiner, but I,ve some errors…

 ![Knime](https://forum-cdn.knime.com/uploads/default/original/2X/d/dbb029724e3b56dc3a317341076a8af9d70a4988.png)

ERROR File Reader 2:17 Execute failed: Too few data elements (line: 1 (Row0), source: ‘file:/P:/Exportations\_LabPlus/resultatspreliminaires%20(10).csv’)

I’m very new with Knime and I don’t know how to begin to solve my problem…

Thanks a lot !  
Hugo.

---

<div class="post-metadata">

**Author:** ![mlauber71](https://forum-cdn.knime.com/user_avatar/forum.knime.com/mlauber71/32/73590_2.png) [@mlauber71](https://forum.knime.com/u/mlauber71)\
**Post date:** [January 24, 2019, 7:36pm UTC](https://forum.knime.com/t/merge-csv-files-with-different-and-same-headers/13271/2 "2019-01-24T19:36:18Z")

</div>

Could you provide us with data representing your problem. If you cannot share the date because of privacy and confidentiality you might want to create files that have the same logical structure as your problem. From the screenshot I have a few questions

- do you have ‘stable’ headers? would they always be on the same row or might that be different? (If different is there an indicator identifying the Header)
- do you want to use IDs and merge the various lines so that you have all the different columns or would you just store them beneath each other while there might be more and more columns
- do you have columns with different names that still would carry the same information and do you want to combine them?

From the screenshot my impression is that you would need several steps. You might have to extract the column information first and then the data itself from line 5 on. You can later bring back the column names with the:

> **[Insert Column Header — NodePit](https://nodepit.com/node/org.knime.base.node.preproc.columnheaderinsert.ColumnHeaderInsertNodeFactory)**
>
> Updates column names of a table according to the mapping in 
> second dictionary table.

---

<div class="post-metadata">

**Author:** ![Hugo](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/h/b38774/32.png) [@Hugo](https://forum.knime.com/u/Hugo)\
**Post date:** [January 24, 2019, 8:21pm UTC](https://forum.knime.com/t/merge-csv-files-with-different-and-same-headers/13271/3 "2019-01-24T20:21:31Z")

</div>

Hello @mlauber71 !

I’ve attached two examples of csv files.  
[resultatspreliminaires (1).zip](https://forum-cdn.knime.com/uploads/default/original/2X/4/4fe37ebf4e17a12c2f1a7df66c69d32ec8e4a650.zip) (13.2 KB)

- Columns header is always in the same row (row number 2)
- I’m not sure to understand. I would like to have one file with one time each differents columns, and one time each differents rows one below the other
- No. If the columns have the same name, they are the same things. Otherwise, they have a different name.

Thanks !!  
Hugo.

---

<div class="post-metadata">

**Author:** ![mlauber71](https://forum-cdn.knime.com/user_avatar/forum.knime.com/mlauber71/32/73590_2.png) [@mlauber71](https://forum.knime.com/u/mlauber71)\
**Post date:** [January 24, 2019, 10:20pm UTC](https://forum.knime.com/t/merge-csv-files-with-different-and-same-headers/13271/4 "2019-01-24T22:20:02Z")

</div>

Well well. I set up a workflow that hopefully does what you want. The CSV data really seems to be quite messy with funny column headers and stuff. For the “_resultatspreliminaires (15).csv_” I had to revert to my trusted [readr package from R](https://forum.knime.com/t/error-with-file-reader-node-while-running-in-a-loop/11263/3). I really would recommend investing in some useful data storage concepts - CSV is widespread but also unstable and messy. Why not use Parquet, or SQLite, or [ARFF](https://waikato.github.io/weka-wiki/arff/) - all supported by KNIME - but that is just me 🙂

The workflow assumes the first 6 columns are always the same and gives them the names Column1 - 6 (you can later rename them to something useful).

Then I use readr to just import the data and determine the column headers and where the real data starts when the first line of Column1 does not have any missing (you might have to tweak that, give a fix number or delete some rows with missing data).

Then I load the data starting from the recently identified 1st row. Then the column names get assigned back.

hmm might be again a little bit over-engineered but I hope it works. Feel free to adapt it.

 ![image](https://forum-cdn.knime.com/uploads/default/original/2X/8/8219f8511db2b09fc64da1ec116b22dc19f30d56.png)

[kn\_example\_read\_multiple\_resultatspreliminaires.knar](https://forum-cdn.knime.com/uploads/default/original/2X/a/a04079436c2bfd0c1e05655c79b3aee66bf68e80.knar) (276.0 KB)

---

<div class="post-metadata">

**Author:** ![Hugo](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/h/b38774/32.png) [@Hugo](https://forum.knime.com/u/Hugo)\
**Post date:** [January 25, 2019, 6:20pm UTC](https://forum.knime.com/t/merge-csv-files-with-different-and-same-headers/13271/5 "2019-01-25T18:20:16Z")

</div>

Excellent !

For the moment, I can’t try it because I’ve some issues with R and Knime connection…  
But I will come back here when I had tried it.

I’m working with our IT support to modify the output data form, because I know that it’s horrible…  
But you know… IT are not usually very fast… especially in large companies…

Thanks !

---

<div class="post-metadata">

**Author:** ![mlauber71](https://forum-cdn.knime.com/user_avatar/forum.knime.com/mlauber71/32/73590_2.png) [@mlauber71](https://forum.knime.com/u/mlauber71)\
**Post date:** [January 25, 2019, 6:24pm UTC](https://forum.knime.com/t/merge-csv-files-with-different-and-same-headers/13271/6 "2019-01-25T18:24:29Z")

</div>

> [@Hugo](#):
>
> I’m working with our IT support to modify the output data form, because I know that it’s horrible…  
> But you know… IT are not usually very fast… especially in large companies…

never heard of _that_ … 😉

Glad it works. R and KNIME is sometimes a little bit complicated because you need to have RServe working and the latest version of that needs to be compiled. I can provide you with some links about that.

Install R

> [@Importing R Code in Knime](https://forum.knime.com/t/importing-r-code-in-knime/11260/3):
>
> There are two basic possibilities to use R with KNIME you have a R version on your computer and you point KNIME to it (“KNIME Interactive R Statistics Integration”) KNIME provides you with an ‘integrated’ R package that sits somewhere deep in the KNIME folders (“KNIME R Statistics Integration (Windows Binaries)”) I would advise to use the first option. So first to proper install R (and maybe RStudio to have an easier handling) and then point KNIME to it. There are further R integrations but t…

RServe compilation

> [@KNIME : R evaluation failed.](https://forum.knime.com/t/knime-r-evaluation-failed/12560/13):
>
> And another thing. If you have to use the newest version of RServe you will have to compile the package. On MacOS you will need the packages mentioned on the relevant R website: [https://cran.r-project.org/bin/macosx/](https://cran.r-project.org/bin/macosx/) On a windows system you will have to compile the package with the help of RTools [https://cran.r-project.org/bin/windows/base/rw-FAQ.html#Can-I-install-packages-into-libraries-in-this-version\_003f](https://cran.r-project.org/bin/windows/base/rw-FAQ.html#Can-I-install-packages-into-libraries-in-this-version_003f) I recently noted that at least when compiling the RServe package Rtools does not li…

> [@Issue with KNIME R version](https://forum.knime.com/t/issue-with-knime-r-version/12562/10):
>
> I mean the up to three KNIME extensions about R as mentioned before. I would deinstall them an install them again. Maybe first only using the “R Scripting extension” [image] From my experience the most important thing is to update RServe to the latest version (1.8-6). You will have to compile the package yourself (depending on your platform) since there is no binary version ready for download (yet). [http://www.rforge.net/Rserve/files/](http://www.rforge.net/Rserve/files/) [image] Download the .tar file and use it to install a …

---

<div class="post-metadata">

**Author:** ![system](https://forum-cdn.knime.com/uploads/default/original/1X/ab3ccf34482a0329361734a18199390177204f15.png) [@system](https://forum.knime.com/u/system)\
**Post date:** [June 23, 2023, 8:32pm UTC](https://forum.knime.com/t/merge-csv-files-with-different-and-same-headers/13271/7 "2023-06-23T20:32:22Z")

</div>


