我有两个列表,一个包含Date
,另一个包含Rf
Date = ['July 12', 'July 13', 'July 14', 'July 15', 'July 16']
rf = ['12', '16', '18', '10', '4']
out = open('out.csv','ab')
writer = csv.writer(out)
writer.writerow(Date)
writer.writerow(rf)
但是csv中的输出并不像
Jul 12 Jul 13 Jul 14 Jul 15 Jul 16
12 16 18 10 4
答案 0 :(得分:3)
在Python 2.x中,可以将io.open
与参数mode='w'
和newline=''
一起使用。您还应该使用with
语句:
Date = ['July 12', 'July 13', 'July 14', 'July 15', 'July 16']
rf = ['12', '16', '18', '10', '4']
import csv, io
with io.open('out.csv', 'wb', newline='') as out:
writer = csv.writer(out)
writer.writerow(Date)
writer.writerow(rf)