# Transpose Dual-Column Dataset to Single-Row Dataset

**URL:** <https://forum.inductiveautomation.com/t/transpose-dual-column-dataset-to-single-row-dataset/90836>\
**Category:** Ignition\
**Tags:** scripting, vision, ignition81\
**Created:** [May 23, 2024, 9:36pm UTC](https://forum.inductiveautomation.com/t/transpose-dual-column-dataset-to-single-row-dataset/90836 "2024-05-23T21:36:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [May 23, 2024, 9:36pm UTC](https://forum.inductiveautomation.com/t/transpose-dual-column-dataset-to-single-row-dataset/90836/1 "2024-05-23T21:36:14Z")

</div>

I have a dual column (t\_stamp, value) dataset tag that is part of a UDT and I want another tag in the UDT to be the same data, but transposed so I can show it in a horizontal table, rather than a vertical one.

So, I have this script that works in the script console, but when called from the tag in the UDT with `runScript` I get an error when it tries to convert the tag path to an int, for whatever reason. ("cannot convert path into type: class java.lang.Integer")

```python
def transposeDualColumnDataset(path):
	'''
		Transpose a 2-column (t_stamp, value) dataset into a single-row dataset.
		
		Args:
			path	(string)	:	path to the dataset to transpose
		
		Returns:
			dataset	(dataset)	:	resulting single-row dataset. Headers are t_stamp, column values for the row are original dataset row values
	'''
	dataset = system.tag.readBlocking([path])[0].value
	#initialize empty dataset headers and data lists
	headers = []
	data = []
	
	#dataset given has exactly 2 columns
	if dataset.columnCount == 2:
		#get row count
		rowCount = dataset.rowCount
		
		#for each row
		for row in range(rowCount):
			#add the t_stamp as a header
			headers.append([str(dataset.getValueAt(row,'t_stamp'))])
			
			#add each value to the row
			data.append([dataset.getValueAt(row,'value')])
	
	return system.dataset.toDataSet(headers, [data])

```

Or, if there's a better way to do this (in Vision), please let me know.

---

<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:** [May 23, 2024, 9:55pm UTC](https://forum.inductiveautomation.com/t/transpose-dual-column-dataset-to-single-row-dataset/90836/2 "2024-05-23T21:55:43Z")

</div>

You need to use the DatasetBuilder and declare the column types as `java.lang.Object` (except the first can be string, if you are putting the original column names in the first column).

You might find my `unionAll()` expression function most efficient for such.
