![](/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.