Styler.set_table_styles(table_styles, axis=0, overwrite=True)[source]

Set the table styles on a Styler.

These are placed in a <style> tag before the generated HTML table.

This function can be used to style the entire table, columns, rows or specific HTML selectors.

table_styleslist or dict

If supplying a list, each individual table_style should be a dictionary with selector and props keys. selector should be a CSS selector that the style will be applied to (automatically prefixed by the table’s UUID) and props should be a list of tuples with (attribute, value). If supplying a dict, the dict keys should correspond to column names or index values, depending upon the specified axis argument. These will be mapped to row or col CSS selectors. MultiIndex values as dict keys should be in their respective tuple form. The dict values should be a list as specified in the form with CSS selectors and props that will be applied to the specified row or column.

Changed in version 1.2.0.

axis{0 or ‘index’, 1 or ‘columns’, None}, default 0

Apply to each column (axis=0 or 'index'), to each row (axis=1 or 'columns'). Only used if table_styles is dict.

New in version 1.2.0.

overwriteboolean, default True

Styles are replaced if True, or extended if False. CSS rules are preserved so most recent styles set will dominate if selectors intersect.

New in version 1.2.0.



>>> df = pd.DataFrame(np.random.randn(10, 4),
...                   columns=['A', 'B', 'C', 'D'])
...     [{'selector': 'tr:hover',
...       'props': [('background-color', 'yellow')]}]
... )

Or with CSS strings

...     [{'selector': 'tr:hover',
...       'props': 'background-color: yellow; font-size: 1em;']}]
... )

Adding column styling by name

...     'A': [{'selector': '',
...            'props': [('color', 'red')]}],
...     'B': [{'selector': 'td',
...            'props': 'color: blue;']}]
... }, overwrite=False)

Adding row styling

...     0: [{'selector': 'td:hover',
...          'props': [('font-size', '25px')]}]
... }, axis=1, overwrite=False)