List into Rows

Hi All,

I have a dataset like this -
image

I want an output like this -

ID                                   Category
Christianity                      Religion & Spirituality
Christianity                      History
True Crime                      Society & Culture
True Crime                      Documentary

Using “substr($Cat$, 0, (length($Cat$)-1))” in String Manipulation, I am able to remove the last comma from the data.

I tried to do UNGROUP on the category column, but, it doesn’t work.

Any help is highly appreciated.

I think I got it

I used
Cell splitter node with , as delimiter And choosing output as list. and finally UNGROUP.

2 Likes

Hi @dvkumaraws2019 , you can achieve this without any code required, using existing nodes.
The Cell Splitter node can split the Category using “,” as the delimiter. The trick is to tell it to split into a “List” rather than columns

This causes it to turn the cell into a String List with each of your categories as elements.

image

The “magic” happens by using this in conjunction with the “Ungroup” node, which expands your list across new rows, but in doing so “fills down” any other columns that are not being “ungrouped”

image

Attached is an example

image

List into rows.knwf (7.8 KB)

(Edit: In your sample data, you had duplicates which of course show here, so you could remove those with a Duplicate Row Filter if required, oh and you’ll want to probably add a Column Rename on the end, which I forgot ! :wink: )

2 Likes

I think you had posted while I was still writing, and I didn’t realise, but yes that’s exactly it.