# Dataset Conversion Issue

**URL:** <https://forum.inductiveautomation.com/t/dataset-conversion-issue/16843>\
**Category:** Ignition\
**Created:** [February 2, 2018, 12:05am UTC](https://forum.inductiveautomation.com/t/dataset-conversion-issue/16843 "2018-02-02T00:05:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![S007](https://avatars.discourse-cdn.com/v4/letter/s/7cd45c/32.png) [@S007](https://forum.inductiveautomation.com/u/S007)\
**Post date:** [February 2, 2018, 12:05am UTC](https://forum.inductiveautomation.com/t/dataset-conversion-issue/16843/1 "2018-02-02T00:05:26Z")

</div>

Hi, I’m grabbing dataset off a table with changeable number of columns but one row. First column is always time\_stamp and rest are integer values. Trying to grab the five highest values and put in a new table. At the very end, I get this error “TypeError: can’t convert Dataset [1R ? 5C] to [[Ljava.lang.Object;” . Any help would be much appreciated. Thanks.

```auto
from heapq import nlargest

table = event.source.parent.getComponent('tHistoryData 1')
pydata = system.dataset.toPyDataSet(table.data)
column_headers = list(pydata.getUnderlyingDataset().getColumnNames())

#print " ****Column Headers with the Indexes*****"
colHeadersIdxList = []
for item in enumerate(column_headers):
	colHeadersIdxList.append(item)

allRowsList = []
for row in pydata:
	rowList = []
	for column in column_headers:
		rowList.append(row[column])
	allRowsList.append(rowList)

#print " ***Create a new list with the top 5 values and indexes****"
trimmedList = []
for data in allRowsList:
	trimmedList.append(nlargest(5, enumerate(data), key=lambda x: x[1]))

# ***Final headers and values**"
columnOut = []
rowOut = []
finalColumn = []
for elements in trimmedList:
	for items in elements:
		rowOut.append(items[0])
		columnOut.append(items[1])

finalColumn.append(columnOut)

#Compare the indexes and remember the column	
headersOut = []
for items in colHeadersIdxList:
	if items[0] in rowOut:
		headersOut.append(items[1])

finalData = system.dataset.toDataSet(headersOut,finalColumn)
newTable = event.source.parent.getComponent('tHistoryData 2').data
newTable.data = finalData

```

---

<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:** [February 2, 2018, 12:45am UTC](https://forum.inductiveautomation.com/t/dataset-conversion-issue/16843/2 "2018-02-02T00:45:19Z")

</div>

I think you’re making this too hard. Try:

```auto
table = event.source.parent.getComponent('tHistoryData 1')
ds = table.data
sortable = [(ds.getValueAt(0, c), c) for c in range(1, ds.columnCount)]
sortable.sort()
top5 = sortable[-5:]
values = [x[0] for x in top5]
headers = [ds.getColumnName(x[1]) for x in top5]
newTable = event.source.parent.getComponent('tHistoryData 2')
newTable.data = system.dataset.toDataSet(headers, [values])

```

---

<div class="post-metadata">

**Author:** ![S007](https://avatars.discourse-cdn.com/v4/letter/s/7cd45c/32.png) [@S007](https://forum.inductiveautomation.com/u/S007)\
**Post date:** [February 2, 2018, 3:52pm UTC](https://forum.inductiveautomation.com/t/dataset-conversion-issue/16843/3 "2018-02-02T15:52:25Z")

</div>

Yup…that worked fine. You are right…I was down in the rabbit hole. Thanks a lot.
