Let's say I have a list like this:
time type value
80 1A 10
100 1A 20
60 18 56
80 18 7
80 2A 10
100 2A 10
80 28 10
100 28 20
and I need to change it to be like this:
time
type 60 80 100
1A 10 20
1B 56 7
2A 10 10
2B 10 20
So far what I did is just basic sorting of the column:
target_column = 0
book = open_workbook('result.xls')
sheet = book.sheets()[0]
data = [sheet.row_values(i) for i in range(sheet.nrows)]
labels = data[0]
data = data[1:]
data.sort(key= lambda x: x[target_column])
bk = xlwt.Workbook()
sheet = bk.add_sheet(sheet.name)
for idx, label in enumerate(labels):
sheet.write(0, idx, label)
for idx_r, row in enumerate(data):
for idx_c, value in enumerate(row):
sheet.write(idx_r+1, idx_c, value)
bk.save('resul.xls')
How can I it with Python?
dictionarywith key as the "type" column and value as anotherdictionarywith keys as60, 80 ,100and their values with corresponding key. Example :{"1A":{80:10,100:20},"1B":{60:56,80:7}....}