pandas.io.formats.style.Styler.highlight_between#
- Styler.highlight_between(subset=None, color='yellow', axis=0, left=None, right=None, inclusive='both', props=None)[source]#
Highlight a defined range with a style.
New 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
If
left
orright
given as sequence, axis along which to apply those boundaries. See examples.- leftscalar or datetime-like, or sequence or array-like, default None
Left bound for defining the range.
- rightscalar or datetime-like, or sequence or array-like, default None
Right bound for defining the range.
- inclusive{‘both’, ‘neither’, ‘left’, ‘right’}
Identify whether bounds are closed or open.
- propsstr, default None
CSS properties to use for highlighting. If
props
is given,color
is not used.
- Returns
- selfStyler
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_quantile
Highlight values defined by a quantile with a style.
Notes
If
left
isNone
only the right bound is applied. Ifright
isNone
only the left bound is applied. If both areNone
all values are highlighted.axis
is only needed ifleft
orright
are provided as a sequence or an array-like object for aligning the shapes. Ifleft
andright
are both scalars then allaxis
inputs will give the same result.This function only works with compatible
dtypes
. For example a datetime-like region can only use equivalent datetime-likeleft
andright
arguments. Usesubset
to control regions which have multipledtypes
.Examples
Basic usage
>>> df = pd.DataFrame({ ... 'One': [1.2, 1.6, 1.5], ... 'Two': [2.9, 2.1, 2.5], ... 'Three': [3.1, 3.2, 3.8], ... }) >>> df.style.highlight_between(left=2.1, right=2.9)
Using a range input sequnce along an
axis
, in this case setting aleft
andright
for each column individually>>> df.style.highlight_between(left=[1.4, 2.4, 3.4], right=[1.6, 2.6, 3.6], ... axis=1, color="#fffd75")
Using
axis=None
and providing theleft
argument as an array that matches the input DataFrame, with a constantright
>>> df.style.highlight_between(left=[[2,2,3],[2,2,3],[3,3,3]], right=3.5, ... axis=None, color="#fffd75")
Using
props
instead of default background coloring>>> df.style.highlight_between(left=1.5, right=3.5, ... props='font-weight:bold;color:#e83e8c')