【发布时间】:2022-12-27 12:10:46
【问题描述】:
How do I write 2 python lists into a csv file? I have tried but it is not the same as my expected output. I would appreciate any guidance you can provide. Thank you :)
fieldHeader = ["id", "name", "car", "colour"]
vaules = ['"1", "John", "honda", "blue"','"2", "Tom", "bmw", "red"']
with open("output.csv", "w") as f:
w = csv.writer(f, delimiter=",")
w.writerow(fieldHeader)
w.writerow(vaules)
I have tried to write out a code to write a csv file with the ',' delimeter and try to write each row into the csv file. Howwever, the output is not what I am expecting.
【问题讨论】:
-
You need to call writerow on each row