You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"In this case the input is a `Series`, one column at a time.\n",
396
+
"In this case the input is a `Series`, one column (or row) at a time.\n",
392
397
"Notice that the output shape of `highlight_max` matches the input shape, an array with `len(s)` items."
393
398
]
394
399
},
@@ -406,8 +411,8 @@
406
411
"outputs": [],
407
412
"source": [
408
413
"def compare_col(s, comparator=None):\n",
409
-
"attr = 'background-color: #00BFFF;'\n",
410
-
" return np.where(s < comparator, attr, '')"
414
+
"css = 'background-color: #00BFFF;'\n",
415
+
" return np.where(s < comparator, css, None)"
411
416
]
412
417
},
413
418
{
@@ -442,41 +447,12 @@
442
447
"cell_type": "markdown",
443
448
"metadata": {},
444
449
"source": [
445
-
"Above we used `Styler.apply` to pass in each column one at a time.\n",
450
+
"Above we used `Styler.apply` to pass in each column (or row) one at a time.\n",
446
451
"\n",
447
452
"<span style=\"background-color: #DEDEBE\">*Debugging Tip*: If you're having trouble writing your style function, try just passing it into <code style=\"background-color: #DEDEBE\">DataFrame.apply</code>. Internally, <code style=\"background-color: #DEDEBE\">Styler.apply</code> uses <code style=\"background-color: #DEDEBE\">DataFrame.apply</code> so the result should be the same.</span>\n",
448
453
"\n",
449
454
"What if you wanted to highlight just the maximum value in the entire table?\n",
450
-
"Use `.apply(function, axis=None)` to indicate that your function wants the entire table, not one column or row at a time. Let's try that next.\n",
451
-
"\n",
452
-
"We'll rewrite our `highlight-max` to handle either Series (from `.apply(axis=0 or 1)`) or DataFrames (from `.apply(axis=None)`). We'll also allow the color to be adjustable, to demonstrate that `.apply`, and `.applymap` pass along keyword arguments."
453
-
]
454
-
},
455
-
{
456
-
"cell_type": "code",
457
-
"execution_count": null,
458
-
"metadata": {},
459
-
"outputs": [],
460
-
"source": [
461
-
"def highlight_max(data, color='yellow'):\n",
462
-
" '''\n",
463
-
" highlight the maximum in a Series or DataFrame\n",
464
-
" '''\n",
465
-
" attr = 'background-color: {}'.format(color)\n",
466
-
" if data.ndim == 1: # Series from .apply(axis=0) or axis=1\n",
"When using ``Styler.apply(func, axis=None)``, the function must return a DataFrame with the same index and column labels."
455
+
"Use `.apply(function, axis=None)` to indicate that your function wants the entire table, not one column or row at a time. In this case the return must be a DataFrame or ndarray of the same shape as the input. Let's try that next. "
Copy file name to clipboardExpand all lines: doc/source/whatsnew/v1.3.0.rst
+2-1Lines changed: 2 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -53,8 +53,9 @@ Other enhancements
53
53
- :meth:`DataFrame.apply` can now accept non-callable DataFrame properties as strings, e.g. ``df.apply("size")``, which was already the case for :meth:`Series.apply` (:issue:`39116`)
54
54
- :meth:`Series.apply` can now accept list-like or dictionary-like arguments that aren't lists or dictionaries, e.g. ``ser.apply(np.array(["sum", "mean"]))``, which was already the case for :meth:`DataFrame.apply` (:issue:`39140`)
55
55
- :meth:`DataFrame.plot.scatter` can now accept a categorical column as the argument to ``c`` (:issue:`12380`, :issue:`31357`)
56
-
- :meth:`.Styler.set_tooltips` allows on hover tooltips to be added to styled HTML dataframes (:issue:`35643`)
56
+
- :meth:`.Styler.set_tooltips` allows on hover tooltips to be added to styled HTML dataframes (:issue:`35643`, :issue:`21266`, :issue:`39317`)
57
57
- :meth:`.Styler.set_tooltips_class` and :meth:`.Styler.set_table_styles` amended to optionally allow certain css-string input arguments (:issue:`39564`)
58
+
- :meth:`.Styler.apply` now more consistently accepts ndarray function returns, i.e. in all cases for ``axis`` is ``0, 1 or None``. (:issue:`39359`)
58
59
- :meth:`Series.loc.__getitem__` and :meth:`Series.loc.__setitem__` with :class:`MultiIndex` now raising helpful error message when indexer has too many dimensions (:issue:`35349`)
59
60
- :meth:`pandas.read_stata` and :class:`StataReader` support reading data from compressed files.
0 commit comments