@@ -614,9 +614,10 @@ def apply(
614
614
Apply to each column (``axis=0`` or ``'index'``), to each row
615
615
(``axis=1`` or ``'columns'``), or to the entire DataFrame at once
616
616
with ``axis=None``.
617
- subset : IndexSlice
618
- A valid indexer to limit ``data`` to *before* applying the
619
- function. Consider using a pandas.IndexSlice.
617
+ subset : label, array-like, IndexSlice, optional
618
+ A valid 2d input to `DataFrame.loc[<subset>]`, or, in the case of a 1d input
619
+ or single key, to `DataFrame.loc[:, <subset>]` where the columns are
620
+ prioritised, to limit ``data`` to *before* applying the function.
620
621
**kwargs : dict
621
622
Pass along to ``func``.
622
623
@@ -642,10 +643,20 @@ def apply(
642
643
--------
643
644
>>> def highlight_max(x, color):
644
645
... return np.where(x == np.nanmax(x.to_numpy()), f"color: {color};", None)
645
- >>> df = pd.DataFrame(np.random.randn(5, 2))
646
+ >>> df = pd.DataFrame(np.random.randn(5, 2), columns=["A", "B"] )
646
647
>>> df.style.apply(highlight_max, color='red')
647
648
>>> df.style.apply(highlight_max, color='blue', axis=1)
648
649
>>> df.style.apply(highlight_max, color='green', axis=None)
650
+
651
+ Using ``subset`` to restrict application to a single column or multiple columns
652
+
653
+ >>> df.style.apply(highlight_max, color='red', subset="A")
654
+ >>> df.style.apply(highlight_max, color='red', subset=["A", "B"])
655
+
656
+ Using a 2d input to ``subset`` to select rows in addition to columns
657
+
658
+ >>> df.style.apply(highlight_max, color='red', subset=([0,1,2], slice(None))
659
+ >>> df.style.apply(highlight_max, color='red', subset=(slice(0,5,2), "A")
649
660
"""
650
661
self ._todo .append (
651
662
(lambda instance : getattr (instance , "_apply" ), (func , axis , subset ), kwargs )
@@ -675,9 +686,10 @@ def applymap(
675
686
----------
676
687
func : function
677
688
``func`` should take a scalar and return a scalar.
678
- subset : IndexSlice
679
- A valid indexer to limit ``data`` to *before* applying the
680
- function. Consider using a pandas.IndexSlice.
689
+ subset : label, array-like, IndexSlice, optional
690
+ A valid 2d input to `DataFrame.loc[<subset>]`, or, in the case of a 1d input
691
+ or single key, to `DataFrame.loc[:, <subset>]` where the columns are
692
+ prioritised, to limit ``data`` to *before* applying the function.
681
693
**kwargs : dict
682
694
Pass along to ``func``.
683
695
@@ -699,8 +711,18 @@ def applymap(
699
711
--------
700
712
>>> def color_negative(v, color):
701
713
... return f"color: {color};" if v < 0 else None
702
- >>> df = pd.DataFrame(np.random.randn(5, 2))
714
+ >>> df = pd.DataFrame(np.random.randn(5, 2), columns=["A", "B"] )
703
715
>>> df.style.applymap(color_negative, color='red')
716
+
717
+ Using ``subset`` to restrict application to a single column or multiple columns
718
+
719
+ >>> df.style.applymap(color_negative, color='red', subset="A")
720
+ >>> df.style.applymap(color_negative, color='red', subset=["A", "B"])
721
+
722
+ Using a 2d input to ``subset`` to select rows in addition to columns
723
+
724
+ >>> df.style.applymap(color_negative, color='red', subset=([0,1,2], slice(None))
725
+ >>> df.style.applymap(color_negative, color='red', subset=(slice(0,5,2), "A")
704
726
"""
705
727
self ._todo .append (
706
728
(lambda instance : getattr (instance , "_applymap" ), (func , subset ), kwargs )
@@ -732,9 +754,10 @@ def where(
732
754
Applied when ``cond`` returns true.
733
755
other : str
734
756
Applied when ``cond`` returns false.
735
- subset : IndexSlice
736
- A valid indexer to limit ``data`` to *before* applying the
737
- function. Consider using a pandas.IndexSlice.
757
+ subset : label, array-like, IndexSlice, optional
758
+ A valid 2d input to `DataFrame.loc[<subset>]`, or, in the case of a 1d input
759
+ or single key, to `DataFrame.loc[:, <subset>]` where the columns are
760
+ prioritised, to limit ``data`` to *before* applying the function.
738
761
**kwargs : dict
739
762
Pass along to ``cond``.
740
763
@@ -1072,9 +1095,9 @@ def hide_columns(self, subset: Subset) -> Styler:
1072
1095
1073
1096
Parameters
1074
1097
----------
1075
- subset : IndexSlice
1076
- An argument to ``DataFrame.loc`` that identifies which columns
1077
- are hidden .
1098
+ subset : label, array-like, IndexSlice
1099
+ A valid 1d input or single key along the appropriate axis within
1100
+ `DataFrame.loc[]`, to limit ``data`` to *before* applying the function .
1078
1101
1079
1102
Returns
1080
1103
-------
@@ -1127,8 +1150,10 @@ def background_gradient(
1127
1150
Apply to each column (``axis=0`` or ``'index'``), to each row
1128
1151
(``axis=1`` or ``'columns'``), or to the entire DataFrame at once
1129
1152
with ``axis=None``.
1130
- subset : IndexSlice
1131
- A valid slice for ``data`` to limit the style application to.
1153
+ subset : label, array-like, IndexSlice, optional
1154
+ A valid 2d input to `DataFrame.loc[<subset>]`, or, in the case of a 1d input
1155
+ or single key, to `DataFrame.loc[:, <subset>]` where the columns are
1156
+ prioritised, to limit ``data`` to *before* applying the function.
1132
1157
text_color_threshold : float or int
1133
1158
Luminance threshold for determining text color in [0, 1]. Facilitates text
1134
1159
visibility across varying background colors. All text is dark if 0, and
@@ -1251,8 +1276,10 @@ def set_properties(self, subset: Subset | None = None, **kwargs) -> Styler:
1251
1276
1252
1277
Parameters
1253
1278
----------
1254
- subset : IndexSlice
1255
- A valid slice for ``data`` to limit the style application to.
1279
+ subset : label, array-like, IndexSlice, optional
1280
+ A valid 2d input to `DataFrame.loc[<subset>]`, or, in the case of a 1d input
1281
+ or single key, to `DataFrame.loc[:, <subset>]` where the columns are
1282
+ prioritised, to limit ``data`` to *before* applying the function.
1256
1283
**kwargs : dict
1257
1284
A dictionary of property, value pairs to be set for each cell.
1258
1285
@@ -1349,8 +1376,10 @@ def bar(
1349
1376
1350
1377
Parameters
1351
1378
----------
1352
- subset : IndexSlice, optional
1353
- A valid slice for `data` to limit the style application to.
1379
+ subset : label, array-like, IndexSlice, optional
1380
+ A valid 2d input to `DataFrame.loc[<subset>]`, or, in the case of a 1d input
1381
+ or single key, to `DataFrame.loc[:, <subset>]` where the columns are
1382
+ prioritised, to limit ``data`` to *before* applying the function.
1354
1383
axis : {0 or 'index', 1 or 'columns', None}, default 0
1355
1384
Apply to each column (``axis=0`` or ``'index'``), to each row
1356
1385
(``axis=1`` or ``'columns'``), or to the entire DataFrame at once
@@ -1431,8 +1460,10 @@ def highlight_null(
1431
1460
Parameters
1432
1461
----------
1433
1462
null_color : str, default 'red'
1434
- subset : label or list of labels, default None
1435
- A valid slice for ``data`` to limit the style application to.
1463
+ subset : label, array-like, IndexSlice, optional
1464
+ A valid 2d input to `DataFrame.loc[<subset>]`, or, in the case of a 1d input
1465
+ or single key, to `DataFrame.loc[:, <subset>]` where the columns are
1466
+ prioritised, to limit ``data`` to *before* applying the function.
1436
1467
1437
1468
.. versionadded:: 1.1.0
1438
1469
@@ -1477,8 +1508,10 @@ def highlight_max(
1477
1508
1478
1509
Parameters
1479
1510
----------
1480
- subset : IndexSlice, default None
1481
- A valid slice for ``data`` to limit the style application to.
1511
+ subset : label, array-like, IndexSlice, optional
1512
+ A valid 2d input to `DataFrame.loc[<subset>]`, or, in the case of a 1d input
1513
+ or single key, to `DataFrame.loc[:, <subset>]` where the columns are
1514
+ prioritised, to limit ``data`` to *before* applying the function.
1482
1515
color : str, default 'yellow'
1483
1516
Background color to use for highlighting.
1484
1517
axis : {0 or 'index', 1 or 'columns', None}, default 0
@@ -1526,8 +1559,10 @@ def highlight_min(
1526
1559
1527
1560
Parameters
1528
1561
----------
1529
- subset : IndexSlice, default None
1530
- A valid slice for ``data`` to limit the style application to.
1562
+ subset : label, array-like, IndexSlice, optional
1563
+ A valid 2d input to `DataFrame.loc[<subset>]`, or, in the case of a 1d input
1564
+ or single key, to `DataFrame.loc[:, <subset>]` where the columns are
1565
+ prioritised, to limit ``data`` to *before* applying the function.
1531
1566
color : str, default 'yellow'
1532
1567
Background color to use for highlighting.
1533
1568
axis : {0 or 'index', 1 or 'columns', None}, default 0
@@ -1580,8 +1615,10 @@ def highlight_between(
1580
1615
1581
1616
Parameters
1582
1617
----------
1583
- subset : IndexSlice, default None
1584
- A valid slice for ``data`` to limit the style application to.
1618
+ subset : label, array-like, IndexSlice, optional
1619
+ A valid 2d input to `DataFrame.loc[<subset>]`, or, in the case of a 1d input
1620
+ or single key, to `DataFrame.loc[:, <subset>]` where the columns are
1621
+ prioritised, to limit ``data`` to *before* applying the function.
1585
1622
color : str, default 'yellow'
1586
1623
Background color to use for highlighting.
1587
1624
axis : {0 or 'index', 1 or 'columns', None}, default 0
@@ -1688,8 +1725,10 @@ def highlight_quantile(
1688
1725
1689
1726
Parameters
1690
1727
----------
1691
- subset : IndexSlice, default None
1692
- A valid slice for ``data`` to limit the style application to.
1728
+ subset : label, array-like, IndexSlice, optional
1729
+ A valid 2d input to `DataFrame.loc[<subset>]`, or, in the case of a 1d input
1730
+ or single key, to `DataFrame.loc[:, <subset>]` where the columns are
1731
+ prioritised, to limit ``data`` to *before* applying the function.
1693
1732
color : str, default 'yellow'
1694
1733
Background color to use for highlighting
1695
1734
axis : {0 or 'index', 1 or 'columns', None}, default 0
0 commit comments