Bootstrap

python将一维数组保存到.csv文件为一列

1、带空行

import csv
filePath = 'csv文件所处的位置,包含.csv'
list1 = [1,2,3,4]
list2 = [4,2,3,4]
list3 = [5,6,7,4]
list4 = [8,2,9,6]
rows = zip(list1,list2,list3,list4)
with open(filePath, "w") as f:
    writer = csv.writer(f)
    for row in rows:
        writer.writerow(row)

2、不带空行

import csv
filePath = 'csv文件所处的位置,包含.csv'
list1 = [1,2,3,4]
list2 = [4,2,3,4]
list3 = [5,6,7,4]
list4 = [8,2,9,6]
rows = zip(list1,list2,list3,list4)
with open(filePath, "w", newline='') as f:
    writer = csv.writer(f)
    for row in rows:
        writer.writerow(row)

;