"{:.1f}") ... .pipe(some_highlights, min_color="green") ... .highlight_between(left=2, right=5)) # doctest: +SKIP .. figure:: ../../_static/style/df_pipe_hl2.png **Advanced Use** Sometimes it may be necessary to pre-define styling functions, but in the case where those functions rely on the styler, data or context. Since ``Styler.use`` and ``Styler.export`` are designed to be non-data dependent, they cannot be used for this purpose. Additionally the ``Styler.apply`` and ``Styler.format`` type methods are not context aware, so a solution is to use ``pipe`` to dynamically wrap this functionality. Suppose we want to code a generic styling function that highlights the final level of a MultiIndex. The number of levels in the Index is dynamic so we need the ``Styler`` context to define the level. >>> def highlight_last_level(styler): ... return styler.apply_index( ... lambda v: "background-color: pink; color: yellow", axis="columns", ... level=styler.columns.nlevels-1 ... ) # doctest: +SKIP >>> df.columns = pd.MultiIndex.from_product([["A", "B"], ["X", "Y"]]) >>> df.style.pipe(highlight_last_level) # doctest: +SKIP .. figure:: ../../_static/style/df_pipe_applymap.png Additionally suppose we want to highlight a column header if there is any missing data in that column. In this case we need the data object itself to determine the effect on the column headers. >>> def highlight_header_missing(styler, level): ... def dynamic_highlight(s): ... return np.where( ... styler.data.isna().any(), "background-color: red;", "" ... ) ... return styler.apply_index(dynamic_highlight, axis=1, level=level) >>> df.style.pipe(highlight_header_missing, level=1) # doctest: +SKIP .. figure:: ../../_static/style/df_pipe_applydata.png )