小编Hum*_*boy的帖子

将 Excel 的列转换为 python 中的字典

我的 Excel 文件中有三列,我必须使用 xlrd 将前两列的所有行转换为字典。

预期输出:

{'Sam' : 'Tester', 'John' : 'Developer', 'Fin' : 'Tester'}
Run Code Online (Sandbox Code Playgroud)

Excel 文件的屏幕截图

for i in range(1, worksheet.nrows):
    row = worksheet.row_values(i)
    variable = row[0] + row[1]
    print(" {0} {1}".format(row[0],format(row[1])))
    print(variable)
Run Code Online (Sandbox Code Playgroud)

该代码打印前两列。如何转换为字典类型?

python excel dictionary xlrd

2
推荐指数
1
解决办法
7301
查看次数

标签 统计

dictionary ×1

excel ×1

python ×1

xlrd ×1