0
私はExcelファイルを解析するためにpython xlrdモジュールを使用しています。ここでは、Excelファイルがどのように見えるかです:PythonでXLRDを使用して行と列を反復する
Title A B C
attribute 1 1 2 3
attribute 2 4 5 6
attribute 3 7 8 9
そして、私は次の形式で出力したい:私は、次の試してみましたが、中に出力を作成する方法を見つけ出すことはできません
[
{
"name": "A",
"attribute1": {
"value": 1
},
"attribute2": {
"value": 4
},
"attribute3": {
"value": 7
}
},
{
"name": "B",
"attribute1": {
"value": 2
},
"attribute2": {
"value": 5
},
"attribute3": {
"value": 8
}
},
{
"name": "C",
"attribute1": {
"value": 3
},
"attribute2": {
"value": 6
},
"attribute3": {
"value": 9
}
}
]
を上記のフォーマット。これについて助けていただければ幸いです!
from xlrd import open_workbook
wb = open_workbook('D:\abc_Template.xlsx', 'r')
wb_sheet = wb.sheet_by_index(0)
values = []
for row_idx in range(7, wb_sheet.nrows):
col_value = []
rowval = str((wb_sheet.cell(row_idx, 1)))
for col_idx in range(1, 5):
if(col_idx != 2 and col_idx != 1):
cellVal = wb_sheet.cell(row_idx, col_idx)
cellObj = {rowval: {"value" : cellVal}}
col_value.append(cellObj)
values.append(col_value)
print values