Writing Python lists to columns in csv

后端 未结 7 712

I have 5 lists, all of the same length, and I\'d like to write them to 5 columns in a CSV. So far, I can only write one to a column with this code:

with open         


        
7条回答
  •  一向
    一向 (楼主)
    2020-11-29 19:30

    change them to rows

    rows = zip(list1,list2,list3,list4,list5)
    

    then just

    import csv
    
    with open(newfilePath, "w") as f:
        writer = csv.writer(f)
        for row in rows:
            writer.writerow(row)
    

提交回复
热议问题