# create columns from rows

**URL:** <https://forum.knime.com/t/create-columns-from-rows/47972>\
**Category:** KNIME Analytics Platform\
**Created:** [October 9, 2022, 10:10am UTC](https://forum.knime.com/t/create-columns-from-rows/47972 "2022-10-09T10:10:57Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![BendegzHegedus](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/b/ecc23a/32.png) [@BendegzHegedus](https://forum.knime.com/u/BendegzHegedus)\
**Post date:** [October 9, 2022, 10:10am UTC](https://forum.knime.com/t/create-columns-from-rows/47972/1 "2022-10-09T10:10:57Z")

</div>

Hi,

I’ve got a dataset which looks like this

![image](https://forum-cdn.knime.com/uploads/default/original/3X/4/7/47ee97e900bea18a6296f272fdbbb65d4884407d.png)

and so on.

I would like to create a table which looks more like this:

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

and so on.

So sort of like transpose it but at the same time using something like groupby, because I want to transpose it but because the cells are several times repeating, if I transpose it I get as many columns as I have rows but I only want as many columns as cells I have, then list the values of each cell below its own column. Also, it would be great if I could merge headers as shown but if it’s impossible it’s also good if it just says cella\_1 over the time and the voltage in each column. I thought about loops or something but i really am a beginner KNIME user so I just can’t figure this out.

I hope I was clear and I would be grateful if you could help me with this.  
Thank you

---

<div class="post-metadata">

**Author:** ![elsamuel](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/e/b4bc9f/32.png) [@elsamuel](https://forum.knime.com/u/elsamuel)\
**Post date:** [October 9, 2022, 11:55am UTC](https://forum.knime.com/t/create-columns-from-rows/47972/2 "2022-10-09T11:55:30Z")

</div>

Welcome to the forum @BendegzHegedus

A KNIME table isn’t a spreadsheet. You can’t have multiple header rows. And ideally each row of data should be a unique record. In my view, the proposed new table would require a lot of manipulation to create and would make further processing quite difficult, so I wonder if it’s the best solution to your problem.

I would suggest using a Pivoting node. Group by “time”, pivot on “cell”, and aggregate on “voltage” using First:

![image](https://forum-cdn.knime.com/uploads/default/original/3X/1/5/153dbec2676393a2feedac7ff512f363289414ec.png)

Others here might have better ideas.

---

<div class="post-metadata">

**Author:** ![iCFO](https://forum-cdn.knime.com/user_avatar/forum.knime.com/icfo/32/36036_2.png) [@iCFO](https://forum.knime.com/u/iCFO)\
**Post date:** [October 9, 2022, 1:33pm UTC](https://forum.knime.com/t/create-columns-from-rows/47972/3 "2022-10-09T13:33:03Z")

</div>

You would have to do this by writing to Excel or another external format. As @elsamuel mentioned, KNIME needs to be based off of a standard structured raw data table.

I think you would have to setup the 1st row merged column headers and then use the Excel Cell Updater to place the pivoted table info below them.

Or you could try to use this on your top row during export.

> **[XLS Cell Merger](https://hub.knime.com/continental_knime_extension_developer/extensions/com.continental.knime.feature/latest/com.continental.knime.xlsformatter.cellmerger.XlsFormatterCellMergerNodeFactory)**
>
> The XLS Cell Merger node merges the cells for given ranges of input tags. Tags in the provided XLS Control Table must appear in rectangular ranges. A single ta…

---

<div class="post-metadata">

**Author:** ![gonhaddock](https://forum-cdn.knime.com/user_avatar/forum.knime.com/gonhaddock/32/35425_2.png) [@gonhaddock](https://forum.knime.com/u/gonhaddock)\
**Post date:** [October 9, 2022, 4:12pm UTC](https://forum.knime.com/t/create-columns-from-rows/47972/4 "2022-10-09T16:12:24Z")

</div>

Hello @BendegzHegedus

Your challenge output results to be a ‘nested hierarchy in column header’ table. And as you pointed out, it’s somehow based in grouping: then the best choice is a Group Loop node and some column name rearrangement.

What is conceptually missed in your description is an output ‘row sense’ column, further than a row ID. In this case could be something like measurement\_round …

Your workflow could be something like this; considering the data is sorted by time:

> **[Data Wrangling \_ Nesting Hierarchy in Column Header – gonhaddock](https://hub.knime.com/gonhaddock/spaces/Public/latest/Data%20Wrangling%20_%20Nesting%20Hierarchy%20in%20Column%20Header~Gsec3KLaF_bWO69b)**
>
> Knime Forum: https://forum.knime.com/t/create-columns-from-rows/47972

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/c/7/c7775a8eac2ab994db0a55782f05e7b0896df1e2.png)

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/c/b/cb80f09314c6f46629a6b139093ec92046054d2a.png)

BR

PS.- Be aware that once your dada is arranged in this way, it couldn’t be usable for some analysis or visualizations, and return it back to original shape can require complex back transformations.

---

<div class="post-metadata">

**Author:** ![gonhaddock](https://forum-cdn.knime.com/user_avatar/forum.knime.com/gonhaddock/32/35425_2.png) [@gonhaddock](https://forum.knime.com/u/gonhaddock)\
**Post date:** [October 9, 2022, 8:50pm UTC](https://forum.knime.com/t/create-columns-from-rows/47972/5 "2022-10-09T20:50:30Z")

</div>

> [@gonhaddock](#):
>
> What is conceptually missed in your description is an output ‘row sense’ column, further than a row ID. In this case could be something like measurement\_round …

PS2.- This is the upper most hierarchy level.

---

<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:** [October 9, 2022, 9:46pm UTC](https://forum.knime.com/t/create-columns-from-rows/47972/6 "2022-10-09T21:46:03Z")

</div>

@BendegzHegedus you could try and adapt this example of how to create an Excel file with a complex header

> [@Positional file](https://forum.knime.com/t/positional-file/42140/4):
>
> @AlucardSTR It is possible to create complex Excel headers with the help of KNIME Continental nodes. You will have to familiarise yourself with the concept. See the links in the attached sample workflow. The workflow was initially created by @Kathrin. É possível criar cabeçalhos Excel complexos com a ajuda dos nós Continentais da KNIME. Terá de se familiarizar com o conceito. Ver as ligações no exemplo de fluxo de trabalho em anexo. O fluxo de trabalho foi inicialmente criado por @Kathrin. (…

> **[create an Excel file with a complex header with the help of Continental Excel...](https://hub.knime.com/mlauber71/spaces/Forum/2022/kn_forum_42140_excel_continental_nodes_complex_header~FLsPoDBusoKLMTWb/current-state)**
>
> create an Excel file with a complex header with the help of Continental Excel nodes

---

<div class="post-metadata">

**Author:** ![BendegzHegedus](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/b/ecc23a/32.png) [@BendegzHegedus](https://forum.knime.com/u/BendegzHegedus)\
**Post date:** [October 10, 2022, 8:57pm UTC](https://forum.knime.com/t/create-columns-from-rows/47972/7 "2022-10-10T20:57:41Z")

</div>

Hi,

thanks for all the advice on merged headers but the really important thing would be to format the table as I described, because the headers could look like in @gonhaddock and it is perfectly fine like that as well.

---

<div class="post-metadata">

**Author:** ![BendegzHegedus](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/b/ecc23a/32.png) [@BendegzHegedus](https://forum.knime.com/u/BendegzHegedus)\
**Post date:** [October 10, 2022, 9:43pm UTC](https://forum.knime.com/t/create-columns-from-rows/47972/10 "2022-10-10T21:43:05Z")

</div>

Wow this actually solved it, after i figured out what’s going on! Thank you very much! Although the java edit part is still unclear but I simply renamed the voltage columns with the flow variable cell so now it says time and the number of the cell in the header, but I think that will do.

---

<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:** [October 17, 2022, 9:43pm UTC](https://forum.knime.com/t/create-columns-from-rows/47972/11 "2022-10-17T21:43:20Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
