I have multiple lists need write into a csv file with custom headers.
An example I have 3 lists as below.
a = ["Item A", "Item B", "Item C", "Item D"]
b = ["Price A", "Price B", "Price C", "Price D"]
c = ["Stock A", "Stock B", "Stock C", "Stock D"]
I tried below
import csv
a = ["Item A", "Item B", "Item C", "Item D"]
b = ["Price A", "Price B", "Price C", "Price D"]
c = ["Stock A", "Stock B", "Stock C", "Stock D"]
c = zip(a, b, c)
with open("test.csv", "w") as f:
writer = csv.writer(f)
writer.writerows(c)
# writer.writerows(c)
But I want them to show as below
csv.writer()with eitherwriterowsorwriterow, the results not what I expected.