我正在尝试从excel表格中读取数据,并在循环中形成一个字典,如下所示。
for row in range(2,sheet.max_row+1):
temp_list.clear()
for col in range (2,sheet.max_column):
temp_list.append(sheet.cell(row,col).value)
dict_key = sheet.cell(row,1).value
Create a dictionary
MyDataDictionary.update( {dict_key : temp_list})假设我的excel有两行我正在读取的数据,我的字典值总是被第二行的值覆盖。
发布于 2020-01-23 19:34:49
(创建字典)如果这是您代码的一部分,我认为您的字典是在您每次运行循环时创建的,因此您应该在运行循环之前创建字典,然后更新它
https://stackoverflow.com/questions/59877359
复制相似问题