I already read Export a Python List to Excel and How to export user inputs (from python) to excel worksheet, but the different is that my list is in more than one size. I mean my list is something like this:
List=[[list1],[list2],...,[list10]]
list1, list2,...,list10 are including of 3 numbers with float46 formats. For example:
list1=[1.34543324545676,2.4354356645454,2.786434355455]
list2=[3.33434342343423,6.6566665655655,7.343545454545]
...
list10=[3.6565656565465,7.45454536565656,7.56565656565]
I want to export the List to an Excel file that list1 is in the first column, list2 is in the second column, ..., list10 is in the tenth column.
If you are fine with using
csv
module to write to a csv, and then open it up in excel, then you can usecsv
module along withzip()
, to write out your list of lists as columns. Example -The
*list_of_list
unpacks the lists and sends each inner list as a separate argument tozip()
and zip() combines each list at each index so first list output ofzip()
is the 0th index of all lists, etc. So this basically transposes the list of lists.Example/Demo -
Output in
a.csv
is -I think something similar (using
zip()
) can be done for other excel libraries as well, if you want.Here is one way to do it using the XlsxWriter module that will automatically handle different list lengths:
Output: