pandas.io.formats.style.Styler.format¶
- Styler.format(formatter, subset=None, na_rep=None)[source]¶
Format the text display value of cells.
- Parameters
- formatterstr, callable, dict or None
If
formatteris None, the default formatter is used.- subsetIndexSlice
An argument to
DataFrame.locthat restricts which elementsformatteris applied to.- na_repstr, optional
Representation for missing values. If
na_repis None, no special formatting is applied.New in version 1.0.0.
- Returns
- selfStyler
Notes
formatteris either anaor a dict{column name: a}whereais one ofstr: 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 withpd.options.display.precisionprecision.Examples
>>> df = pd.DataFrame(np.random.randn(4, 2), columns=['a', 'b']) >>> df.style.format("{:.2%}") >>> df['c'] = ['a', 'b', 'c', 'd'] >>> df.style.format({'c': str.upper})