On this page
pandas.io.formats.style.Styler.format
Styler.format(formatter, subset=None)
[source]-
Format the text display value of cells.
New in version 0.18.0.
Parameters: -
formatter : str, callable, or dict
-
subset : IndexSlice
-
An argument to
DataFrame.loc
that restricts which elementsformatter
is applied to.
Returns: -
self : Styler
Notes
formatter
is either ana
or a dict{column name: a}
wherea
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 withpd.options.display.precision
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})
-
© 2008–2012, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team
Licensed under the 3-clause BSD License.
https://pandas.pydata.org/pandas-docs/version/0.24.2/reference/api/pandas.io.formats.style.Styler.format.html