Convert List to String

Hello,
I have 30 columns that I aggregated into 1 list. I now need access to this one string of values to remove duplicates and specific values to clean this string.
Unfortunately, being a list, this column is not available to the nodes that are able to assist with duplicate or specific char removal.
How can I convert the column of List datatype to string?

1 Like

Could you use a group by with an “Intersection”?

kn_example_collect_columns_group.knwf (27.1 KB)

If you use Column Aggregator node with Unique concatenate function it will eliminate duplicates and will produce a string of values separated by coma. To remove specific characters use String Manipulation node with removeChars() function.

2 Likes

Column Aggregator includes all empty fields - extra for me to clean; and unique concatenate produces, unfortunately, garbage as it removes not only duplicate strings but also some duplicate characters (makes ‘avilbe’ out of the word ‘available’).

I will try the first suggestion.

Thank you!

1 Like

I tried the intersection. It also produces the List type, not a string type.
Is there no way to convert list to string? Via Java snippet maybe?

1 Like

To be more close to solution it is necessary to see your input data and desirable result. Or current WF with data.

yes that is also possible

kn_example_collect_columns_group.knwf (41.5 KB)

3 Likes

We have a Collection to String node unreleased at present at @vernalis. When back in the office I will see about getting out released.

Steve

7 Likes

Howdy.

I’m not seeing anyone recommending the following solution for making an array into a string, or rather, a use-able object that can downstream into a node that is relevant to a non-rocket scientist like myself. So for me i ran into this because i need to export a column of arrays but the thingy only shows a few then cuts off with a “…” this is called a collection cell form what i’ve gathered!

The following helped me, as this array isn’t suiting my abilities or current problem.

join(“['”,joinSep(“‘,’”,$Split Value 1$,$Split Value 2$,$Split Value 3$,$Split Value 4$,$Split Value 5$,$Split Value 6$,$Split Value 7$),“]”)

This draws an array around the values i split out using the split arrays to column, or what i like to call my horizontal array ungrouper (trade mark pending) that makes my array use-able, excuse me it makes the “GROUP list aggregation” a use-able array. (i really hope there’s something easier lol, but i can see this logic leading to me automating adding this “column list” into this string manipulation tool so that it’s not guessing if the array happened to NOT be the exact same over and over, shhh back to explaining)

joinSep() works to get ball going optimized and fancy… and so does join() by itself, however join by itself is a lot of extra work.

join(“'”,$Split Value 1$,“'”) … imagine doing that little additional step each time, that can take a long time, joinSep() seems to be more optimal if you’re trying to still get the same array but in a STRING format :slight_smile:

My usecase needs me to make arrays i can dump into python function calls or paste there to get the ball rolling. As it’s easy to make a function with python, i need faster ways to write the functions and based on incoming data. For me i think an array will help with my python code and want to make knime automate consuming my invoice notes and make an array that then can be pushed into my python code to push to a spreadsheet template.

I need to make an array specifically with this padded “python” comments logic, you might not need it for yours, or not and then you’ll need a little less than me. Hope this helps or gets peoples juices flowing to solve their List to String or Collection cell to String solution. CHEERS!

i wrote this because i dont see the node suggested at the end of this thread, rather i found other things when i typed collection and this is what lead me to this solution.

Other helpful links that lead me to this page; each are somewhat relative to my user story and they all taught me enough to get to this thread and type the right question in google.

Good luck

3 Likes

Thank you I would have to take a look :blush:

Next interesting thing would be to bring these arrays or collections to R or Python.

1 Like

Did you know you can right-click on the header of a “collection” column to choose rendering as the full collection?

The Column Combiner node can do this for an arbitrary large set of columns.

6 Likes

That’s awesome, i had no idea this was available. Very much appreciate the help.

1 Like