1
사전 목록에서 Excel의 한 열을 변환하고 싶습니다. 가능한가?dicts 목록에서 하나의 열 변환
입력 샘플 :
A B C D E
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