Styler.
applymap
Apply a CSS-styling function elementwise.
Updates the HTML representation with the result.
func should take a scalar and return a scalar.
func
A valid indexer to limit data to before applying the function. Consider using a pandas.IndexSlice.
data
Pass along to func.
See also
Styler.where
Updates the HTML representation with a style which is selected in accordance with the return value of a function.
Notes
The output of func should be a CSS style as string or, if nothing is to be applied, an empty string or None.
None
Examples
>>> def color_negative(v, color): ... return f"color: {color};" if v < 0 else None >>> df = pd.DataFrame(np.random.randn(5, 2)) >>> df.style.applymap(color_negative, color='red')