Styler.
set_table_styles
Set the table styles on a Styler.
These are placed in a <style> tag before the generated HTML table.
<style>
This function can be used to style the entire table, columns, rows or specific HTML selectors.
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.
selector
props
(attribute, value)
Changed in version 1.2.0.
Apply to each column (axis=0 or 'index'), to each row (axis=1 or 'columns'). Only used if table_styles is dict.
axis=0
'index'
axis=1
'columns'
New in version 1.2.0.
Styles are replaced if True, or extended if False. CSS rules are preserved so most recent styles set will dominate if selectors intersect.
Examples
>>> df = pd.DataFrame(np.random.randn(10, 4), ... columns=['A', 'B', 'C', 'D']) >>> df.style.set_table_styles( ... [{'selector': 'tr:hover', ... 'props': [('background-color', 'yellow')]}] ... )
Adding column styling by name
>>> df.style.set_table_styles({ ... 'A': [{'selector': '', ... 'props': [('color', 'red')]}], ... 'B': [{'selector': 'td', ... 'props': [('color', 'blue')]}] ... }, overwrite=False)
Adding row styling
>>> df.style.set_table_styles({ ... 0: [{'selector': 'td:hover', ... 'props': [('font-size', '25px')]}] ... }, axis=1, overwrite=False)