@@ -1318,9 +1318,10 @@ def format_index(
1318
1318
Using the default ``formatter`` for unspecified levels
1319
1319
1320
1320
>>> df = pd.DataFrame([[1, 2, 3]],
1321
- ... columns=pd.MultiIndex.from_arrays([["a", "a", "b"],[2, np.nan, 4]]))
1321
+ ... columns=pd.MultiIndex.from_arrays(
1322
+ ... [["a", "a", "b"], [2, np.nan, 4]]))
1322
1323
>>> df.style.format_index({0: lambda v: v.upper()}, axis=1, precision=1)
1323
- ... # doctest: +SKIP
1324
+ ... # doctest: +SKIP
1324
1325
A B
1325
1326
2.0 nan 4.0
1326
1327
0 1 2 3
@@ -1329,7 +1330,7 @@ def format_index(
1329
1330
1330
1331
>>> func = lambda s: 'STRING' if isinstance(s, str) else 'FLOAT'
1331
1332
>>> df.style.format_index(func, axis=1, na_rep='MISS')
1332
- ... # doctest: +SKIP
1333
+ ... # doctest: +SKIP
1333
1334
STRING STRING
1334
1335
FLOAT MISS FLOAT
1335
1336
0 1 2 3
@@ -1338,7 +1339,7 @@ def format_index(
1338
1339
1339
1340
>>> df = pd.DataFrame([[1, 2, 3]], columns=['"A"', 'A&B', None])
1340
1341
>>> s = df.style.format_index('$ {0}', axis=1, escape="html", na_rep="NA")
1341
- ... # doctest: +SKIP
1342
+ ... # doctest: +SKIP
1342
1343
<th .. >$ "A"</th>
1343
1344
<th .. >$ A&B</th>
1344
1345
<th .. >NA</td>
@@ -1348,7 +1349,7 @@ def format_index(
1348
1349
1349
1350
>>> df = pd.DataFrame([[1, 2, 3]], columns=["123", "~", "$%#"])
1350
1351
>>> df.style.format_index("\\textbf{{{}}}", escape="latex", axis=1).to_latex()
1351
- ... # doctest: +SKIP
1352
+ ... # doctest: +SKIP
1352
1353
\begin{tabular}{lrrr}
1353
1354
{} & {\textbf{123}} & {\textbf{\textasciitilde }} & {\textbf{\$\%\#}} \\
1354
1355
0 & 1 & 2 & 3 \\
@@ -1475,7 +1476,7 @@ def relabel_index(
1475
1476
1476
1477
Chaining with pre-hidden elements
1477
1478
1478
- >>> df.style.hide([0,1]).relabel_index(["C"]) # doctest: +SKIP
1479
+ >>> df.style.hide([0, 1]).relabel_index(["C"]) # doctest: +SKIP
1479
1480
col
1480
1481
C c
1481
1482
@@ -1493,19 +1494,20 @@ def relabel_index(
1493
1494
1 5
1494
1495
1 0 6
1495
1496
1 7
1496
- >>> styler.hide((midx.get_level_values(0)==0)|(midx.get_level_values(1)==0))
1497
- ... # doctest: +SKIP
1498
- >>> styler.hide(level=[0,1]) # doctest: +SKIP
1497
+ >>> styler.hide((midx.get_level_values(0) == 0) |
1498
+ ... (midx.get_level_values(1) == 0))
1499
+ ... # doctest: +SKIP
1500
+ >>> styler.hide(level=[0, 1]) # doctest: +SKIP
1499
1501
>>> styler.relabel_index(["binary6", "binary7"]) # doctest: +SKIP
1500
1502
col
1501
1503
binary6 6
1502
1504
binary7 7
1503
1505
1504
1506
We can also achieve the above by indexing first and then re-labeling
1505
1507
1506
- >>> styler = df.loc[[(1,1, 0), (1,1, 1)]].style
1507
- >>> styler.hide(level=[0,1]).relabel_index(["binary6", "binary7"])
1508
- ... # doctest: +SKIP
1508
+ >>> styler = df.loc[[(1, 1, 0), (1, 1, 1)]].style
1509
+ >>> styler.hide(level=[0, 1]).relabel_index(["binary6", "binary7"])
1510
+ ... # doctest: +SKIP
1509
1511
col
1510
1512
binary6 6
1511
1513
binary7 7
@@ -1516,9 +1518,9 @@ def relabel_index(
1516
1518
brackets if the string if pre-formatted),
1517
1519
1518
1520
>>> df = pd.DataFrame({"samples": np.random.rand(10)})
1519
- >>> styler = df.loc[np.random.randint(0,10,3)].style
1521
+ >>> styler = df.loc[np.random.randint(0, 10, 3)].style
1520
1522
>>> styler.relabel_index([f"sample{i+1} ({{}})" for i in range(3)])
1521
- ... # doctest: +SKIP
1523
+ ... # doctest: +SKIP
1522
1524
samples
1523
1525
sample1 (5) 0.315811
1524
1526
sample2 (0) 0.495941
0 commit comments