Skip to content

DOC: update style.ipynb user guide for recent enhancements #41013

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Apr 21, 2021
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
e0c64f9
add the highlight quantile function
attack68 Apr 13, 2021
670135c
add binary images
attack68 Apr 13, 2021
cd82788
add tests
attack68 Apr 13, 2021
a9d769b
Merge remote-tracking branch 'upstream/master' into highlight_quantile
attack68 Apr 14, 2021
b4e08f3
See also links
attack68 Apr 14, 2021
b4d346f
doc fix
attack68 Apr 14, 2021
2487988
mypy fix
attack68 Apr 14, 2021
c083818
Merge remote-tracking branch 'upstream/master' into highlight_quantile
attack68 Apr 14, 2021
8058d72
Merge remote-tracking branch 'upstream/master' into highlight_quantile
attack68 Apr 15, 2021
73ec52d
switch to DataFrame.quantile
attack68 Apr 16, 2021
fc60ca6
switch to DataFrame.quantile and Series.quantile
attack68 Apr 16, 2021
36acb98
leave only str dtype in omissions
attack68 Apr 16, 2021
2752faf
Merge remote-tracking branch 'upstream/master' into highlight_quantile
attack68 Apr 16, 2021
d581866
Merge remote-tracking branch 'upstream/master' into highlight_quantile
attack68 Apr 16, 2021
bf74b45
update Styler user guide for recent additions
attack68 Apr 17, 2021
dfb30ac
Merge remote-tracking branch 'upstream/master' into highlight_quantile
attack68 Apr 18, 2021
c82eac9
Merge branch 'highlight_quantile' into builtsin_user_guide_update
attack68 Apr 18, 2021
f46d73c
Merge remote-tracking branch 'upstream/master' into highlight_quantile
attack68 Apr 20, 2021
3efb783
Merge branch 'highlight_quantile' into builtsin_user_guide_update
attack68 Apr 20, 2021
672b484
Merge remote-tracking branch 'upstream/master' into builtsin_user_gui…
attack68 Apr 21, 2021
d86f702
fix doc links
attack68 Apr 21, 2021
47f0962
fix doc links
attack68 Apr 21, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 61 additions & 16 deletions doc/source/user_guide/style.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,30 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"We expect certain styling functions to be common enough that we've included a few \"built-in\" to the `Styler`, so you don't have to write them yourself."
"Some styling functions are common enough that we've \"built them in\" to the `Styler`, so you don't have to write them and apply them yourself. The current list of such functions is:\n",
"\n",
" - [.highlight_null][nullfunc]: for use with identifying missing data. \n",
" - [.highlight_min][minfunc] and [.highlight_max][maxfunc]: for use with identifying extremeties in data.\n",
" - [.highlight_between][betweenfunc] and [.highlight_quantile][quantilefunc]: for use with identifying classes within data.\n",
" - [.background_gradient][bgfunc]: a flexible method for highlighting cells based or their, or other, values on a numeric scale.\n",
" - [.bar][barfunc]: to display mini-charts within cell backgrounds.\n",
" \n",
"The individual documentation on each function often gives more examples of their arguments.\n",
"\n",
"[nullfunc]: ../reference/api/pandas.io.formats.style.Styler.highlight_null.rst\n",
"[minfunc]: ../reference/api/pandas.io.formats.style.Styler.highlight_min.rst\n",
"[maxfunc]: ../reference/api/pandas.io.formats.style.Styler.highlight_max.rst\n",
"[betweenfunc]: ../reference/api/pandas.io.formats.style.Styler.highlight_between.rst\n",
"[quantilefunc]: ../reference/api/pandas.io.formats.style.Styler.highlight_quantile.rst\n",
"[bgfunc]: ../reference/api/pandas.io.formats.style.Styler.background_gradient.rst\n",
"[barfunc]: ../reference/api/pandas.io.formats.style.Styler.bar.rst"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Highlight Null"
]
},
{
Expand All @@ -1017,14 +1040,14 @@
"source": [
"df2.iloc[0,2] = np.nan\n",
"df2.iloc[4,3] = np.nan\n",
"df2.loc[:4].style.highlight_null(null_color='red')"
"df2.loc[:4].style.highlight_null(null_color='yellow')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can create \"heatmaps\" with the `background_gradient` method. These require matplotlib, and we'll use [Seaborn](https://stanford.edu/~mwaskom/software/seaborn/) to get a nice colormap."
"### Highlight Min or Max"
]
},
{
Expand All @@ -1033,17 +1056,15 @@
"metadata": {},
"outputs": [],
"source": [
"import seaborn as sns\n",
"cm = sns.light_palette(\"green\", as_cmap=True)\n",
"\n",
"df2.style.background_gradient(cmap=cm)"
"df2.loc[:4].style.highlight_max(axis=1, props='color:white; font-weight:bold; background-color:darkblue;')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"`Styler.background_gradient` takes the keyword arguments `low` and `high`. Roughly speaking these extend the range of your data by `low` and `high` percent so that when we convert the colors, the colormap's entire range isn't used. This is useful so that you can actually read the text still."
"### Highlight Between\n",
"This method accepts ranges as float, or NumPy arrays or Series provided the indexes match."
]
},
{
Expand All @@ -1052,8 +1073,16 @@
"metadata": {},
"outputs": [],
"source": [
"# Uses the full color range\n",
"df2.loc[:4].style.background_gradient(cmap='viridis')"
"left = pd.Series([1.0, 0.0, 1.0], index=[\"A\", \"B\", \"D\"])\n",
"df2.loc[:4].style.highlight_between(left=left, right=1.5, axis=1, props='color:white; background-color:purple;')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Highlight Quantile\n",
"Useful for detecting the highest or lowest percentile values"
]
},
{
Expand All @@ -1062,17 +1091,21 @@
"metadata": {},
"outputs": [],
"source": [
"# Compress the color range\n",
"df2.loc[:4].style\\\n",
" .background_gradient(cmap='viridis', low=.5, high=0)\\\n",
" .highlight_null('red')"
"df2.loc[:4].style.highlight_quantile(q_left=0.85, axis=None, color='yellow')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Background Gradient"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"There's also `.highlight_min` and `.highlight_max`, which is almost identical to the user defined version we created above, and also a `.highlight_null` method. "
"You can create \"heatmaps\" with the `background_gradient` method. These require matplotlib, and we'll use [Seaborn](https://stanford.edu/~mwaskom/software/seaborn/) to get a nice colormap."
]
},
{
Expand All @@ -1081,7 +1114,19 @@
"metadata": {},
"outputs": [],
"source": [
"df2.loc[:4].style.highlight_max(axis=0)"
"import seaborn as sns\n",
"cm = sns.light_palette(\"green\", as_cmap=True)\n",
"\n",
"df2.style.background_gradient(cmap=cm)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[.background_gradient][bgfunc] has a number of keyword arguments to customise the gradients and colors. See its documentation.\n",
"\n",
"[bgfunc]: ../reference/api/pandas.io.formats.style.Styler.background_gradient.rst"
]
},
{
Expand Down