GroupBy "list aggregation" as string output

Hi there,

is there a Knime-Way to create a list of all entries of a column? I know there is a “list” option in GroupBy Nodes but I do not know how to convert this list to string type.

So far I use a Python-Script Node with:

import pandas as pd

a = ".*|".join(input_table_1["Column0"])

data = {"Column0": [a]}
output_table_1 = pd.DataFrame(data)

Background of my question:
I convert this string-list to a variable and use it later as a parameterized sql query.

Andreas

PS: There is a Vernalis Node “list to string variable”. But I’m not allowed to use one of these.

Maybe the option you are looking for is Concatenate (or Unique Concatenate) instead of converting to String?

2 Likes

It’s so easy sometimes… Thanks a lot!

Hi @ActionAndi , there are a few alternatives. I’ll show you 2 of them.

We’ll use this input data as sample:
image

One of them is to use the Concatenate aggregation via the GroupBy as suggested by @toscanomatheus

You can set the delimiter that you want, in this case I set it to “|”.

Results:
image

The other one that I want to show you is useful to convert list to string, like you tried to do, so basically if you already have a list. Let’s say you have this list:
image
(It’s actually [aa,bb,cc,dd,ee,ff])

You can use the joinSep() function to “convert” the list to string. The joinSep() function will take each item of the list and join them with a separator (“joinSep” where “Sep” means separator, can be read as “join with separator”).
The expression would be:
joinSep("|", $column1$)

Results:
image

7 Likes

@bruno29a I wasn’t aware of all these opportunities! Thanks a lot!!

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