# Rows in datasets

**URL:** <https://forum.inductiveautomation.com/t/rows-in-datasets/81615>\
**Category:** Ignition\
**Tags:** ignition81, perspective, scripting\
**Created:** [November 7, 2023, 7:06pm UTC](https://forum.inductiveautomation.com/t/rows-in-datasets/81615 "2023-11-07T19:06:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pbg](https://avatars.discourse-cdn.com/v4/letter/p/ecd19e/32.png) [@pbg](https://forum.inductiveautomation.com/u/pbg)\
**Post date:** [November 7, 2023, 7:06pm UTC](https://forum.inductiveautomation.com/t/rows-in-datasets/81615/1 "2023-11-07T19:06:25Z")

</div>

Hi, all I want to do is return the same dataset but with only the first row left. This doesn't work since the grabbed headers aren't the right data type. How can I alter datasets efficiently?

value is a JsonDataset to PyDataset

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/a/ba766f8e95d1c53b3943fcee67ac070875cac8bc.png)

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [November 7, 2023, 7:12pm UTC](https://forum.inductiveautomation.com/t/rows-in-datasets/81615/2 "2023-11-07T19:12:48Z")

</div>

Search this forum for `DatasetBuilder` examples.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [November 7, 2023, 7:25pm UTC](https://forum.inductiveautomation.com/t/rows-in-datasets/81615/3 "2023-11-07T19:25:10Z")

</div>

I'm sorry but... those few lines hurt my brain and soul.

- there's an unconditional return in a loop, it's ALWAYS going to return and the following iterations of the loop will never happen
- it's followed by a break !
- if the loop was actually looping, you'd be pulling the same headers at every iteration

Concerning the actual problem: The headers you get from `getColumnNames` are actually not a sequence `toDataSet` accepts. It boggles my mind, but that's how it is. Cast the whole thing to a list and it will work just fine.  
The next problem you'll have is that `row` is a simple list (well... almost), but it should be a list of lists.

Here's something that should work (can't test it though):

```python
return system.dataset.toDataSet(
    list(value.columnNames),
    [value[0]]
)

```

Assuming `value[0]` is in a format `toDataSet` accepts. Otherwise, cast it to a list as well, I'm pretty sure that works.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [November 7, 2023, 8:03pm UTC](https://forum.inductiveautomation.com/t/rows-in-datasets/81615/4 "2023-11-07T20:03:29Z")

</div>

The list returned by a dataset's `columnNames` property is perfectly acceptable to a DatasetBuilder's `.colNames()` method. Same with a dataset's `.columnTypes` property and a builder's `.colTypes()` method. Then you can construct one row as a simple list, and add it to the builder with a single `.addRow()`. Then `.build()` and return.

(If you need to be sure column types are transferred, use `DatasetBuilder`.)
