Styler.format(formatter, subset=None)

Format the text display value of cells.

New in version 0.18.0.


formatter: str, callable, or dict

subset: IndexSlice

An argument to DataFrame.loc that restricts which elements formatter is applied to.


self : Styler


formatter is either an a or a dict {column name: a} where a is one of

  • str: this will be wrapped in: a.format(x)
  • callable: called with the value of an individual cell

The default display value for numeric values is the “general” (g) format with pd.options.display.precision precision.


>>> df = pd.DataFrame(np.random.randn(4, 2), columns=['a', 'b'])
>>> df['c'] = ['a', 'b', 'c', 'd']
>>>{'C': str.upper})