在python中将简单的Dictionary转换为Excel文件 [英] Export a simple Dictionary into Excel file in python
本文介绍了在python中将简单的Dictionary转换为Excel文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个简单的字典,键和值如下:
dict1 = {存储阵列数:45,港口数:2390,......}
我需要以获得他们在excel表如下
存储阵列数45
端口数量2390
我有一个非常大的字典。
解决方案
Sassikant,
这将打开一个名为 output.csv
的文件,并输出内容的字典转化为电子表格。第一列将具有密钥,第二列为值。
import csv
with open( 'output.csv','wb')作为输出:
writer = csv.writer(输出)
为key,dict in dictitems()中的值:
writer.writerow([key ,value])
您可以使用excel打开csv并将其保存到您想要的任何格式。
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":2390,......}
i need to get them in a excel sheet as follows
number of storage arrays 45
number of ports 2390
I have a very big dictionary.
解决方案
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.
这篇关于在python中将简单的Dictionary转换为Excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文