Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
Ctrl+K

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.

Added in version 1.3.0.

Parameters:
bufstr, path object, file-like object, optional

String, path object (implementingos.PathLike[str]), or file-likeobject implementing a stringwrite() function. IfNone, the result isreturned as a string.

table_uuidstr, optional

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

<tableid="T_<table_uuid>"..>

If not given uses Styler’s initially assigned value.

table_attributesstr, 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_indexbool, optional

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

Added in version 1.4.0.

sparse_columnsbool, optional

Whether to sparsify the display of a hierarchical index. Setting to Falsewill display each explicit level element in a hierarchical key for eachcolumn. Defaults topandas.options.styler.sparse.columns value.

Added in version 1.4.0.

bold_headersbool, optional

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

Added in version 1.4.0.

captionstr, optional

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

Added in version 1.4.0.

max_rowsint, optional

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

Added in version 1.4.0.

max_columnsint, optional

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

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

Added in version 1.4.0.

encodingstr, optional

Character encoding setting for file output (and meta tags if available).Defaults topandas.options.styler.render.encoding value of “utf-8”.

doctype_htmlbool, default False

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

exclude_stylesbool, default False

Whether to include the<style> element and all associated elementclass andid identifiers, or solely the<table> element withoutstyling identifiers.

**kwargs

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

Returns:
str or None

Ifbuf is None, returns the result as a string. Otherwise returnsNone.

See also

DataFrame.to_html

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

Examples

>>>df=pd.DataFrame({'A':[1,2],'B':[3,4]})>>>print(df.style.to_html())<style type="text/css"></style><table id="T_1e78e">  <thead>    <tr>      <th class="blank level0" >&nbsp;</th>      <th id="T_1e78e_level0_col0" class="col_heading level0 col0" >A</th>      <th id="T_1e78e_level0_col1" class="col_heading level0 col1" >B</th>    </tr>...

[8]ページ先頭

©2009-2025 Movatter.jp