concatenate column header and column values

Hi there,

I am looking for an easy, simple way to concatenate the column headers (for multiple columns) with every cell of the respective column in an elegant short way? i.e.:
original table

length             width              height
3                     5.5                 7.6
4.5                  6.5                 2

should transform to:

length             width              height
length: 3        width: 5.5        height: 7.6
length: 4.5     width: 6.5        height: 2

I tried with header extraction and handling/uniting the two resulting tables in a loop using flow variables, but there must be a simpler solution that I just cannot see?!

thanks!

Hi @roberting , one way to do this is using JSON. I always use JSON when having to mix column headers with values.

I put something together that looks like this:
image

Input (Same as yours):
image

Results:
image

Here’s the workflow: Concatenate column header and column values.knwf (16.7 KB)

EDIT: I just noticed that the whole numbers converted to decimals (3.0 and 2.0). This is because my original columns are of type decimal, and when Knime converts them to string, it adds the “.0” to whole numbers. If that is an issue, I added an additional manipulation to get rid of these.

Updated workflow looks like this:
image

And new results look like this:
image

Here’s the updated workflow: Concatenate column header and column values.knwf (18.8 KB)

6 Likes

Thanks, @bruno29a ,

not quite as short as I hoped, but this solution opened my eyes for the JSON-thing, which I haven’t looked at before … interesting!
Anyway, I will wrap it in a metanode of this and put it in my library :smiley:

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