great_tables
  • Get Started
  • Examples
  • Reference
  • Blog

On this page

  • Boxhead, Stub, and Summary Rows

Technical notes

This document holds technical notes on how the dataclass behind GT interact.

import polars as pl
from great_tables import GT, exibble

Boxhead, Stub, and Summary Rows

lil_ex = pl.from_pandas(exibble).select("num", "row", "group").head(6)

gt = GT(lil_ex).grand_summary_rows(fns={"Total": pl.col("num").sum()})

Placeholder stub

(gt


)
num row group
  0.1111 row_1 grp_a
  2.222 row_2 grp_a
  33.33 row_3 grp_a
  444.4 row_4 grp_a
  5550.0 row_5 grp_b
  None row_6 grp_b
Total 6030.0631 --- ---

Rowname stub

(gt
    .tab_stub(rowname_col="row")

)
num group
row_1 0.1111 grp_a
row_2 2.222 grp_a
row_3 33.33 grp_a
row_4 444.4 grp_a
row_5 5550.0 grp_b
row_6 None grp_b
Total 6030.0631 ---

Group stub

(gt
    .tab_stub(groupname_col="group")
    .tab_options(row_group_as_column=True)
)
num row
grp_a 0.1111 row_1
2.222 row_2
33.33 row_3
444.4 row_4
grp_b 5550.0 row_5
None row_6
Total 6030.0631 ---

One more not shown above is if both rowname and groupnames are used in the stub, then the summary spans both those columns:

(gt.tab_stub(rowname_col="row", groupname_col="group").tab_options(row_group_as_column=True))
num
grp_a row_1 0.1111
row_2 2.222
row_3 33.33
row_4 444.4
grp_b row_5 5550.0
row_6 None
Total 6030.0631