Skip to content Skip to sidebar Skip to footer

Exporting A List To A Csv/space Separated And Each Sublist In Its Own Column

I'm sure there is an easy way to do this, so here goes. I'm trying to export my lists into CSV in columns. (Basically, it's how another program will be able to use the data I've

Solution 1:

What you're describing is that you want to translate a 2 dimensional array of data. In Python you can achieve this easily with the zip function as long as the inner lists are all the same length.

out.writerows(zip(*data))

If they are not all the same length, you can use itertools.izip_longest to fill the remaining fields with some default value (even '').

Post a Comment for "Exporting A List To A Csv/space Separated And Each Sublist In Its Own Column"