writing data from a python list to csv row-wise

前端 未结 2 1810
孤街浪徒
孤街浪徒 2020-12-14 07:30

Using python, i am writing data from a list to a .csv file, row-wise.

Code:

writer=csv.writer(open(filepath,\'wb\'))
header=[\'type\',\'id\',\'numbe         


        
相关标签:
2条回答
  • 2020-12-14 07:46

    This work for me:

    for item in RESULTS:
         wr.writerow([item,])
    
    0 讨论(0)
  • 2020-12-14 07:57

    Change writer.writerow(data) to writer.writerow([data]).

    .writerow takes an iterable and uses each element of that iterable for each column. If you use a list with only one element it will be placed in a single column.

    You should also restructure your loop:

    for word in header:
        writer.writerow([word])
    
    0 讨论(0)
提交回复
热议问题