pandas.io.formats.style.Styler¶
- class pandas.io.formats.style.Styler(data, precision=None, table_styles=None, uuid=None, caption=None, table_attributes=None, cell_ids=True, na_rep=None, uuid_len=5, decimal='.', thousands=None, escape=None)[source]¶
Helps style a DataFrame or Series according to the data with HTML and CSS.
- Parameters
- dataSeries or DataFrame
Data to be styled - either a Series or DataFrame.
- precisionint
Precision to round floats to, defaults to pd.options.display.precision.
- table_styleslist-like, default None
List of {selector: (attr, value)} dicts; see Notes.
- uuidstr, default None
A unique identifier to avoid CSS collisions; generated automatically.
- captionstr, tuple, default None
String caption to attach to the table. Tuple only used for LaTeX dual captions.
- table_attributesstr, default None
Items that show up in the opening
<table>
tag in addition to automatic (by default) id.- cell_idsbool, default True
If True, each cell will have an
id
attribute in their HTML tag. Theid
takes the formT_<uuid>_row<num_row>_col<num_col>
where<uuid>
is the unique identifier,<num_row>
is the row number and<num_col>
is the column number.- na_repstr, optional
Representation for missing values. If
na_rep
is None, no special formatting is applied.New in version 1.0.0.
- uuid_lenint, default 5
If
uuid
is not specified, the length of theuuid
to randomly generate expressed in hex characters, in range [0, 32].New in version 1.2.0.
- decimalstr, default “.”
Character used as decimal separator for floats, complex and integers
New in version 1.3.0.
- thousandsstr, optional, default None
Character used as thousands separator for floats, complex and integers
New in version 1.3.0.
- escapestr, optional
Use ‘html’ to replace the characters
&
,<
,>
,'
, and"
in cell display string with HTML-safe sequences. Use ‘latex’ to replace the characters&
,%
,$
,#
,_
,{
,}
,~
,^
, and\
in the cell display string with LaTeX-safe sequences.New in version 1.3.0.
See also
DataFrame.style
Return a Styler object containing methods for building a styled HTML representation for the DataFrame.
Notes
Most styling will be done by passing style functions into
Styler.apply
orStyler.applymap
. Style functions should return values with strings containing CSS'attr: value'
that will be applied to the indicated cells.If using in the Jupyter notebook, Styler has defined a
_repr_html_
to automatically render itself. Otherwise call Styler.render to get the generated HTML.CSS classes are attached to the generated HTML
Index and Column names include
index_name
andlevel<k>
where k is its level in a MultiIndexIndex label cells include
row_heading
row<n>
where n is the numeric position of the rowlevel<k>
where k is the level in a MultiIndex
Column label cells include *
col_heading
*col<n>
where n is the numeric position of the column *level<k>
where k is the level in a MultiIndexBlank cells include
blank
Data cells include
data
Attributes
env
(Jinja2 jinja2.Environment)
template
(Jinja2 Template)
loader
(Jinja2 Loader)
Methods
apply
(func[, axis, subset])Apply a CSS-styling function column-wise, row-wise, or table-wise.
applymap
(func[, subset])Apply a CSS-styling function elementwise.
background_gradient
([cmap, low, high, axis, ...])Color the background in a gradient style.
bar
([subset, axis, color, width, align, ...])Draw bar chart in the cell backgrounds.
clear
()Reset the
Styler
, removing any previously applied styles.export
()Export the styles applied to the current
Styler
.format
([formatter, subset, na_rep, ...])Format the text display value of cells.
from_custom_template
(searchpath[, ...])Factory function for creating a subclass of
Styler
.hide_columns
([subset])Hide the column headers or specific keys in the columns from rendering.
hide_index
([subset])Hide the entire index, or specific keys in the index from rendering.
highlight_between
([subset, color, axis, ...])Highlight a defined range with a style.
highlight_max
([subset, color, axis, props])Highlight the maximum with a style.
highlight_min
([subset, color, axis, props])Highlight the minimum with a style.
highlight_null
([null_color, subset, props])Highlight missing values with a style.
highlight_quantile
([subset, color, axis, ...])Highlight values defined by a quantile with a style.
pipe
(func, *args, **kwargs)Apply
func(self, *args, **kwargs)
, and return the result.render
([sparse_index, sparse_columns])Render the
Styler
including all applied styles to HTML.set_caption
(caption)Set the text added to a
<caption>
HTML element.set_na_rep
(na_rep)(DEPRECATED) Set the missing data representation on a
Styler
.set_precision
(precision)(DEPRECATED) Set the precision used to display values.
set_properties
([subset])Set defined CSS-properties to each
<td>
HTML element within the given subset.set_sticky
([axis, pixel_size, levels])Add CSS to permanently display the index or column headers in a scrolling frame.
set_table_attributes
(attributes)Set the table attributes added to the
<table>
HTML element.set_table_styles
(table_styles[, axis, overwrite])Set the table styles included within the
<style>
HTML element.set_td_classes
(classes)Set the DataFrame of strings added to the
class
attribute of<td>
HTML elements.set_tooltips
(ttips[, props, css_class])Set the DataFrame of strings on
Styler
generating:hover
tooltips.set_uuid
(uuid)Set the uuid applied to
id
attributes of HTML elements.text_gradient
([cmap, low, high, axis, ...])Color the text in a gradient style.
to_excel
(excel_writer[, sheet_name, na_rep, ...])Write Styler to an Excel sheet.
to_html
([buf, table_uuid, table_attributes, ...])Write Styler to a file, buffer or string in HTML-CSS format.
to_latex
([buf, column_format, position, ...])Write Styler to a file, buffer or string in LaTeX format.
use
(styles)Set the styles on the current
Styler
.where
(cond, value[, other, subset])(DEPRECATED) Apply CSS-styles based on a conditional function elementwise.