Writing Python lists to columns in csv

后端 未结 7 732

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:53

    I just wanted to add to this one- because quite frankly, I banged my head against it for a while - and while very new to python - perhaps it will help someone else out.

     writer.writerow(("ColName1", "ColName2", "ColName"))
                     for i in range(len(first_col_list)):
                         writer.writerow((first_col_list[i], second_col_list[i], third_col_list[i]))
    

提交回复
热议问题