You need to have odfpy and pandas installed. This can be done as follows.

python -m pip install odfpy pandas

Here’s a quick example.

import pandas as pd

excel_writer = pd.ExcelWriter("output.ods")

col1 = [1, 2, 3]
col2 = [4, 5, 6]

df = pd.DataFrame({
    "Col1": col1,
    "Col2": col2,
})

df.to_excel(excel_writer, index=False, sheet_name="Sheet one")

excel_writer.close()

You can call to_excel with different sheet names to get multiple worksheets in the Excel file. Or call to_excel multiple times with the same sheet name to get multiple tables written in the same page.

Tags: Excel Pandas