@@ -217,8 +217,10 @@ def set_tooltips(
217
217
css_class : Optional [str ] = None ,
218
218
) -> Styler :
219
219
"""
220
- Add string based tooltips that will appear in the `Styler` HTML result. These
221
- tooltips are applicable only to`<td>` elements.
220
+ Set the DataFrame of strings on ``Styler`` generating ``:hover`` tooltips.
221
+
222
+ These string based tooltips are only applicable to ``<td>`` HTML elements,
223
+ and cannot be used for column or index headers.
222
224
223
225
.. versionadded:: 1.3.0
224
226
@@ -227,7 +229,7 @@ def set_tooltips(
227
229
ttips : DataFrame
228
230
DataFrame containing strings that will be translated to tooltips, mapped
229
231
by identical column and index values that must exist on the underlying
230
- ` Styler` data. None, NaN values, and empty strings will be ignored and
232
+ Styler data. None, NaN values, and empty strings will be ignored and
231
233
not affect the rendered HTML.
232
234
props : list-like or str, optional
233
235
List of (attr, value) tuples or a valid CSS string. If ``None`` adopts
@@ -671,21 +673,33 @@ def format(
671
673
672
674
def set_td_classes (self , classes : DataFrame ) -> Styler :
673
675
"""
674
- Add string based CSS class names to data cells that will appear within the
675
- `Styler` HTML result. These classes are added within specified `<td>` elements.
676
+ Set the DataFrame of strings added to the ``class`` attribute of ``<td>``
677
+ HTML elements.
676
678
677
679
Parameters
678
680
----------
679
681
classes : DataFrame
680
682
DataFrame containing strings that will be translated to CSS classes,
681
- mapped by identical column and index values that must exist on the
682
- underlying ` Styler` data. None, NaN values, and empty strings will
683
+ mapped by identical column and index key values that must exist on the
684
+ underlying Styler data. None, NaN values, and empty strings will
683
685
be ignored and not affect the rendered HTML.
684
686
685
687
Returns
686
688
-------
687
689
self : Styler
688
690
691
+ See Also
692
+ --------
693
+ Styler.set_table_styles: Set the table styles included within the ``<style>``
694
+ HTML element.
695
+ Styler.set_table_attributes: Set the table attributes added to the ``<table>``
696
+ HTML element.
697
+
698
+ Notes
699
+ -----
700
+ Can be used in combination with ``Styler.set_table_styles`` to define an
701
+ internal CSS solution without reference to external CSS files.
702
+
689
703
Examples
690
704
--------
691
705
>>> df = pd.DataFrame(data=[[1, 2, 3], [4, 5, 6]], columns=["A", "B", "C"])
@@ -707,16 +721,16 @@ def set_td_classes(self, classes: DataFrame) -> Styler:
707
721
Form of the output with new additional css classes,
708
722
709
723
>>> df = pd.DataFrame([[1]])
710
- >>> css = pd.DataFrame(["other-class"])
724
+ >>> css = pd.DataFrame([[ "other-class"] ])
711
725
>>> s = Styler(df, uuid="_", cell_ids=False).set_td_classes(css)
712
726
>>> s.hide_index().render()
713
- '<style type="text/css" ></style>'
714
- '<table id="T__" >'
727
+ '<style type="text/css"></style>'
728
+ '<table id="T__">'
715
729
' <thead>'
716
730
' <tr><th class="col_heading level0 col0" >0</th></tr>'
717
731
' </thead>'
718
732
' <tbody>'
719
- ' <tr><td class="data row0 col0 other-class" >1</td></tr>'
733
+ ' <tr><td class="data row0 col0 other-class" >1</td></tr>'
720
734
' </tbody>'
721
735
'</table>'
722
736
"""
@@ -736,7 +750,7 @@ def set_td_classes(self, classes: DataFrame) -> Styler:
736
750
737
751
def render (self , ** kwargs ) -> str :
738
752
"""
739
- Render the built up styles to HTML.
753
+ Render the ``Styler`` including all applied styles to HTML.
740
754
741
755
Parameters
742
756
----------
@@ -753,7 +767,7 @@ def render(self, **kwargs) -> str:
753
767
754
768
Notes
755
769
-----
756
- `` Styler`` objects have defined the ``_repr_html_`` method
770
+ Styler objects have defined the ``_repr_html_`` method
757
771
which automatically calls ``self.render()`` when it's the
758
772
last item in a Notebook cell. When calling ``Styler.render()``
759
773
directly, wrap the result in ``IPython.display.HTML`` to view
@@ -779,7 +793,7 @@ def render(self, **kwargs) -> str:
779
793
780
794
def _update_ctx (self , attrs : DataFrame ) -> None :
781
795
"""
782
- Update the state of the Styler for data cells.
796
+ Update the state of the `` Styler`` for data cells.
783
797
784
798
Collects a mapping of {index_label: [('<property>', '<value>'), ..]}.
785
799
@@ -839,7 +853,7 @@ def __deepcopy__(self, memo) -> Styler:
839
853
840
854
def clear (self ) -> None :
841
855
"""
842
- Reset the styler , removing any previously applied styles.
856
+ Reset the ``Styler`` , removing any previously applied styles.
843
857
844
858
Returns None.
845
859
"""
@@ -923,10 +937,11 @@ def apply(
923
937
Parameters
924
938
----------
925
939
func : function
926
- ``func`` should take a Series or DataFrame (depending
927
- on ``axis``), and return an object with the same shape.
928
- Must return a DataFrame with identical index and
929
- column labels or an ndarray with same shape as input when ``axis=None``.
940
+ ``func`` should take a Series if ``axis`` in [0,1] and return an object
941
+ of same length, also with identical index if the object is a Series.
942
+ ``func`` should take a DataFrame if ``axis`` is ``None`` and return either
943
+ an ndarray with the same shape or a DataFrame with identical columns and
944
+ index.
930
945
931
946
.. versionchanged:: 1.3.0
932
947
@@ -944,13 +959,16 @@ def apply(
944
959
-------
945
960
self : Styler
946
961
962
+ See Also
963
+ --------
964
+ Styler.where: Apply CSS-styles based on a conditional function elementwise.
965
+ Styler.applymap: Apply a CSS-styling function elementwise.
966
+
947
967
Notes
948
968
-----
949
- The output of ``func`` should be elements having CSS style as string or,
969
+ The elements of the output of ``func`` should be CSS styles as strings, in the
970
+ format 'attribute: value; attribute2: value2; ...' or,
950
971
if nothing is to be applied to that element, an empty string or ``None``.
951
- The output shape must match the input, i.e. if
952
- ``x`` is the input row, column, or table (depending on ``axis``),
953
- then ``func(x).shape == x.shape`` should be ``True``.
954
972
955
973
This is similar to ``DataFrame.apply``, except that ``axis=None``
956
974
applies the function to the entire DataFrame at once,
@@ -1001,13 +1019,14 @@ def applymap(self, func: Callable, subset=None, **kwargs) -> Styler:
1001
1019
1002
1020
See Also
1003
1021
--------
1004
- Styler.where: Updates the HTML representation with a style which is
1005
- selected in accordance with the return value of a function .
1022
+ Styler.where: Apply CSS-styles based on a conditional function elementwise.
1023
+ Styler.apply: Apply a CSS-styling function column-wise, row-wise, or table-wise .
1006
1024
1007
1025
Notes
1008
1026
-----
1009
- The output of ``func`` should be a CSS style as string or, if nothing is to be
1010
- applied, an empty string or ``None``.
1027
+ The elements of the output of ``func`` should be CSS styles as strings, in the
1028
+ format 'attribute: value; attribute2: value2; ...' or,
1029
+ if nothing is to be applied to that element, an empty string or ``None``.
1011
1030
1012
1031
Examples
1013
1032
--------
@@ -1030,7 +1049,7 @@ def where(
1030
1049
** kwargs ,
1031
1050
) -> Styler :
1032
1051
"""
1033
- Apply a function elementwise.
1052
+ Apply CSS-styles based on a conditional function elementwise.
1034
1053
1035
1054
Updates the HTML representation with a style which is
1036
1055
selected in accordance with the return value of a function.
@@ -1055,7 +1074,15 @@ def where(
1055
1074
1056
1075
See Also
1057
1076
--------
1058
- Styler.applymap: Updates the HTML representation with the result.
1077
+ Styler.applymap: Apply a CSS-styling function elementwise.
1078
+ Styler.apply: Apply a CSS-styling function column-wise, row-wise, or table-wise.
1079
+
1080
+ Examples
1081
+ --------
1082
+ >>> def cond(v):
1083
+ ... return v > 1 and v != 4
1084
+ >>> df = pd.DataFrame([[1, 2], [3, 4]])
1085
+ >>> df.style.where(cond, value='color:red;', other='font-size:2em;')
1059
1086
"""
1060
1087
if other is None :
1061
1088
other = ""
@@ -1092,10 +1119,9 @@ def set_precision(self, precision: int) -> Styler:
1092
1119
1093
1120
def set_table_attributes (self , attributes : str ) -> Styler :
1094
1121
"""
1095
- Set the table attributes.
1122
+ Set the table attributes added to the ``<table>`` HTML element .
1096
1123
1097
- These are the items that show up in the opening ``<table>`` tag
1098
- in addition to automatic (by default) id.
1124
+ These are items in addition to automatic (by default) ``id`` attribute.
1099
1125
1100
1126
Parameters
1101
1127
----------
@@ -1105,6 +1131,13 @@ def set_table_attributes(self, attributes: str) -> Styler:
1105
1131
-------
1106
1132
self : Styler
1107
1133
1134
+ See Also
1135
+ --------
1136
+ Styler.set_table_styles: Set the table styles included within the ``<style>``
1137
+ HTML element.
1138
+ Styler.set_td_classes: Set the DataFrame of strings added to the ``class``
1139
+ attribute of ``<td>`` HTML elements.
1140
+
1108
1141
Examples
1109
1142
--------
1110
1143
>>> df = pd.DataFrame(np.random.randn(10, 4))
@@ -1116,23 +1149,23 @@ def set_table_attributes(self, attributes: str) -> Styler:
1116
1149
1117
1150
def export (self ) -> List [Tuple [Callable , Tuple , Dict ]]:
1118
1151
"""
1119
- Export the styles to applied to the current Styler.
1152
+ Export the styles applied to the current `` Styler`` .
1120
1153
1121
- Can be applied to a second style with ``Styler.use``.
1154
+ Can be applied to a second Styler with ``Styler.use``.
1122
1155
1123
1156
Returns
1124
1157
-------
1125
1158
styles : list
1126
1159
1127
1160
See Also
1128
1161
--------
1129
- Styler.use: Set the styles on the current Styler.
1162
+ Styler.use: Set the styles on the current `` Styler`` .
1130
1163
"""
1131
1164
return self ._todo
1132
1165
1133
1166
def use (self , styles : List [Tuple [Callable , Tuple , Dict ]]) -> Styler :
1134
1167
"""
1135
- Set the styles on the current Styler.
1168
+ Set the styles on the current `` Styler`` .
1136
1169
1137
1170
Possibly uses styles from ``Styler.export``.
1138
1171
@@ -1147,14 +1180,14 @@ def use(self, styles: List[Tuple[Callable, Tuple, Dict]]) -> Styler:
1147
1180
1148
1181
See Also
1149
1182
--------
1150
- Styler.export : Export the styles to applied to the current Styler.
1183
+ Styler.export : Export the styles to applied to the current `` Styler`` .
1151
1184
"""
1152
1185
self ._todo .extend (styles )
1153
1186
return self
1154
1187
1155
1188
def set_uuid (self , uuid : str ) -> Styler :
1156
1189
"""
1157
- Set the uuid for a Styler .
1190
+ Set the uuid applied to ``id`` attributes of HTML elements .
1158
1191
1159
1192
Parameters
1160
1193
----------
@@ -1163,13 +1196,19 @@ def set_uuid(self, uuid: str) -> Styler:
1163
1196
Returns
1164
1197
-------
1165
1198
self : Styler
1199
+
1200
+ Notes
1201
+ -----
1202
+ Almost all HTML elements within the table, and including the ``<table>`` element
1203
+ are assigned ``id`` attributes. The format is ``T_uuid_<extra>`` where
1204
+ ``<extra>`` is typically a more specific identifier, such as ``row1_col2``.
1166
1205
"""
1167
1206
self .uuid = uuid
1168
1207
return self
1169
1208
1170
1209
def set_caption (self , caption : str ) -> Styler :
1171
1210
"""
1172
- Set the caption on a Styler .
1211
+ Set the text added to a ``<caption>`` HTML element .
1173
1212
1174
1213
Parameters
1175
1214
----------
@@ -1189,9 +1228,7 @@ def set_table_styles(
1189
1228
overwrite : bool = True ,
1190
1229
) -> Styler :
1191
1230
"""
1192
- Set the table styles on a Styler.
1193
-
1194
- These are placed in a ``<style>`` tag before the generated HTML table.
1231
+ Set the table styles included within the ``<style>`` HTML element.
1195
1232
1196
1233
This function can be used to style the entire table, columns, rows or
1197
1234
specific HTML selectors.
@@ -1232,6 +1269,13 @@ def set_table_styles(
1232
1269
-------
1233
1270
self : Styler
1234
1271
1272
+ See Also
1273
+ --------
1274
+ Styler.set_td_classes: Set the DataFrame of strings added to the ``class``
1275
+ attribute of ``<td>`` HTML elements.
1276
+ Styler.set_table_attributes: Set the table attributes added to the ``<table>``
1277
+ HTML element.
1278
+
1235
1279
Examples
1236
1280
--------
1237
1281
>>> df = pd.DataFrame(np.random.randn(10, 4),
@@ -1295,7 +1339,7 @@ def set_table_styles(
1295
1339
1296
1340
def set_na_rep (self , na_rep : str ) -> Styler :
1297
1341
"""
1298
- Set the missing data representation on a Styler.
1342
+ Set the missing data representation on a `` Styler`` .
1299
1343
1300
1344
.. versionadded:: 1.0.0
1301
1345
@@ -1505,7 +1549,8 @@ def css(rgba) -> str:
1505
1549
1506
1550
def set_properties (self , subset = None , ** kwargs ) -> Styler :
1507
1551
"""
1508
- Method to set one or more non-data dependent properties or each cell.
1552
+ Set defined CSS-properties to each ``<td>`` HTML element within the given
1553
+ subset.
1509
1554
1510
1555
Parameters
1511
1556
----------
@@ -1518,6 +1563,11 @@ def set_properties(self, subset=None, **kwargs) -> Styler:
1518
1563
-------
1519
1564
self : Styler
1520
1565
1566
+ Notes
1567
+ -----
1568
+ This is a convenience methods which wraps the :meth:`Styler.applymap` calling a
1569
+ function returning the CSS-properties independently of the data.
1570
+
1521
1571
Examples
1522
1572
--------
1523
1573
>>> df = pd.DataFrame(np.random.randn(10, 4))
@@ -1865,8 +1915,8 @@ def pipe(self, func: Callable, *args, **kwargs):
1865
1915
See Also
1866
1916
--------
1867
1917
DataFrame.pipe : Analogous method for DataFrame.
1868
- Styler.apply : Apply a function row -wise, column -wise, or table-wise to
1869
- modify the dataframe's styling .
1918
+ Styler.apply : Apply a CSS-styling function column -wise, row -wise, or
1919
+ table-wise .
1870
1920
1871
1921
Notes
1872
1922
-----
@@ -1915,7 +1965,7 @@ def pipe(self, func: Callable, *args, **kwargs):
1915
1965
class _Tooltips :
1916
1966
"""
1917
1967
An extension to ``Styler`` that allows for and manipulates tooltips on hover
1918
- of table data- cells in the HTML result.
1968
+ of ``<td>`` cells in the HTML result.
1919
1969
1920
1970
Parameters
1921
1971
----------
@@ -1924,7 +1974,7 @@ class _Tooltips:
1924
1974
css_props: list-like, default; see Notes
1925
1975
List of (attr, value) tuples defining properties of the CSS class.
1926
1976
tooltips: DataFrame, default empty
1927
- DataFrame of strings aligned with underlying `` Styler`` data for tooltip
1977
+ DataFrame of strings aligned with underlying Styler data for tooltip
1928
1978
display.
1929
1979
1930
1980
Notes
@@ -2025,7 +2075,7 @@ def _translate(self, styler_data: FrameOrSeriesUnion, uuid: str, d: Dict):
2025
2075
"""
2026
2076
Mutate the render dictionary to allow for tooltips:
2027
2077
2028
- - Add `<span>` HTML element to each data cells `display_value`. Ignores
2078
+ - Add `` <span>`` HTML element to each data cells `` display_value` `. Ignores
2029
2079
headers.
2030
2080
- Add table level CSS styles to control pseudo classes.
2031
2081
0 commit comments