我一直在 excel 中工作,我正在尝试获取带有键和值的字典。这是我的表:int1 int2 int3 int4 int5core_6 2 22 32 core_8 23.34.34.4572.20.20.20 11 33 core_7 core_work255.255.255.0 12 12 core_12 44 我正在尝试制作为:{'int1' : 'core_6' '72.20.20.20' ,'255.255.255.0' 'int2': and so on}.我的代码面临的问题是:import xlrdworkbook = xlrd.open_workbook('input.xlsx')workbook = xlrd.open_workbook('input.xlsx', on_demand = True)worksheet = workbook.sheet_by_name("GlobalInfo")my_dict = {}for i in range(2): row = worksheet.row_values(i) my_dict[row[1]] = row[1::]d =dict((k, v) for k,v in my_dict.items() if k is not None and k != '')for x in d: print(d[x])my_di = {k: '' for k in d[x]} print(my_di) ////take all the int1 as keysworksheet.cell_value(0, 1) num_rows = worksheet.nrows - 1curr_row = 1kk = []while curr_row < num_rows: curr_row += 1 row = worksheet.row(curr_row) kk.append(row[1].value)print(kk) ///this will print value of 1st row但我无法为我制作的键添加值。我也无法获得其他行的值。
添加回答
举报
0/150
提交
取消