mlresearch.latex.export_table¶
- mlresearch.latex.export_table(table, path=None, caption=None, label=None, index=True, longtable=True)[source]¶
Exports a pandas dataframe to LaTeX (tabular or longtable) format.
This function replaces
df.to_latexwhen there are latex commands in the table. For longtable format, it requires\usepackage{booktabs}and\usepackage{longtable}in the LaTeX preamble.Warning
Do not pass a table with column names, index names or values containing an underscore (“_”), as it will result in an error in LaTeX. If you wish to have underscores in the LaTeX table, add a backslash before the underscore.
- Parameters:
- tablepd.DataFrame
Dataframe with results statistics. Must not contain non-indexed metadata. Supports both single and multi index.
- pathstr, default=None
File path to write to. If None, the output is returned as a string.
- captionstr or tuple, default=None
Tuple (full_caption, short_caption), which results in
\caption[short_caption]{full_caption}; if a single string is passed, no short caption will be set.- labelstr, default=None
The LaTeX label to be placed inside
\label{}in the output. This is used with\ref{}in the main.texfile.- indexbool, default=True
Write row names (index).
- Returns:
- tex_tablestr or None
If
pathis None, returns the result as a string. Otherwise returns None.