Add grand summary rows by using the table data and any suitable aggregation functions. With grand summary rows, all of the available data in the gt table is incorporated (regardless of whether some of the data are part of row groups). Multiple grand summary rows can be added via expressions given to fns. You can selectively format the values in the resulting grand summary cells by use of formatting expressions from the vals.fmt_* class of functions.
A dictionary mapping row labels to aggregation expressions. Can be either Polars expressions or callable functions that take the entire DataFrame and return aggregated results. Each key becomes the label for a grand summary row.
fmt:FormatFn | None=None
A formatting function from the vals.fmt_* family (e.g., vals.fmt_number, vals.fmt_currency) to apply to the summary row values. If None, no formatting is applied.
columns:SelectExpr=None
Currently, this function does not support selection by columns. If you would like to choose which columns to summarize, you can select columns within the functions given to fns=. See examples below for more explicit cases.
side:Literal['bottom', 'top']='bottom'
Should the grand summary rows be placed at the "bottom" (the default) or the "top" of the table?
missing_text:str='—'
The text to be used in summary cells with no data outputs.
The GT object is returned. This is the same object that the method is called on so that we can facilitate method chaining.
Examples
Let’s use a subset of the sp500 dataset to create a table with grand summary rows. We’ll calculate min, max, and mean values for the numeric columns. Notice the different approaches to selecting columns to apply the aggregations to: we can use polars selectors or select the columns directly.
We can also use custom callable functions to create more complex summary calculations. Notice here that grand summary rows can be placed at the top of the table and formatted with currency notation, by passing a formatter from the vals.fmt_* class of functions.