How to write a list of list into excel using python?

How to write a list of list into excel using python?

You can use the pandas library.

import pandas as pd

new_list = [[first, second], [third, four], [five, six]]
df = pd.DataFrame(new_list)
writer = pd.ExcelWriter(test.xlsx, engine=xlsxwriter)
df.to_excel(writer, sheet_name=welcome, index=False)
writer.save()

Related documentation:

Here is one way to do it using XlsxWriter:

import xlsxwriter

new_list = [[first, second], [third, four], [1, 2, 3, 4, 5, 6]]

with xlsxwriter.Workbook(test.xlsx) as workbook:
    worksheet = workbook.add_worksheet()

    for row_num, data in enumerate(new_list):
        worksheet.write_row(row_num, 0, data)

Output:

enter

How to write a list of list into excel using python?

I think you should use pandas library to write and read data in this library the function pandas.DataFrame.to_excel(..) will make you able to directly write to excel files for all this you may need to define pandas.DataFrame for this work here is a tutorial on pandas-dataframe by dataCamp.

Leave a Reply

Your email address will not be published. Required fields are marked *