How do I make a 3 or more column csv file using the example?
import csv
fruits = ["apple", "banana", "grape", "orange"]
vegetables = ["onion", "garlic", "carrot", "cabbage"]
spices = ["salt", "pepper", "paprika", "cumin"]
types = ["Fruits", "Vegetables", "Spices"]
with open("test.csv", "w") as testfile:
writer = csv.DictWriter(testfile, fieldnames=types)
writer.writeheader()
I'm pretty confused on the DictWriter method and would like some help on how to properly make a csv file with 3 or more columns. So far the best I could do was:
Fruits,Vegetables,Spices
orange,,
,cabbage,
,,cumin
something like this, which is pretty bad.