Example: Polars Excel getting started example#

A simple getting started example of converting a Polars dataframe to an Excel file using Polars and XlsxWriter. See Working with Polars and XlsxWriter for more details.

_images/polars_simple.png
##############################################################################
#
# A simple example of converting a Polars dataframe to an xlsx file using
# Polars and XlsxWriter.
#
# SPDX-License-Identifier: BSD-2-Clause
# Copyright 2013-2024, John McNamara, jmcnamara@cpan.org
#

import polars as pl

# Create a Pandas dataframe from some data.
df = pl.DataFrame({"Data": [10, 20, 30, 20, 15, 30, 45]})

# Write the dataframe to a new Excel file.
df.write_excel(workbook="polars_simple.xlsx")