# IndexError: Row 0 doesn't have the same number of columns as header list

**URL:** <https://forum.inductiveautomation.com/t/indexerror-row-0-doesnt-have-the-same-number-of-columns-as-header-list/68891>\
**Category:** Ignition\
**Created:** [January 22, 2023, 11:01pm UTC](https://forum.inductiveautomation.com/t/indexerror-row-0-doesnt-have-the-same-number-of-columns-as-header-list/68891 "2023-01-22T23:01:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![WChester](https://avatars.discourse-cdn.com/v4/letter/w/df788c/32.png) [@WChester](https://forum.inductiveautomation.com/u/WChester)\
**Post date:** [January 22, 2023, 11:01pm UTC](https://forum.inductiveautomation.com/t/indexerror-row-0-doesnt-have-the-same-number-of-columns-as-header-list/68891/1 "2023-01-22T23:01:14Z")

</div>

This is driving me crazy. What am I doing wrong? I am trying to do something like this and keep getting this error. I'm trying to do this.  
modesHeader=['Mode1','Mode2','Mode3','Mode4']  
modesHeaderEco=['Mode1','Mode2']  
modesEco=  
for mode in traits['sdm.devices.traits.ThermostatEco']['availableModes']:  
modesEco.append(mode)  
modes=  
for mode in traits['sdm.devices.traits.ThermostatMode']['availableModes']:  
modes.append(mode)  
print len(modes),len(modesHeader)  
print len(modesEco),len(modesHeaderEco)   
modeEcoDataset=system.dataset.toDataSet(modesHeaderEco,modesEco)  
modeDataset=system.dataset.toDataSet(modesHeader,modes)  
And I keep getting the error. So for a sanity check I did this and got the same error.  
headers=['thing','thing2']  
items=['toby','steak']  
dataset=system.dataset.toDataSet(headers,items)

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [January 22, 2023, 11:02pm UTC](https://forum.inductiveautomation.com/t/indexerror-row-0-doesnt-have-the-same-number-of-columns-as-header-list/68891/2 "2023-01-22T23:02:54Z")

</div>

Put each individual item in brackets `['item1'], ['item2']`

---

<div class="post-metadata">

**Author:** ![WChester](https://avatars.discourse-cdn.com/v4/letter/w/df788c/32.png) [@WChester](https://forum.inductiveautomation.com/u/WChester)\
**Post date:** [January 23, 2023, 12:11am UTC](https://forum.inductiveautomation.com/t/indexerror-row-0-doesnt-have-the-same-number-of-columns-as-header-list/68891/3 "2023-01-23T00:11:43Z")

</div>

Thank you for the input but that did not seem to fix the problem.

---

<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:** [January 23, 2023, 12:44am UTC](https://forum.inductiveautomation.com/t/indexerror-row-0-doesnt-have-the-same-number-of-columns-as-header-list/68891/4 "2023-01-23T00:44:41Z")

</div>

You don't provide any printouts to go with your code, so it is not entirely clear what your `traits` dictionary is yielding. Anyways, the key is that `system.dataset.toDataSet(headers, rows)` needs `headers` to be a list of strings that will become your column names, and `rows` must be a _ **list of lists** _, where the outer list represents rows, and in the inner lists are the column **values** for each row. Those inner lists must be the same length as `headers`.

This is valid:

```auto
ds = system.dataset.toDataSet(['a', 'b', 'c'], [[1, 'w', 2], [3, 'x', 4], [5, 'y', 6], [7, 'z', 8]])

```

Notice the nested structure of `rows`. Organize your code to do the same.

{ ps. Edit your comment, highlight all of the code, and click the "Preformatted Text" button in the comment editor. This will make a code block that will preserve code formatting for us to see. }

---

<div class="post-metadata">

**Author:** ![WChester](https://avatars.discourse-cdn.com/v4/letter/w/df788c/32.png) [@WChester](https://forum.inductiveautomation.com/u/WChester)\
**Post date:** [January 23, 2023, 1:06am UTC](https://forum.inductiveautomation.com/t/indexerror-row-0-doesnt-have-the-same-number-of-columns-as-header-list/68891/6 "2023-01-23T01:06:46Z")

</div>

I did end up doing this

```auto
modes=system.dataset.toDataSet(['Modes'], [[x] for x in traits['sdm.devices.traits.ThermostatMode']['availableModes']])
	modesEco=system.dataset.toDataSet(['Modes'], [[x] for x in traits['sdm.devices.traits.ThermostatEco']['availableModes']])

```
