Write dictionary values in an excel file

后端 未结 1 765
孤独总比滥情好
孤独总比滥情好 2020-12-08 11:46

I have a dictionary with multiple values for each key. I add the values using the following code:

d.setdefault(key, []).append(values)

The

相关标签:
1条回答
  • 2020-12-08 12:09

    It seems like you want something like this:

    import xlsxwriter
    
    workbook = xlsxwriter.Workbook('data.xlsx')
    worksheet = workbook.add_worksheet()
    
    d = {'a':['e1','e2','e3'], 'b':['e1','e2'], 'c':['e1']}
    row = 0
    col = 0
    
    for key in d.keys():
        row += 1
        worksheet.write(row, col, key)
        for item in d[key]:
            worksheet.write(row, col + 1, item)
            row += 1
    
    workbook.close()
    
    0 讨论(0)
提交回复
热议问题