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
Citation
If you find this work useful, please cite it as:
@article{yaltirakli,
title = "Pandas ODS ODF Excel Export",
author = "Yaltirakli, Gokberk",
journal = "gkbrk.com",
year = "2024",
url = "https://www.gkbrk.com/pandas-ods-odf-excel-export"
}
Not using BibTeX? Click here for more citation styles.
IEEE Citation Gokberk Yaltirakli, "Pandas ODS ODF Excel Export", November, 2024. [Online]. Available: https://www.gkbrk.com/pandas-ods-odf-excel-export. [Accessed Nov. 12, 2024].
APA Style Yaltirakli, G. (2024, November 12). Pandas ODS ODF Excel Export. https://www.gkbrk.com/pandas-ods-odf-excel-export
Bluebook Style Gokberk Yaltirakli, Pandas ODS ODF Excel Export, GKBRK.COM (Nov. 12, 2024), https://www.gkbrk.com/pandas-ods-odf-excel-export