Highlighting
Highlighting methods colour specific cells based on conditions.
All highlighting methods accept fill (background colour) and color (text colour).
If color is omitted, contrast is computed automatically (black or white).
highlight_max(in_col, scope="column", color=None, fill="yellow", exclude=None)
Highlight the maximum value in each selected column.
in_colstr | list | Expr— Column(s) to apply toscope"column" | "table", default"column"— Compute max per column or across all selected columnscolorstr | None, defaultNone— Text colour (auto-contrast if None)fillstr, default"yellow"— Background fill colourexcludestr | list | None, defaultNone— Columns to exclude whenin_colis an expression
Example:
df.style().highlight_max("Revenue").show()
| Company | Revenue | Profit | Growth | Employees_k |
|---|---|---|---|---|
| Apple | 383.3 | 97.0 | 7.8 | 161 |
| Microsoft | 211.9 | 72.4 | 6.9 | 221 |
| 307.4 | 73.8 | 8.7 | 182 | |
| Amazon | 574.8 | 30.4 | 11.8 | 1541 |
| Meta | 134.9 | 39.1 | 16.4 | 67 |
highlight_min(in_col, scope="column", color=None, fill="lightblue", exclude=None)
Highlight the minimum value in each selected column.
in_colstr | list | Expr— Column(s) to apply toscope"column" | "table", default"column"— Compute min per column or across all selected columnscolorstr | None, defaultNone— Text colour (auto-contrast if None)fillstr, default"lightblue"— Background fill colourexcludestr | list | None, defaultNone— Columns to exclude
Example:
df.style().highlight_min("Profit").show()
| Company | Revenue | Profit | Growth | Employees_k |
|---|---|---|---|---|
| Apple | 383.3 | 97.0 | 7.8 | 161 |
| Microsoft | 211.9 | 72.4 | 6.9 | 221 |
| 307.4 | 73.8 | 8.7 | 182 | |
| Amazon | 574.8 | 30.4 | 11.8 | 1541 |
| Meta | 134.9 | 39.1 | 16.4 | 67 |
highlight_above(in_col, value, inclusive=False, scope="column", color=None, fill="yellow")
Highlight values strictly above (or equal to, if inclusive=True) a threshold.
in_colstr | list | Expr— Column(s) to apply tovaluefloat— Threshold valueinclusivebool, defaultFalse— Include the threshold value itselfscope"column" | "table", default"column"— Unused for this method (kept for API consistency)colorstr | None, defaultNone— Text colourfillstr, default"yellow"— Background fill colour
Example:
df.style().highlight_above("Growth", value=10.0).show()
| Company | Revenue | Profit | Growth | Employees_k |
|---|---|---|---|---|
| Apple | 383.3 | 97.0 | 7.8 | 161 |
| Microsoft | 211.9 | 72.4 | 6.9 | 221 |
| 307.4 | 73.8 | 8.7 | 182 | |
| Amazon | 574.8 | 30.4 | 11.8 | 1541 |
| Meta | 134.9 | 39.1 | 16.4 | 67 |
highlight_below(in_col, value, inclusive=False, scope="column", color=None, fill="yellow")
Highlight values strictly below (or equal to, if inclusive=True) a threshold.
in_colstr | list | Expr— Column(s) to apply tovaluefloat— Threshold valueinclusivebool, defaultFalse— Include the threshold value itselfscope"column" | "table", default"column"— Unused for this method (kept for API consistency)colorstr | None, defaultNone— Text colourfillstr, default"yellow"— Background fill colour
Example:
df.style().highlight_below("Profit", value=73).show()
| Company | Revenue | Profit | Growth | Employees_k |
|---|---|---|---|---|
| Apple | 383.3 | 97.0 | 7.8 | 161 |
| Microsoft | 211.9 | 72.4 | 6.9 | 221 |
| 307.4 | 73.8 | 8.7 | 182 | |
| Amazon | 574.8 | 30.4 | 11.8 | 1541 |
| Meta | 134.9 | 39.1 | 16.4 | 67 |
highlight_equal(in_col, value, color=None, fill="yellow")
Highlight cells whose value exactly equals the target.
in_colstr | list | Expr— Column(s) to apply tovaluefloat | str— Target valuecolorstr | None, defaultNone— Text colourfillstr, default"yellow"— Background fill colour
Example:
df.style().highlight_equal("Employees_k", value=182).show()
| Company | Revenue | Profit | Growth | Employees_k |
|---|---|---|---|---|
| Apple | 383.3 | 97.0 | 7.8 | 161 |
| Microsoft | 211.9 | 72.4 | 6.9 | 221 |
| 307.4 | 73.8 | 8.7 | 182 | |
| Amazon | 574.8 | 30.4 | 11.8 | 1541 |
| Meta | 134.9 | 39.1 | 16.4 | 67 |
highlight_between(in_col, low, high, scope="column", color=None, fill="yellow")
Highlight values within the range [low, high] (inclusive).
in_colstr | list | Expr— Column(s) to apply tolowfloat— Lower bound (inclusive)highfloat— Upper bound (inclusive)scope"column" | "table", default"column"— Unused for this methodcolorstr | None, defaultNone— Text colourfillstr, default"yellow"— Background fill colour
Example:
df.style().highlight_between("Revenue", low=200.0, high=400.0).show()
| Company | Revenue | Profit | Growth | Employees_k |
|---|---|---|---|---|
| Apple | 383.3 | 97.0 | 7.8 | 161 |
| Microsoft | 211.9 | 72.4 | 6.9 | 221 |
| 307.4 | 73.8 | 8.7 | 182 | |
| Amazon | 574.8 | 30.4 | 11.8 | 1541 |
| Meta | 134.9 | 39.1 | 16.4 | 67 |
highlight_identical(in_col, color=None, fill="yellow")
Highlight rows where all specified columns share the same value. Unlike other highlight methods, this operates row-wise across columns.
in_collist[str]— Columns to compare (must be a list)colorstr | None, defaultNone— Text colourfillstr, default"yellow"— Background fill colour
Example:
df.style().highlight_identical(["Col_A", "Col_B"]).show()
| actual | predicted |
|---|---|
| 1 | 1 |
| 2 | 3 |
| 3 | 3 |
| 2 | 4 |
| 5 | 5 |
highlight_when(in_col, when, then_fill="yellow", then_color=None, exclude=None)
Highlight cells in in_col when a Polars expression when evaluates to True.
The expression can reference any column, enabling cross-column conditions.
in_colstr | list | Expr— Column(s) to colourwhenpl.Expr— Boolean Polars expressionthen_fillstr, default"yellow"— Background colour when condition is Truethen_colorstr | None, defaultNone— Text colour when condition is Trueexcludestr | list | None, defaultNone— Columns to exclude
Example:
import polars as pl
# Highlight Revenue where Growth > 15%
df.style().highlight_when(
"Revenue",
when=pl.col("Growth") > 15,
then_fill="lightgreen"
).show()
| Company | Revenue | Profit | Growth | Employees_k |
|---|---|---|---|---|
| Apple | 383.3 | 97.0 | 7.8 | 161 |
| Microsoft | 211.9 | 72.4 | 6.9 | 221 |
| 307.4 | 73.8 | 8.7 | 182 | |
| Amazon | 574.8 | 30.4 | 11.8 | 1541 |
| Meta | 134.9 | 39.1 | 16.4 | 67 |