Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
Ctrl+K

pandas.io.formats.style.Styler.set_tooltips#

Styler.set_tooltips(ttips,props=None,css_class=None)[source]#

Set the DataFrame of strings onStyler generating:hover tooltips.

These string based tooltips are only applicable to<td> HTML elements,and cannot be used for column or index headers.

Added in version 1.3.0.

Parameters:
ttipsDataFrame

DataFrame containing strings that will be translated to tooltips, mappedby identical column and index values that must exist on the underlyingStyler data. None, NaN values, and empty strings will be ignored andnot affect the rendered HTML.

propslist-like or str, optional

List of (attr, value) tuples or a valid CSS string. IfNone adoptsthe internal default values described in notes.

css_classstr, optional

Name of the tooltip class used in CSS, should conform to HTML standards.Only useful if integrating tooltips with external CSS. IfNone uses theinternal default value ‘pd-t’.

Returns:
Styler

Notes

Tooltips are created by adding<span class=”pd-t”></span> to each data celland then manipulating the table level CSS to attach pseudo hover and pseudoafter selectors to produce the required the results.

The default properties for the tooltip CSS class are:

  • visibility: hidden

  • position: absolute

  • z-index: 1

  • background-color: black

  • color: white

  • transform: translate(-20px, -20px)

The property ‘visibility: hidden;’ is a key prerequisite to the hoverfunctionality, and should always be included in any manual propertiesspecification, using theprops argument.

Tooltips are not designed to be efficient, and can add large amounts ofadditional HTML for larger tables, since they also require thatcell_idsis forced toTrue.

Examples

Basic application

>>>df=pd.DataFrame(data=[[0,1],[2,3]])>>>ttips=pd.DataFrame(...data=[["Min",""],[np.nan,"Max"]],columns=df.columns,index=df.index...)>>>s=df.style.set_tooltips(ttips).to_html()

Optionally controlling the tooltip visual display

>>>df.style.set_tooltips(ttips,css_class='tt-add',props=[...('visibility','hidden'),...('position','absolute'),...('z-index',1)])>>>df.style.set_tooltips(ttips,css_class='tt-add',...props='visibility:hidden; position:absolute; z-index:1;')...

[8]ページ先頭

©2009-2025 Movatter.jp