# This example create a single column dataset. headers = ['col1', 'col2', 'col3'] list1= [ [1, 30, 68], [2, 23, 133], [3, 25, 65], [4, 23, 145], [5, 22, 2], [5, 31, 8], [5, 32, 30], [6, 11, 3], [6, 20, 241], [7, 22, 2], [7, 19, 202], [8, 19, 2], [8, 24, 241], [8, 13, 30], [9, 18, 19], [10, 13, 4]] mylist = system.dataset.toPyDataSet(system.dataset.toDataSet(headers, list1)) listOfRowValues=[] for row in mylist: listOfRowValues.append(row[0]) print (row[0],row[1],row[2]) # create a dictionary failCodeDesc = {10: "Ch1", 11: "Ch2", 12: "Ch3", 13: "Ch4", 18: "Ch1", 19: "Ch2", 20: "Ch3", 21: "Ch4", 22: "Ch1", 23: "Ch2", 24: "Ch3", 25: "Ch4", 30: "Ch1", 31: "Ch2", 32: "Ch3", 33: "Ch4"} newData = [] #------------------------------------------------------ def update(json, nestId, newValue): index = -1 for i, obj in enumerate(json): if obj['NestID'] == nestId: index = i if index >= 0: json[index] = newValue #------------------------------------------------------ nest1 = mylist.getColumnAsList(0) #channel list failCode1 = mylist.getColumnAsList(1) #failcode list counts1 = mylist.getColumnAsList(2) #amount of failcodes list # get list of values using map channels1 = list(map(failCodeDesc.get, failCode1)) #------------------------------------------------------ for data in mylist: for i, (w,x,y,z) in enumerate(zip(nest1, failCode1,counts1,channels1)): #checking for duplicates in the first column (duplicate NestIDs) if ((i != 0) and (nest1[i]== nest1[i-1])): #check if the firs value of first column (nestID) is the same as the previous one update(newData, nest1[i], {channels1[i]:str(counts1[i])}) else: #else, if there's unique numbers at the first column (unique NestIDs) newData.append({'NestID': str(nest1[i]), channels1[i]:str(counts1[i])}) break #------------------------------------------------------ for i in range(0, len(newData)): print(newData[i])