我試圖將以下字典保存爲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
什麼是你想要的輸出格式,給出的字典輸入你提供的? –
請參閱下面的答案 –