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(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