Export a simple Dictionary into Excel file in python

后端 未结 2 1353
南笙
南笙 2020-12-31 20:19

I am new to python. I have a simple dictionary for which the key and values are as follows

dict1 = {\"number of storage arrays\": 45, \"number of ports\":239         


        
2条回答
  •  旧时难觅i
    2020-12-31 20:46

    Sassikant,

    This will open a file named output.csv and output the contents of your dictionary into a spreadsheet. The first column will have the key, the second the value.

    import csv
    
    with open('output.csv', 'wb') as output:
        writer = csv.writer(output)
        for key, value in dict1.iteritems():
            writer.writerow([key, value])
    

    You can open the csv with excel and save it to any format you'd like.

提交回复
热议问题