tiIndex level numbers or names, and values should be string or callable, as above. The default formatter currently expresses floats and complex numbers with the pandas display precision unless using the ``precision`` argument here. The default formatter does not adjust the representation of missing values unless the ``na_rep`` argument is used. The ``level`` argument defines which levels of a MultiIndex to apply the method to. If the ``formatter`` argument is given in dict form but does not include all levels within the level argument then these unspecified levels will have the default formatter applied. Any levels in the formatter dict specifically excluded from the level argument will be ignored. When using a ``formatter`` string the dtypes must be compatible, otherwise a `ValueError` will be raised. .. warning:: `Styler.format_index` is ignored when using the output format `Styler.to_excel`, since Excel and Python have inherrently different formatting structures. However, it is possible to use the `number-format` pseudo CSS attribute to force Excel permissible formatting. See documentation for `Styler.format`. Examples -------- Using ``na_rep`` and ``precision`` with the default ``formatter`` >>> df = pd.DataFrame([[1, 2, 3]], columns=[2.0, np.nan, 4.0]) >>> df.style.format_index(axis=1, na_rep='MISS', precision=3) # doctest: +SKIP 2.000 MISS 4.000 0 1 2 3 Using a ``formatter`` specification on consistent dtypes in a level >>> df.style.format_index('{:.2f}', axis=1, na_rep='MISS') # doctest: +SKIP 2.00 MISS 4.00 0 1 2 3 Using the default ``formatter`` for unspecified levels >>> df = pd.DataFrame([[1, 2, 3]], ... columns=pd.MultiIndex.from_arrays([["a", "a", "b"],[2, np.nan, 4]])) >>> df.style.format_index({0: lambda v: v.upper()}, axis=1, precision=1) ... # doctest: +SKIP A B 2.0 nan 4.0 0 1 2 3 Using a callable ``formatter`` function. >>> func = lambda s: 'STRING' if isinstance(s, str) else 'FLOAT' >>> df.style.format_index(func, axis=1, na_rep='MISS') ... # doctest: +SKIP STRING STRING FLOAT MISS FLOAT 0 1 2 3 Using a ``formatter`` with HTML ``escape`` and ``na_rep``. >>> df = pd.DataFrame([[1, 2, 3]], columns=['"A"', 'A&B', None]) >>> s = df.style.format_index('$ {0}', axis=1, escape="html", na_rep="NA") ... # doctest: +SKIP $ "A" $ A&B NA ... Using a ``formatter`` with LaTeX ``escape``. >>> df = pd.DataFrame([[1, 2, 3]], columns=["123", "~", "$%#"]) >>> df.style.format_index("\\textbf{{{}}}", escape="latex", axis=1).to_latex() ... # doctest: +SKIP \begin{tabular}{lrrr} {} & {\textbf{123}} & {\textbf{\textasciitilde }} & {\textbf{\$\%\#}} \\ 0 & 1 & 2 & 3 \\ \end{tabular} r