To convert a list of lists to csv in python, we can use the csv. writer() method along with the csv. writerow() method.
The most common method to write data from a list to CSV file is the writerow() method of writer and DictWriter class. Example 1: Creating a CSV file and writing data row-wise into it using writer class.
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])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With