我试图将以下字典保存为csv。我的词典内容的格式是:将字典保存为CSV python
dict = {0:[u'ab', u'cd'], 1:[u'b'], 2: [u'Ge', u'TT'], 3: [u'Stas'], 4: [u'sap', u'd3', u'ch99']}.
我的代码是:
with open('Cr_pt.csv', 'wb') as f:
writer = csv.writer(f)
writer.writerow(dict.keys())
writer.writerows(zip(*dict.values())).
下面是我想在CSV保存格式。
1 2 3 4
ab Ge Stas sap
cd TT d3
ch99
但是我得到我的最终CSV从字典中只有很少的值,如:
1 2 3 4
ab Ge Stas sap
什么是你想要的输出格式,给出的字典输入你提供的? –
请参阅下面的答案 –