simple_df_to_latex#
Render a simple LaTeX table from a flat DataFrame.
First column (e.g., βModelβ) is treated as the row label
Other columns contain either scalars or list-like values (e.g. [0.82, 0.84, 0.85])
Automatically formats values as mean Β± std or stderr
Optionally highlights best values per column (min or max)
π§Ύ Required LaTeX packages / commands#
\usepackage{booktabs}
π₯ Arguments#
Name |
Type |
Required |
Description |
|---|---|---|---|
df |
pd.DataFrame |
β |
DataFrame where the first column is a string label (e.g., βModelβ) and other columns are scalars or list-like numeric values. |
highlight |
Dict[str, str] |
β |
Map of column β βminβ or βmaxβ to bold the best values. |
stderr |
bool |
β |
Use standard error (instead of std) for Β± formatting. |
caption |
str |
β |
Optional caption to display below the table. |
label |
str |
β |
Optional LaTeX label for referencing. |
π¦ Example Output#
Click to show example code
import pandas as pd
from swizz import table
df = pd.DataFrame({
"Model": ["A", "B"],
"acc": [[0.85, 0.88, 0.87], [0.90, 0.91, 0.89]],
"f1": [0.83, [0.92, 0.93]]
})
latex = table(
"df_to_latex",
df,
highlight={"acc": "max", "f1": "max"},
stderr=False,
caption="Results on CIFAR-10",
label="tab:cifar10_results"
)
print(latex)