![](/img/trans.png)
[英]How to complete a CSV file with data from a Python dictionary in progress
[英]How to write complete dictionary in existing csv file in loop using python
我想将字典写入循环内新列中的现有.CSV
中。
我的示例代码:
for loop:
keys = []
values = []
dictionary = {}`
for loop:
dictionary = dict(zip(keys,values)
编写用于在第一个循环中在 csv 文件中插入字典的代码。
我的字典数据是
{ 'string': value, 'string': value }
我想要的 CSV 数据应该是:
Count
{'string':value, 'string':value}
你的意思是这样?
dict_test = { 'string1': 22, 'string2': 33 }
with open("test.csv", "w+") as file:
file.write(str(dict_test))
作为文件中的输出,您将获得:
{'string1':22,'string2':33}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.