Styler.
format
Format the text display value of cells.
If formatter is None, the default formatter is used.
formatter
An argument to DataFrame.loc that restricts which elements formatter is applied to.
DataFrame.loc
Representation for missing values. If na_rep is None, no special formatting is applied.
na_rep
New in version 1.0.0.
Notes
formatter is either an a or a dict {column name: a} where a is one of
a
{column name: a}
str: this will be wrapped in: a.format(x)
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.
g
pd.options.display.precision
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})