@@ -1063,33 +1063,33 @@ def format(
10631063
10641064 Using a ``formatter`` specification on consistent column dtypes
10651065
1066- >>> df.style.format('{:.2f}', na_rep='MISS', subset=[0,1]) # doctest: +SKIP
1066+ >>> df.style.format('{:.2f}', na_rep='MISS', subset=[0, 1]) # doctest: +SKIP
10671067 0 1 2
10681068 0 MISS 1.00 A
10691069 1 2.00 MISS 3.000000
10701070
10711071 Using the default ``formatter`` for unspecified columns
10721072
1073- >>> df.style.format({0: '{:.2f}', 1: '£ {:.1f}'}, na_rep='MISS', precision=1)
1074- ... # doctest: +SKIP
1073+ >>> df.style.format({0: '{:.2f}', 1: '£ {:.1f}'},
1074+ ... na_rep='MISS', precision=1) # doctest: +SKIP
10751075 0 1 2
10761076 0 MISS £ 1.0 A
10771077 1 2.00 MISS 3.0
10781078
10791079 Multiple ``na_rep`` or ``precision`` specifications under the default
10801080 ``formatter``.
10811081
1082- >>> (df.style.format(na_rep='MISS', precision=1, subset=[0])
1083- ... .format( na_rep='PASS', precision=2, subset=[1, 2])) # doctest: +SKIP
1082+ >>> (df.style.format(na_rep='MISS', precision=1, subset=[0]).format(
1083+ ... na_rep='PASS', precision=2, subset=[1, 2])) # doctest: +SKIP
10841084 0 1 2
10851085 0 MISS 1.00 A
10861086 1 2.0 PASS 3.00
10871087
10881088 Using a callable ``formatter`` function.
10891089
10901090 >>> func = lambda s: 'STRING' if isinstance(s, str) else 'FLOAT'
1091- >>> df.style.format({0: '{:.1f}', 2: func}, precision=4, na_rep='MISS')
1092- ... # doctest: +SKIP
1091+ >>> df.style.format({0: '{:.1f}', 2: func},
1092+ ... precision=4, na_rep='MISS') # doctest: +SKIP
10931093 0 1 2
10941094 0 MISS 1.0000 STRING
10951095 1 2.0 MISS FLOAT
@@ -1098,8 +1098,7 @@ def format(
10981098
10991099 >>> df = pd.DataFrame([['<div></div>', '"A&B"', None]])
11001100 >>> s = df.style.format(
1101- ... '<a href="a.com/{0}">{0}</a>', escape="html", na_rep="NA"
1102- ... )
1101+ ... '<a href="a.com/{0}">{0}</a>', escape="html", na_rep="NA")
11031102 >>> s.to_html() # doctest: +SKIP
11041103 ...
11051104 <td .. ><a href="a.com/<div></div>"><div></div></a></td>
@@ -1110,8 +1109,8 @@ def format(
11101109 Using a ``formatter`` with ``escape`` in 'latex' mode.
11111110
11121111 >>> df = pd.DataFrame([["123"], ["~ ^"], ["$%#"]])
1113- >>> df.style.format("\\textbf{{{}}}", escape="latex").to_latex()
1114- ... # doctest: +SKIP
1112+ >>> df.style.format("\\textbf{{{}}}",
1113+ ... escape="latex").to_latex() # doctest: +SKIP
11151114 \begin{tabular}{ll}
11161115 & 0 \\
11171116 0 & \textbf{123} \\
@@ -1122,10 +1121,10 @@ def format(
11221121 Applying ``escape`` in 'latex-math' mode. In the example below
11231122 we enter math mode using the character ``$``.
11241123
1125- >>> df = pd.DataFrame([[r"$\sum_{i=1}^{10} a_i$ a~b $\alpha \
1126- ... = \ frac{\beta}{\zeta^2}$"], ["%#^ $ \$x^2 $"]])
1127- >>> df.style.format(escape="latex-math").to_latex( )
1128- ... # doctest: +SKIP
1124+ >>> df = pd.DataFrame([
1125+ ... [r"$\sum_{i=1}^{10} a_i$ a~b $\alpha = \ frac{\beta}{\zeta^2}$"],
1126+ ... [r"%#^ $ \$x^2 $"]] )
1127+ >>> df.style.format(escape="latex-math").to_latex() # doctest: +SKIP
11291128 \begin{tabular}{ll}
11301129 & 0 \\
11311130 0 & $\sum_{i=1}^{10} a_i$ a\textasciitilde b $\alpha = \frac{\beta}{\zeta^2}$ \\
@@ -1135,10 +1134,10 @@ def format(
11351134 We can use the character ``\(`` to enter math mode and the character ``\)``
11361135 to close math mode.
11371136
1138- >>> df = pd.DataFrame([[r"\(\sum_{i=1}^{10} a_i\) a~b \(\alpha \
1139- ... = \frac{\beta}{\zeta^2}\)"], ["%#^ \( \$x^2 \)"]])
1140- >>> df.style.format(escape="latex-math").to_latex( )
1141- ... # doctest: +SKIP
1137+ >>> df = pd.DataFrame([
1138+ ... [r"\(\sum_{i=1}^{10} a_i\) a~b \(\alpha = \frac{\beta}{\zeta^2} \)"],
1139+ ... [r"%#^ \( \$x^2 \)"]] )
1140+ >>> df.style.format(escape="latex-math").to_latex() # doctest: +SKIP
11421141 \begin{tabular}{ll}
11431142 & 0 \\
11441143 0 & \(\sum_{i=1}^{10} a_i\) a\textasciitilde b \(\alpha
@@ -1149,10 +1148,10 @@ def format(
11491148 If we have in one DataFrame cell a combination of both shorthands
11501149 for math formulas, the shorthand with the sign ``$`` will be applied.
11511150
1152- >>> df = pd.DataFrame([[r"\( x^2 \) $x^2$"], \
1151+ >>> df = pd.DataFrame([
1152+ ... [r"\( x^2 \) $x^2$"],
11531153 ... [r"$\frac{\beta}{\zeta}$ \(\frac{\beta}{\zeta}\)"]])
1154- >>> df.style.format(escape="latex-math").to_latex()
1155- ... # doctest: +SKIP
1154+ >>> df.style.format(escape="latex-math").to_latex() # doctest: +SKIP
11561155 \begin{tabular}{ll}
11571156 & 0 \\
11581157 0 & \textbackslash ( x\textasciicircum 2 \textbackslash ) $x^2$ \\
@@ -1169,7 +1168,7 @@ def format(
11691168 >>> df = pd.DataFrame({"A": [1, 0, -1]})
11701169 >>> pseudo_css = "number-format: 0§[Red](0)§-§@;"
11711170 >>> filename = "formatted_file.xlsx"
1172- >>> df.style.map(lambda v: pseudo_css).to_excel(filename) # doctest: +SKIP
1171+ >>> df.style.map(lambda v: pseudo_css).to_excel(filename) # doctest: +SKIP
11731172
11741173 .. figure:: ../../_static/style/format_excel_css.png
11751174 """
0 commit comments