如何在 python 中将列表转换为 csv 文件
How to convert list to csv file in python
如何在 python 中将列表转换为 csv 格式
我尝试先将其转换为数据框,但没有成功
谁能帮忙
list = [[1,2,3,4],[5,6,7,8],[9,10,11,12]]
header = ["a","b","c","d"]
至
csv:
a | b | c | d |
1 | 2 | 3 | 4 |
5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 |
试试这个?
import csv
stuff = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]
header = ["a", "b", "c", "d"]
with open("stuff.csv", "w") as f:
w = csv.writer(f, delimiter="|")
w.writerow(header)
w.writerows(stuff)
输出:
a|b|c|d
1|2|3|4
5|6|7|8
9|10|11|12
如何在 python 中将列表转换为 csv 格式 我尝试先将其转换为数据框,但没有成功 谁能帮忙
list = [[1,2,3,4],[5,6,7,8],[9,10,11,12]]
header = ["a","b","c","d"]
至
csv:
a | b | c | d |
1 | 2 | 3 | 4 |
5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 |
试试这个?
import csv
stuff = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]
header = ["a", "b", "c", "d"]
with open("stuff.csv", "w") as f:
w = csv.writer(f, delimiter="|")
w.writerow(header)
w.writerows(stuff)
输出:
a|b|c|d
1|2|3|4
5|6|7|8
9|10|11|12