def format(self, formatter, subset=None):
if subset is None:<EOL><INDENT>row_locs = range(len(self.data))<EOL>col_locs = range(len(self.data.columns))<EOL><DEDENT>else:<EOL><INDENT>subset = _non_reducing_slice(subset)<EOL>if len(subset) == <NUM_LIT:1>:<EOL><INDENT>subset = subset, self.data.columns<EOL><DEDENT>sub_df = self.data.loc[subset]<EOL>row_locs = self.data.index.get_indexer_for(sub_df.index)<EOL>col_locs = self.data.columns.get_indexer_for(sub_df.columns)<EOL><DEDENT>if is_dict_like(formatter):<EOL><INDENT>for col, col_formatter in formatter.items():<EOL><INDENT>col_formatter = _maybe_wrap_formatter(col_formatter)<EOL>col_num = self.data.columns.get_indexer_for([col])[<NUM_LIT:0>]<EOL>for row_num in row_locs:<EOL><INDENT>self._display_funcs[(row_num, col_num)] = col_formatter<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>locs = product(*(row_locs, col_locs))<EOL>for i, j in locs:<EOL><INDENT>formatter = _maybe_wrap_formatter(formatter)<EOL>self._display_funcs[(i, j)] = formatter<EOL><DEDENT><DEDENT>return self<EOL>
Format the text display value of cells.

.. versionadded:: 0.18.0

Parameters
----------
formatter : str, callable, or dict
subset : IndexSlice
    An argument to ``DataFrame.loc`` that restricts which elements
    ``formatter`` is applied to.

Returns
-------
self : Styler

Notes
-----

``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.

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})