-
-
Notifications
You must be signed in to change notification settings - Fork 640
/
Copy pathpolars_checkbox.py
31 lines (28 loc) · 910 Bytes
/
polars_checkbox.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
##############################################################################
#
# A example of displaying the boolean values in a Polars dataframe as checkboxes
# in an output xlsx file.
#
# SPDX-License-Identifier: BSD-2-Clause
#
# Copyright (c) 2013-2025, John McNamara, [email protected]
#
import polars as pl
# Create a Pandas dataframe with some sample data.
df = pl.DataFrame(
{
"Region": ["North", "South", "East", "West"],
"Target": [100, 70, 90, 120],
"On-track": [False, True, True, False],
}
)
# Write the dataframe to a new Excel file with formatting options.
df.write_excel(
workbook="polars_checkbox.xlsx",
# Set the checkbox format for the "On-track" boolean column.
column_formats={"On-track": {"checkbox": True}},
# Set an alternative table style.
table_style="Table Style Light 9",
# Autofit the column widths.
autofit=True,
)