# Sorting through a dataset

**URL:** <https://forum.inductiveautomation.com/t/sorting-through-a-dataset/80709>\
**Category:** Ignition\
**Tags:** python, perspective\
**Created:** [October 19, 2023, 4:39pm UTC](https://forum.inductiveautomation.com/t/sorting-through-a-dataset/80709 "2023-10-19T16:39:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hw79](https://avatars.discourse-cdn.com/v4/letter/h/838e76/32.png) [@hw79](https://forum.inductiveautomation.com/u/hw79)\
**Post date:** [October 19, 2023, 4:39pm UTC](https://forum.inductiveautomation.com/t/sorting-through-a-dataset/80709/1 "2023-10-19T16:39:15Z")

</div>

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

```auto
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

```auto
    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!

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [October 19, 2023, 4:46pm UTC](https://forum.inductiveautomation.com/t/sorting-through-a-dataset/80709/2 "2023-10-19T16:46:24Z")

</div>

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

```python
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)

```

---

<div class="post-metadata">

**Author:** ![hw79](https://avatars.discourse-cdn.com/v4/letter/h/838e76/32.png) [@hw79](https://forum.inductiveautomation.com/u/hw79)\
**Post date:** [October 19, 2023, 4:50pm UTC](https://forum.inductiveautomation.com/t/sorting-through-a-dataset/80709/3 "2023-10-19T16:50:12Z")

</div>

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

I appreciate your time!
