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.

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 or right 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.


See also


Highlight missing values with a style.


Highlight the maximum with a style.


Highlight the minimum with a style.


Highlight values defined by a quantile with a style.


If left is None only the right bound is applied. If right is None only the left bound is applied. If both are None all values are highlighted.

axis is only needed if left or right are provided as a sequence or an array-like object for aligning the shapes. If left and right are both scalars then all axis inputs will give the same result.

This function only works with compatible dtypes. For example a datetime-like region can only use equivalent datetime-like left and right arguments. Use subset to control regions which have multiple dtypes.


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],
... })
>>>, right=2.9)  

Using a range input sequnce along an axis, in this case setting a left and right for each column individually

>>>[1.4, 2.4, 3.4], right=[1.6, 2.6, 3.6],
...     axis=1, color="#fffd75")  

Using axis=None and providing the left argument as an array that matches the input DataFrame, with a constant right

>>>[[2,2,3],[2,2,3],[3,3,3]], right=3.5,
...     axis=None, color="#fffd75")  

Using props instead of default background coloring

>>>, right=3.5,
...     props='font-weight:bold;color:#e83e8c')