# Convert python dictionary to ignition dataset

**URL:** <https://forum.inductiveautomation.com/t/convert-python-dictionary-to-ignition-dataset/86531>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [February 28, 2024, 5:39pm UTC](https://forum.inductiveautomation.com/t/convert-python-dictionary-to-ignition-dataset/86531 "2024-02-28T17:39:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Travis\_Crooks](https://avatars.discourse-cdn.com/v4/letter/t/3da27b/32.png) [@Travis\_Crooks](https://forum.inductiveautomation.com/u/Travis_Crooks)\
**Post date:** [February 28, 2024, 5:39pm UTC](https://forum.inductiveautomation.com/t/convert-python-dictionary-to-ignition-dataset/86531/1 "2024-02-28T17:39:19Z")

</div>

I have a dictionary that represents one row of data from a table, the keys for the dictionary items are the column headers and the values are the value for that specific row. I am trying to write a method in scripting that will convert the dictionary into a dataset that can be used with power tables on the ignition GUI side for the user to see. I am trying to use the system.dataset.toDataSet(headers, row) method to do this. to create the headers var I do the following, headers = list(dict\_in.keys()). to create the row I am trying to create a list of list's where each child list is something like [key, value]. am I thinking of this correctly? Any advice would be appreciated.

---

<div class="post-metadata">

**Author:** ![chandler](https://avatars.discourse-cdn.com/v4/letter/c/e9a140/32.png) [@chandler](https://forum.inductiveautomation.com/u/chandler)\
**Post date:** [February 28, 2024, 9:06pm UTC](https://forum.inductiveautomation.com/t/convert-python-dictionary-to-ignition-dataset/86531/2 "2024-02-28T21:06:52Z")

</div>

The data that you pass to the toDataSet function needs to be a list of lists where each inner list is the values for one row in the same order as the headers that you pass in. There is probably a cleaner way to do this, but the following should work:

```auto
rowData = []
headers = []
for key, value in dict_in.iteritems():
    headers.append(key)
    rowData.append(value)
dataset = system.dataset.toDataSet(headers, [rowData])

```

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [February 28, 2024, 9:12pm UTC](https://forum.inductiveautomation.com/t/convert-python-dictionary-to-ignition-dataset/86531/3 "2024-02-28T21:12:11Z")

</div>

I'm a bit confused by your question because there seems to be little utility in taking a single dictionary and making it a DataSet. If you truly need just a single dictionary converted, the supplied approach above should be good enough.

If you need to convert a list of dictionaries, you an use the approach below. There are some assumptions being made in my example (like homogenous dictionaries), but this should be a general approach:

```python
def transform(self, value, quality, timestamp):
	headers = value[0].keys() # assumes all row have the exact same keys
	data = []
	for row in value:
		data.append([row[header] for header in headers])
	return system.dataset.toDataSet(headers, data)

```

---

<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:** [February 28, 2024, 10:13pm UTC](https://forum.inductiveautomation.com/t/convert-python-dictionary-to-ignition-dataset/86531/4 "2024-02-28T22:13:33Z")

</div>

> [@chandler](#):
>
> ```auto
> rowData = []
> headers = []
> for key, value in dict_in.iteritems():
> headers.append(key)
> rowData.append(value)
> 
> ```

I'll suggest this:

```python
headers = dict_in.keys()
data = dict_in.values()

```

They may or may not need to be wrapped in a `list()`

---

<div class="post-metadata">

**Author:** ![chandler](https://avatars.discourse-cdn.com/v4/letter/c/e9a140/32.png) [@chandler](https://forum.inductiveautomation.com/u/chandler)\
**Post date:** [February 28, 2024, 10:53pm UTC](https://forum.inductiveautomation.com/t/convert-python-dictionary-to-ignition-dataset/86531/5 "2024-02-28T22:53:49Z")

</div>

wasn't sure if they would be in the same order, but looking at the python docs they will be assuming no modifications to the dictionary between calls.
