Helps style a DataFrame or Series according to the data with HTML and CSS.
Data to be styled - either a Series or DataFrame.
Precision to round floats to. If not given defaults to pandas.options.styler.format.precision.
Changed in version 1.4.0.
List of {selector: (attr, value)} dicts; see Notes.
A unique identifier to avoid CSS collisions; generated automatically.
String caption to attach to the table. Tuple only used for LaTeX dual captions.
Items that show up in the opening <table> tag in addition to automatic (by default) id.
If True, each cell will have an id attribute in their HTML tag. The id takes the form T_<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.
Representation for missing values. If na_rep is None, no special formatting is applied, and falls back to pandas.options.styler.format.na_rep.
If uuid is not specified, the length of the uuid to randomly generate expressed in hex characters, in range [0, 32].
Character used as decimal separator for floats, complex and integers. If not given uses pandas.options.styler.format.decimal.
Added in version 1.3.0.
Character used as thousands separator for floats, complex and integers. If not given uses pandas.options.styler.format.thousands.
Added in version 1.3.0.
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. Use ‘latex-math’ to replace the characters the same way as in ‘latex’ mode, except for math substrings, which either are surrounded by two characters $ or start with the character \( and end with \). If not given uses pandas.options.styler.format.escape.
Added in version 1.3.0.
Object to define how values are displayed. See Styler.format. If not given uses pandas.options.styler.format.formatter.
Added in version 1.4.0.
Attributes
env | (Jinja2 jinja2.Environment) |
template_html | (Jinja2 Template) |
template_html_table | (Jinja2 Template) |
template_html_style | (Jinja2 Template) |
template_latex | (Jinja2 Template) |
loader | (Jinja2 Loader) |
See also
DataFrame.styleReturn 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 or Styler.map. 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.to_html to get the generated HTML.
CSS classes are attached to the generated HTML
Index and Column names include index_name and level<k> where k is its level in a MultiIndex
Index label cells include
row_heading
row<n> where n is the numeric position of the row
level<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 MultiIndex
Blank cells include blank
Data cells include data
Trimmed cells include col_trim or row_trim.
Any, or all, or these classes can be renamed by using the css_class_names argument in Styler.set_table_classes, giving a value such as {“row”: “MY_ROW_CLASS”, “col_trim”: “”, “row_trim”: “”}.
Examples
>>> df = pd.DataFrame([[1.0, 2.0, 3.0], [4, 5, 6]], index=['a', 'b'],
... columns=['A', 'B', 'C'])
>>> pd.io.formats.style.Styler(df, precision=2,
... caption="My table")
Please see: Table Visualization for more examples.
Attributes
Methods
| Apply a CSS-styling function column-wise, row-wise, or table-wise. |
| Apply a CSS-styling function to the index or column headers, level-wise. |
| (DEPRECATED) Apply a CSS-styling function elementwise. |
| (DEPRECATED) Apply a CSS-styling function to the index or column headers, elementwise. |
| Color the background in a gradient style. |
| Draw bar chart in the cell backgrounds. |
| Reset the |
| Append another Styler to combine the output into a single table. |
| Export the styles applied to the current Styler. |
| Format the text display value of cells. |
| Format the text display value of index labels or column headers. |
| Factory function for creating a subclass of |
| Hide the entire index / column headers, or specific rows / columns from display. |
| Highlight a defined range with a style. |
| Highlight the maximum with a style. |
| Highlight the minimum with a style. |
| Highlight missing values with a style. |
| Highlight values defined by a quantile with a style. |
| Apply a CSS-styling function elementwise. |
| Apply a CSS-styling function to the index or column headers, elementwise. |
| Apply |
| Relabel the index, or column header, keys to display a set of specified values. |
| Set the text added to a |
| Set defined CSS-properties to each |
| Add CSS to permanently display the index or column headers in a scrolling frame. |
| Set the table attributes added to the |
| Set the table styles included within the |
| Set the |
| Set the DataFrame of strings on |
| Set the uuid applied to |
| Color the text in a gradient style. |
| Write Styler to an Excel sheet. |
| Write Styler to a file, buffer or string in HTML-CSS format. |
| Write Styler to a file, buffer or string in LaTeX format. |
| Write Styler to a file, buffer or string in text format. |
| Set the styles on the current Styler. |
© 2008–2011, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team
© 2011–2025, Open source contributors
Licensed under the 3-clause BSD License.
https://pandas.pydata.org/pandas-docs/version/2.3.0/reference/api/pandas.io.formats.style.Styler.html