@@ -1307,6 +1307,21 @@ def to_html(
1307
1307
See Also
1308
1308
--------
1309
1309
DataFrame.to_html: Write a DataFrame to a file, buffer or string in HTML format.
1310
+
1311
+ Examples
1312
+ --------
1313
+ >>> df = pd.DataFrame({'A': [1, 2], 'B': [3, 4]})
1314
+ >>> print(df.style.to_html()) # doctest: +SKIP
1315
+ <style type="text/css">
1316
+ </style>
1317
+ <table id="T_1e78e">
1318
+ <thead>
1319
+ <tr>
1320
+ <th class="blank level0" > </th>
1321
+ <th id="T_1e78e_level0_col0" class="col_heading level0 col0" >A</th>
1322
+ <th id="T_1e78e_level0_col1" class="col_heading level0 col1" >B</th>
1323
+ </tr>
1324
+ ...
1310
1325
"""
1311
1326
obj = self ._copy (deepcopy = True ) # manipulate table_styles on obj, not self
1312
1327
@@ -1419,6 +1434,12 @@ def to_string(
1419
1434
-------
1420
1435
str or None
1421
1436
If `buf` is None, returns the result as a string. Otherwise returns `None`.
1437
+
1438
+ Examples
1439
+ --------
1440
+ >>> df = pd.DataFrame({'A': [1, 2], 'B': [3, 4]})
1441
+ >>> df.style.to_string()
1442
+ ' A B\\ n0 1 3\\ n1 2 4\\ n'
1422
1443
"""
1423
1444
obj = self ._copy (deepcopy = True )
1424
1445
@@ -1650,6 +1671,21 @@ def clear(self) -> None:
1650
1671
Reset the ``Styler``, removing any previously applied styles.
1651
1672
1652
1673
Returns None.
1674
+
1675
+ Examples
1676
+ --------
1677
+ >>> df = pd.DataFrame({'A': [1, 2], 'B': [3, np.nan]})
1678
+
1679
+ After any added style:
1680
+
1681
+ >>> df.style.highlight_null(color='yellow') # doctest: +SKIP
1682
+
1683
+ Remove it with:
1684
+
1685
+ >>> df.style.clear() # doctest: +SKIP
1686
+
1687
+ Please see:
1688
+ `Table Visualization <../../user_guide/style.ipynb>`_ for more examples.
1653
1689
"""
1654
1690
# create default GH 40675
1655
1691
clean_copy = Styler (self .data , uuid = self .uuid )
@@ -2257,6 +2293,22 @@ def set_uuid(self, uuid: str) -> Styler:
2257
2293
Almost all HTML elements within the table, and including the ``<table>`` element
2258
2294
are assigned ``id`` attributes. The format is ``T_uuid_<extra>`` where
2259
2295
``<extra>`` is typically a more specific identifier, such as ``row1_col2``.
2296
+
2297
+ Examples
2298
+ --------
2299
+ >>> df = pd.DataFrame([[1, 2], [3, 4]], index=['A', 'B'], columns=['c1', 'c2'])
2300
+
2301
+ You can get the `id` attributes with the following:
2302
+
2303
+ >>> print((df).style.to_html()) # doctest: +SKIP
2304
+
2305
+ To add a title to column `c1`, its `id` is T_20a7d_level0_col0:
2306
+
2307
+ >>> df.style.set_uuid("T_20a7d_level0_col0")
2308
+ ... .set_caption("Test") # doctest: +SKIP
2309
+
2310
+ Please see:
2311
+ `Table visualization <../../user_guide/style.ipynb>`_ for more examples.
2260
2312
"""
2261
2313
self .uuid = uuid
2262
2314
return self
@@ -2275,6 +2327,14 @@ def set_caption(self, caption: str | tuple | list) -> Styler:
2275
2327
Returns
2276
2328
-------
2277
2329
Styler
2330
+
2331
+ Examples
2332
+ --------
2333
+ >>> df = pd.DataFrame({'A': [1, 2], 'B': [3, 4]})
2334
+ >>> df.style.set_caption("test") # doctest: +SKIP
2335
+
2336
+ Please see:
2337
+ `Table Visualization <../../user_guide/style.ipynb>`_ for more examples.
2278
2338
"""
2279
2339
msg = "`caption` must be either a string or 2-tuple of strings."
2280
2340
if isinstance (caption , (list , tuple )):
@@ -2323,6 +2383,14 @@ def set_sticky(
2323
2383
- `styler.set_sticky(axis="columns").hide(axis="columns")`
2324
2384
2325
2385
may produce strange behaviour due to CSS controls with missing elements.
2386
+
2387
+ Examples
2388
+ --------
2389
+ >>> df = pd.DataFrame({'A': [1, 2], 'B': [3, 4]})
2390
+ >>> df.style.set_sticky(axis="index") # doctest: +SKIP
2391
+
2392
+ Please see:
2393
+ `Table Visualization <../../user_guide/style.ipynb>`_ for more examples.
2326
2394
"""
2327
2395
axis = self .data ._get_axis_number (axis )
2328
2396
obj = self .data .index if axis == 0 else self .data .columns
@@ -3073,6 +3141,11 @@ def bar( # pylint: disable=disallowed-name
3073
3141
This section of the user guide:
3074
3142
`Table Visualization <../../user_guide/style.ipynb>`_ gives
3075
3143
a number of examples for different settings and color coordination.
3144
+
3145
+ Examples
3146
+ --------
3147
+ >>> df = pd.DataFrame({'A': [1, 2, 3, 4], 'B': [3, 4, 5, 6]})
3148
+ >>> df.style.bar(subset=['A'], color='gray') # doctest: +SKIP
3076
3149
"""
3077
3150
if color is None and cmap is None :
3078
3151
color = "#d65f5f"
@@ -3147,6 +3220,14 @@ def highlight_null(
3147
3220
Styler.highlight_min: Highlight the minimum with a style.
3148
3221
Styler.highlight_between: Highlight a defined range with a style.
3149
3222
Styler.highlight_quantile: Highlight values defined by a quantile with a style.
3223
+
3224
+ Examples
3225
+ --------
3226
+ >>> df = pd.DataFrame({'A': [1, 2], 'B': [3, np.nan]})
3227
+ >>> df.style.highlight_null(color='yellow') # doctest: +SKIP
3228
+
3229
+ Please see:
3230
+ `Table Visualization <../../user_guide/style.ipynb>`_ for more examples.
3150
3231
"""
3151
3232
3152
3233
def f (data : DataFrame , props : str ) -> np .ndarray :
@@ -3193,6 +3274,14 @@ def highlight_max(
3193
3274
Styler.highlight_min: Highlight the minimum with a style.
3194
3275
Styler.highlight_between: Highlight a defined range with a style.
3195
3276
Styler.highlight_quantile: Highlight values defined by a quantile with a style.
3277
+
3278
+ Examples
3279
+ --------
3280
+ >>> df = pd.DataFrame({'A': [2, 1], 'B': [3, 4]})
3281
+ >>> df.style.highlight_max(color='yellow') # doctest: +SKIP
3282
+
3283
+ Please see:
3284
+ `Table Visualization <../../user_guide/style.ipynb>`_ for more examples.
3196
3285
"""
3197
3286
3198
3287
if props is None :
@@ -3241,6 +3330,14 @@ def highlight_min(
3241
3330
Styler.highlight_max: Highlight the maximum with a style.
3242
3331
Styler.highlight_between: Highlight a defined range with a style.
3243
3332
Styler.highlight_quantile: Highlight values defined by a quantile with a style.
3333
+
3334
+ Examples
3335
+ --------
3336
+ >>> df = pd.DataFrame({'A': [2, 1], 'B': [3, 4]})
3337
+ >>> df.style.highlight_min(color='yellow') # doctest: +SKIP
3338
+
3339
+ Please see:
3340
+ `Table Visualization <../../user_guide/style.ipynb>`_ for more examples.
3244
3341
"""
3245
3342
3246
3343
if props is None :
0 commit comments