在Python中将清单清单写入csv [英] Write a list of lists into csv in Python
本文介绍了在Python中将清单清单写入csv的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个这样的纯数据列表列表
I have a list of lists of pure data like this
a=[[1,2,3],
[4,5,6],
[7,8,9]]
如何将a
写入CSV文件,并且每个列表都在这样的列中?
How can I write a
into a CSV file with each list in a column like this?
1 4 7
2 5 8
3 6 9
推荐答案
使用:
import csv
with open('output.csv', 'w', newline='') as csvfile:
writer = csv.writer(csvfile)
writer.writerows(list(zip(*l)))
这篇关于在Python中将清单清单写入csv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文