Sorting through a dataset

I have a dataset set to a custom param that I want to go through and remove rows where the IsValid column is true.

I think I can do this through a script transform

def transform(self, value, quality, timestamp):
	valueDataset = system.dataset.toPyDataSet(value)
	validRows = [row for row in valueDataset if row['IsValid'] == True]
	return validRows

This works with returning the rows, but I need it back as a regular dataset. I tried toDataSet

    filteredDataset = system.dataset.toDataSet(validRows)
    return filteredDataset

but I'm getting a ScriptEval error because I think I need to give it column headers, which I have no idea how to do that.

edit: that being said, I feel like there should/could be a more elegant way of doing this, as I lose the column names when I convert toPyDataSet.

Thanks for the help!

getColumnNames() is what you're looking for. This should work with either dataset type.

def transform(self, value, quality, timestamp):
	valueDataset = system.dataset.toPyDataSet(value)
	validRows = [row for row in valueDataset if row['IsValid'] == True]
	headers = list(value.getColumnNames())
	return system.dataset.toDataSet(headers, validRows)
2 Likes

That was it, thank you! I knew it would be something simple.

I appreciate your time!

1 Like