Skip to main content

loc.summary_stub

Target the group summary stub.

Usage

Source

loc.summary_stub(
    groups=None,
    rows=None,
)

With loc.summary_stub() we can target the cells containing the group summary row labels, which reside in the table stub. This is useful for applying custom styling with the tab_style() method. That method has a locations= argument and this class should be used there to perform the targeting.

Parameters

groups: list[str] | str | None = None

The groups to target. Can be a list of group IDs or a single group ID string. If None, all groups with summary rows are targeted.

rows: RowLiteralSelectExpr = None
The rows to target within the summary stub. Can either be a single row name or a series of row names provided in a list. If no rows are specified, all summary rows are targeted.

Returns

LocSummaryStub
A LocSummaryStub object, which is used for a locations= argument if specifying the table’s group summary rows’ labels.

Examples

Let’s use a subset of the gtcars dataset in a new table. We will style the entire group summary stub (the row labels) by using locations=loc.summary_stub() within tab_style().

import polars as pl
from great_tables import GT, data, style, loc, vals

gtcars_mini = (
    data.pl.gtcars
    .select(["mfr", "model", "hp", "trq"])
    .head(12)
)

(
    GT(gtcars_mini, rowname_col="model", groupname_col="mfr")
    .summary_rows(
        fns={
            "Min": pl.col("hp", "trq").min(),
            "Max": pl.col("hp", "trq").max(),
        },
        fmt=vals.fmt_integer,
    )
    .tab_style(
        style=[style.text(color="crimson", weight="bold"), style.fill(color="lightgray")],
        locations=loc.summary_stub(),
    )
)
hp trq
Ford
GT 647.0 550.0
Min 647 550
Max 647 550
Ferrari
458 Speciale 597.0 398.0
458 Spider 562.0 398.0
458 Italia 562.0 398.0
488 GTB 661.0 561.0
California 553.0 557.0
GTC4Lusso 680.0 514.0
FF 652.0 504.0
F12Berlinetta 731.0 509.0
LaFerrari 949.0 664.0
Min 553 398
Max 949 664
Acura
NSX 573.0 476.0
Min 573 476
Max 573 476
Nissan
GT-R 545.0 436.0
Min 545 436
Max 545 436