great_tables
  • Get Started
  • Examples
  • Reference
  • Blog

On this page

  • Parameters
  • Returns
  • Examples

loc.grand_summary_stub

loc.grand_summary_stub(rows=None)

Target the grand summary stub.

With loc.grand_summary_stub() we can target the cells containing the grand 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

rows : RowSelectExpr = None

The rows to target within the grand 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 grand summary rows are targeted. Note that if rows are targeted by index, top and bottom grand summary rows are indexed as one combined list starting with the top rows.

Returns

: LocGrandSummaryStub

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

Examples

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

from great_tables import GT, style, loc, vals
from great_tables.data import gtcars

(
    GT(
        gtcars[["mfr", "model", "hp", "trq", "mpg_c"]].head(6),
        rowname_col="model",
    )
    .fmt_integer(columns=["hp", "trq", "mpg_c"])
    .grand_summary_rows(
        fns={
            "Min": lambda df: df.min(numeric_only=True),
            "Max": lambda x: x.max(numeric_only=True),
        },
        side="top",
        fmt=vals.fmt_integer,
    )
    .tab_style(
        style=[style.text(color="crimson", weight="bold"), style.fill(color="lightgray")],
        locations=loc.grand_summary_stub(),
    )
)
mfr hp trq mpg_c
Min --- 553 398 11
Max --- 661 561 16
GT Ford 647 550 11
458 Speciale Ferrari 597 398 13
458 Spider Ferrari 562 398 13
458 Italia Ferrari 562 398 13
488 GTB Ferrari 661 561 15
California Ferrari 553 557 16