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

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.
for mode in traits['sdm.devices.traits.ThermostatEco']['availableModes']:
for mode in traits['sdm.devices.traits.ThermostatMode']['availableModes']:
print len(modes),len(modesHeader)
print len(modesEco),len(modesHeaderEco)
And I keep getting the error. So for a sanity check I did this and got the same error.

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

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

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:

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. }

I did end up doing this

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']])