grouped_multirow_latex#
Render a grouped LaTeX table with two-level row headers (e.g., Domain and Task) and flat method columns (e.g., MLP, Modality, Component).
Input must be a flat DataFrame with (row1, row2, column, value) format.
Each value should be a float or a list of floats, from which mean Β± std or stderr is computed.
Bolds the best (min or max) per row.
π§Ύ Required LaTeX packages / commands#
\usepackage{booktabs}\usepackage{multirow}\newcommand{\highlightcolor}[1]{\colorbox[HTML]{bae6fb}{\textbf{#1}}}
π₯ Arguments#
Name |
Type |
Required |
Description |
|---|---|---|---|
df |
pd.DataFrame |
β |
DataFrame with columns for row1, row2, column, and values (as lists or floats). |
row1 |
str |
β |
Column name for the outer row grouping (e.g., Domain). |
row2 |
str |
β |
Column name for the row label (e.g., Task). |
col |
str |
β |
Column name representing the method axis (e.g., Method). |
value_column |
str |
β |
Column name containing scalar or list-of-floats to summarize. |
highlight |
str |
β |
βminβ or βmaxβ to bold best value per row. |
stderr |
bool |
β |
Use standard error instead of std when formatting. |
caption |
str |
β |
LaTeX caption to display below the table. |
label |
str |
β |
Optional LaTeX label for referencing. |
π¦ Example Output#
Click to show example code
import numpy as np
import pandas as pd
from swizz import table
np.random.seed(0)
domains = ["HalfCheetah", "Hopper", "Walker2d", "Ant"]
tasks = ["IL (β) [1]", "Off-RL (β) [1]", "Sensor failure (β) [11]", "Dynamics change (β) [4]"]
methods = ["MLP", "Modality", "Component"]
rows = []
for domain in domains:
for task in tasks:
for method in methods:
values = np.round(np.random.normal(loc=1.0, scale=0.05, size=5), 3).tolist()
rows.append({
"Domain": domain,
"Task": task,
"Method": method,
"score": values
})
df = pd.DataFrame(rows)
latex = table(
"grouped_multirow_latex",
df=df,
row1="Domain",
row2="Task",
col="Method",
value_column="score",
highlight="max",
stderr=False,
caption="Expert-normalized returns across domains and methods.",
label="tab:tokenization_comparison"
)
print(latex)