【发布时间】:2019-04-09 00:25:45
【问题描述】:
这是我的字典结构
dic = {'tt3832096': ['remake', 'horror-movie-remake', 'flesh-eating-virus', 'gore'],
'tt6217804': ['chainsaw', 'sequel', 'second-part', 'mable-simmons-character']}
我想将它保存在 csv 文件中,如下所示:
movie id keyword
tt3832096 ['remake', 'horror-movie-remake', 'flesh-eating-virus', 'gore']
tt6217804 ['chainsaw', 'sequel', 'second-part', 'mable-simmons-character']
我试过这个:
with open('test.csv', 'w') as f:
for key in dic.keys():
f.write("%s:%s\n"%(key,dic[key]))
但是它将每个值项放在一个单元格中。有没有更好的办法?
【问题讨论】:
标签: python csv dictionary export-to-csv