【发布时间】:2018-11-15 14:30:16
【问题描述】:
我有一个列表,我想将列表写入 CSV。但首先,写标题。
名单:
top_list = [[1,2,3],[4,5,6],[7,8,9]]
标题:
title = ['col1','col2','col3']
我想要这个结果:
但是现在,我的代码结果是:
我的代码:
import csv
top_list = [[1,2,3],[4,5,6],[7,8,9]]
title = ['col1','col2','col3']
with open(r'D:/aaa.csv', 'w', newline='', encoding='utf-8') as f:
writer = csv.writer(f)
writer.writerows(top_list)
如何修改?
【问题讨论】:
标签: python python-3.x csv