system.dataset.filterColumns using CSV

I’m trying to filter multiple columns of a dataset using another dataset. I’m currently attempting to use the dataset to filter with by converting it to a CSV using system.dataset.toCSV, then using that as the list of column names to filter by in the filterColumn function. It doesn’t seem to work though. Anyone got any ideas on how to do this?

dataIn = event.source.data
ds = system.tag.read("datasetTag").value
list = system.dataset.toCSV(ds,0)

filter = system.dataset.filterColumns(dataIn, list)

This should work.

dataIn = event.source.data
ds = system.tag.read("datasetTag").value
list = system.dataset.getColumnHeaders(ds)

filter = system.dataset.filterColumns(dataIn, list)

Hmm. this might work if I change how the dataset tag is setup. Currently, the dataset tag has one, arbitrary header and the columns to filter by are rows. I can probably change it to a dataset tag with all column headers and no rows, then I can utilize the getColumnHeaders

Oh, I see. You could do it without changing the dataset fairly easily as well.

list = [ds.getValueAt(row, 0) for row in range(ds.rowCount)]

Of course if the item you want to filter on isn’t in column 0 you will need to change the script accordingly.

When I do this, it works but the values i’m getting are like u'Inspect' instead of Inspect so the filterColumns isn’t working

That is how items in the list print to console. It is indicating that the value in the list is a unicode string with the value of Inspect.

A list of unicode strings should work just fine for system.dataset.FilterColumns().

Have you verified that all of the values in the list are valid column names in your dataIn dataset? They will have to match exactly including case.

1 Like

Gotcha, I’m not sure what happened, but it is working now. It must have been a typo in the code by me. It is working, thank you!