create columns from rows

I have 5 columns. I want to convert values of first 3 rows in to columns. So 3X5 = 15 columns. And so on. Here is an example:

Input table
|Column 1|Column 2|Column 3|Column 4|Column 5|

|1|11|21|31|41|
|2|12|22|32|42|
|3|13|23|33|43|
|4|14|24|34|44|
|5|15|25|35|45|
|6|16|26|36|46|
|7|17|27|37|47|
|8|18|28|38|48|
|9|19|29|39|49|

Output Table:
image

Any Help will be much appreciated. TIA.

Hi @richakaundal , is this something you’ll need to do often, cos if not I think copy and paste would have been faster, if not so satisfying… :wink:

If I’m understanding this correctly, you want to end up with a table of 3 rows and 15 columns. The cells in the original 9 row x 5 columns will move to the following cell positions (with columns A thru O)

I modified my initial test data to make it easier to visualise where each cell was going to be heading to…
input:
image

output:

The attached workflow achieves this. It is specific in that it is based on a known number of initial rows etc so if this is something that needs to be able to scale up, some sort of loop would be in order rather than repeating the central processing (but in my defence, it was getting late! :wink: )

However, if the requirement is only ever this specific size of input and output table, then this is perhaps a possible solution or at least a starting point…

The data set that you gave:
image

becomes:

KNIME_Columns from Rows 2a.knwf (44.2 KB)

6 Likes

Thanks, Takbb!

I have more than 1000 rows in the table :smiley:, so copy paste was not an option.
I have used your logic and loop through all rows. And found solution. :smile:


image

Thank you for adding comments, it helped me understand how workflow is working.

4 Likes

Hi @richakaundal , I’m glad it assisted you’ve extended it to work across 1000 (999? :wink: ) rows!

Just kidding by the way re copy-and-paste. To be fair, a job like this would always have me reaching for a technical solution if there’s even a sniff of any danger of having to do it more than once!

I’m trying to get my head round that workflow. I like the idea of the chunk loop, but I’m trying to work out how it can work as when I tried to reproduce that, although the values went to the correct rows, they didn’t get to the correct columns.

The only way I managed to get that to generate the columns in the correct order was by modifying the String Manipulation node to create column names “out of sequence”
image

and then add a Column Resorter after the Loop End to put all the columns in alphabetical order…

Still, I may have missed something, and your loop greatly simplifies the original, so nice work!

Here is my take on it, if anybody wants to make use of it or improve further…
KNIME_Columns from Rows 2b -loop 2.knwf (31.7 KB)

5 Likes

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