转换列表中的一列

我想在Excel的字典列表中转换一列。 可能吗?

input样本:

ABCDE 0.00 10.00 22.00 10.00 15.00 1.00 81.29 28.00 23.33 18.38 

输出样本:

 somefunc(column="A") [{ "A": 0.00 }, { "A": 1.00 }] 

目前我使用这个代码,然后删除额外的键..这是没有任何意义的。

 def to_dict(file_path, header_index=0, sheet_index=0): data, keys, sheet = {}, [], _read(file_path).sheet_by_index(sheet_index) for col_index in xrange(0, sheet.ncols): keys.append(sheet.cell(header_index, col_index).value.encode("utf-8")) for row_index in xrange(2, sheet.nrows): for col_index in xrange(sheet.ncols): if keys[col_index] not in data.keys(): data[keys[col_index]] = [] data[keys[col_index]].append(sheet.cell(row_index, col_index).value) return data 

我想你可以做这样的事情:

 def to_dict(file_path, header_index=0, sheet_index=0): result = [] sheet = _read(file_path).sheet_by_index(sheet_index) for row_index in xrange(2, sheet.nrows): row_dict = {} for col_index in xrange(sheet.ncols): key = sheet.cell(header_index, col_index).value.encode("utf-8") row_dict[key] = sheet.cell(row_index, col_index).value result.append(row_dict) return result