py_research.tables module#
Utilities for creating pretty result tables.
- class TableStyle(dfs=None, cols=None, rows=None, name=None, format=None, css=None, header_css=None, hide=None, include=None, require=None)[source]#
Bases:
object
Define a pretty table column format.
- Parameters:
- dfs: str | list[str] | None = None#
Dataframe names to apply this style to. If None, apply to all dataframes.
- cols: str | list[str] | None = None#
Column name(s) to apply this style to. If None, apply to all columns. Index levels can be styled via their names as if they were columns.
- format: str | Callable[[Any], str] | None = None#
Format string or callback function to use for formatting data values
- css: dict[str, str] | Callable[[Any], str] | None = None#
Custom CSS styles to apply to matched cells. Supplied as a mapping from CSS property to value.
- header_css: dict[str, str] | None = None#
Custom CSS styles applied to the headers of matched cells. Supplied as a mapping from CSS property to value.
- class TableColors(row_even='#f2f2f2', row_odd='#fff', header_even='#677a96', header_odd='#677a96')[source]#
Bases:
object
Define colors for a pretty table.
- class ResultTable(df, styles=<factory>, labels=<factory>, widths=<factory>, title=None, max_row_cutoff=100, font_size=1.0, default_style=<factory>, column_flatten_format=None, show_index=False, table_colors=<factory>, table_css=<factory>, index_label=None)[source]#
Bases:
object
Define and render a pretty result table with custom formatting and highlights.
- Parameters:
df (dataclasses.InitVar[DataFrame]) –
styles (list[TableStyle]) –
title (str | None) –
max_row_cutoff (int) –
font_size (float) –
default_style (TableStyle) –
column_flatten_format (str | None) –
show_index (bool) –
table_colors (TableColors) –
index_label (str | None) –
- df: dataclasses.InitVar[DataFrame]#
Dataframe to render as pretty table.
- styles: list[TableStyle]#
Styles to apply to the table.
- labels: dict[str, str] | Callable[[str], str]#
Labels to use for the table headers.
If dict, the keys are column names and the values are the labels. If callable, the function is called with the column name and should return the label
- widths: dict[str, float | str]#
Widths to use for the table columns.
If a float, the width is relative to the sum of all widths. If a string, the width is set to the CSS string value.
- default_style: TableStyle#
Default style to apply to the table.
- column_flatten_format: str | None = None#
Format string to use for flatteting multi-index column labels. Leave as None to keep a multi-level column header. Format string must take two positional arguments, e.g. “{0}_{1}”.
- table_colors: TableColors#
Colors to use for this table.
- table_css: dict[str, dict[str, str]]#
Additional styles to apply to the table. Dictionary keys must be CSS selectors and values must be dictionaries of CSS properties.