[英]how to export a dictionary into a csv file in python
I have a very big dictionary and want to export into a text or csv file in such a way that keys would be in the first column and values in the 2nd column.我有一个非常大的字典,并希望以这样一种方式导出到文本或 csv 文件中,即键在第一列中,值在第二列中。 could anyone help to do so?有人可以帮忙吗?
Simply iterate through the dictionary and output:只需遍历字典并输出:
with open 'my_csv.csv' as f:
for k, v in my_dict.items(): # or iteritems in python 2
f.write("%s,%s\n" % (k, v)) # or whatever format code of your data types
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.