pandas.io.formats.style.Styler.highlight_quantile#
- Styler.highlight_quantile(subset=None, color='yellow', axis=0, q_left=0.0, q_right=1.0, interpolation='linear', inclusive='both', props=None)[source]#
Highlight values defined by a quantile with a style.
Added in version 1.3.0.
- Parameters:
- subsetlabel, array-like, IndexSlice, optional
A valid 2d input to DataFrame.loc[<subset>], or, in the case of a 1d input or single key, to DataFrame.loc[:, <subset>] where the columns are prioritised, to limit
data
to before applying the function.- colorstr, default ‘yellow’
Background color to use for highlighting.
- axis{0 or ‘index’, 1 or ‘columns’, None}, default 0
Axis along which to determine and highlight quantiles. If
None
quantiles are measured over the entire DataFrame. See examples.- q_leftfloat, default 0
Left bound, in [0, q_right), for the target quantile range.
- q_rightfloat, default 1
Right bound, in (q_left, 1], for the target quantile range.
- interpolation{‘linear’, ‘lower’, ‘higher’, ‘midpoint’, ‘nearest’}
Argument passed to
Series.quantile
orDataFrame.quantile
for quantile estimation.- inclusive{‘both’, ‘neither’, ‘left’, ‘right’}
Identify whether quantile bounds are closed or open.
- propsstr, default None
CSS properties to use for highlighting. If
props
is given,color
is not used.
- Returns:
- Styler
See also
Styler.highlight_null
Highlight missing values with a style.
Styler.highlight_max
Highlight the maximum with a style.
Styler.highlight_min
Highlight the minimum with a style.
Styler.highlight_between
Highlight a defined range with a style.
Notes
This function does not work with
str
dtypes.Examples
Using
axis=None
and apply a quantile to all collective data>>> df = pd.DataFrame(np.arange(10).reshape(2, 5) + 1) >>> df.style.highlight_quantile(axis=None, q_left=0.8, color="#fffd75") ...
Or highlight quantiles row-wise or column-wise, in this case by row-wise
>>> df.style.highlight_quantile(axis=1, q_left=0.8, color="#fffd75") ...
Use
props
instead of default background coloring>>> df.style.highlight_quantile( ... axis=None, ... q_left=0.2, ... q_right=0.8, ... props="font-weight:bold;color:#e83e8c", ... )