-
-
Notifications
You must be signed in to change notification settings - Fork 640
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
checkbox: add polars checkbox example
Feature request #1092
- Loading branch information
Showing
3 changed files
with
39 additions
and
1 deletion.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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, | ||
) |