How to write Python Array into Excel Spread sheet
Here is one way to do it using the XlsxWriter module:
import xlsxwriter
workbook = xlsxwriter.Workbook('arrays.xlsx')
worksheet = workbook.add_worksheet()
array = [['a1', 'a2', 'a3'],
['a4', 'a5', 'a6'],
['a7', 'a8', 'a9'],
['a10', 'a11', 'a12', 'a13', 'a14']]
row = 0
for col, data in enumerate(array):
worksheet.write_column(row, col, data)
workbook.close()
Output:
Use pandas data frame!
import pandas as pd
array = [['a1', 'a2', 'a3'],
['a4', 'a5', 'a6'],
['a7', 'a8', 'a9'],
['a10', 'a11', 'a12', 'a13', 'a14']]
df = pd.DataFrame(array).T
df.to_excel(excel_writer = "C:/Users/Jing Li/Desktop/test.xlsx")
excel_writer is File path in str or existing ExcelWriter object.