Styler.applymap(func, subset=None, **kwargs)[source]

Apply a CSS-styling function elementwise.

Updates the HTML representation with the result.


func should take a scalar and return a scalar.

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.


Pass along to func.


See also


Apply a CSS-styling function column-wise, row-wise, or table-wise.


The elements of the output of func should be CSS styles as strings, in the format ‘attribute: value; attribute2: value2; …’ or, if nothing is to be applied to that element, an empty string or None.


>>> def color_negative(v, color):
...     return f"color: {color};" if v < 0 else None
>>> df = pd.DataFrame(np.random.randn(5, 2), columns=["A", "B"])
>>>, color='red')

Using subset to restrict application to a single column or multiple columns

>>>, color='red', subset="A")
>>>, color='red', subset=["A", "B"])

Using a 2d input to subset to select rows in addition to columns

>>>, color='red', subset=([0,1,2], slice(None))
>>>, color='red', subset=(slice(0,5,2), "A")