pandas / 1.4.0 / reference / api / pandas.io.formats.style.styler.to_html.html /

pandas.io.formats.style.Styler.to_html

Styler. to_html ( buf=None, *, table_uuid=None, table_attributes=None, sparse_index=None, sparse_columns=None, bold_headers=False, caption=None, max_rows=None, max_columns=None, encoding=None, doctype_html=False, exclude_styles=False, **kwargs ) [source]

Write Styler to a file, buffer or string in HTML-CSS format.

New in version 1.3.0.

Parameters
buf :str, path object, file-like object, or None, default None

String, path object (implementing os.PathLike[str]), or file-like object implementing a string write() function. If None, the result is returned as a string.

table_uuid :str, optional

Id attribute assigned to the <table> HTML element in the format:

<table id="T_<table_uuid>" ..>

If not given uses Styler’s initially assigned value.

table_attributes :str, optional

Attributes to assign within the <table> HTML element in the format:

<table .. <table_attributes> >

If not given defaults to Styler’s preexisting value.

sparse_index :bool, optional

Whether to sparsify the display of a hierarchical index. Setting to False will display each explicit level element in a hierarchical key for each row. Defaults to pandas.options.styler.sparse.index value.

New in version 1.4.0.

sparse_columns :bool, optional

Whether to sparsify the display of a hierarchical index. Setting to False will display each explicit level element in a hierarchical key for each column. Defaults to pandas.options.styler.sparse.columns value.

New in version 1.4.0.

bold_headers :bool, optional

Adds “font-weight: bold;” as a CSS property to table style header cells.

New in version 1.4.0.

caption :str, optional

Set, or overwrite, the caption on Styler before rendering.

New in version 1.4.0.

max_rows :int, optional

The maximum number of rows that will be rendered. Defaults to pandas.options.styler.render.max_rows/max_columns.

New in version 1.4.0.

max_columns :int, optional

The maximum number of columns that will be rendered. Defaults to pandas.options.styler.render.max_columns, which is None.

Rows and columns may be reduced if the number of total elements is large. This value is set to pandas.options.styler.render.max_elements, which is 262144 (18 bit browser rendering).

New in version 1.4.0.

encoding :str, optional

Character encoding setting for file output, and HTML meta tags. Defaults to pandas.options.styler.render.encoding value of “utf-8”.

doctype_html :bool, default False

Whether to output a fully structured HTML file including all HTML elements, or just the core <style> and <table> elements.

exclude_styles :bool, default False

Whether to include the <style> element and all associated element class and id identifiers, or solely the <table> element without styling identifiers.

**kwargs

Any additional keyword arguments are passed through to the jinja2 self.template.render process. This is useful when you need to provide additional variables for a custom template.

Returns
str or None

If buf is None, returns the result as a string. Otherwise returns None.

See also

DataFrame.to_html

Write a DataFrame to a file, buffer or string in HTML format.

© 2008–2022, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team
Licensed under the 3-clause BSD License.
https://pandas.pydata.org/pandas-docs/version/1.4.0/reference/api/pandas.io.formats.style.Styler.to_html.html