Dataset Conversion Issue

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.

from heapq import nlargest

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

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

allRowsList = []
for row in pydata:
	rowList = []
	for column in column_headers:

#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:


#Compare the indexes and remember the column	
headersOut = []
for items in colHeadersIdxList:
	if items[0] in rowOut:

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

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

table = event.source.parent.getComponent('tHistoryData 1')
ds =
sortable = [(ds.getValueAt(0, c), c) for c in range(1, ds.columnCount)]
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') = system.dataset.toDataSet(headers, [values])

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

1 Like