我一直在 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但我無法為我制作的鍵添加值。我也無法獲得其他行的值。
如何grep列并將其作為值添加到字典鍵中
慕婉清6462132
2021-06-11 14:17:31