From eb72fa4e19455142a41be9a0b11dfb89799ecddb Mon Sep 17 00:00:00 2001 From: bang128 <71242233+bang128@users.noreply.github.com> Date: Tue, 13 Dec 2022 02:30:33 -0800 Subject: [PATCH 01/11] Deprecate is_object --- data.csv | 4 + data.json | 1 + doc/source/user_guide/style.nbconvert.ipynb | 16030 ++++++++++++++++++ doc/source/whatsnew/v2.0.0.rst | 1 + pandas/core/indexes/base.py | 26 +- pandas/tests/indexes/common.py | 6 + pandas/tests/indexing/test_indexing.py | 5 +- 7 files changed, 16063 insertions(+), 10 deletions(-) create mode 100644 data.csv create mode 100644 data.json create mode 100644 doc/source/user_guide/style.nbconvert.ipynb diff --git a/data.csv b/data.csv new file mode 100644 index 0000000000000..436430591f70f --- /dev/null +++ b/data.csv @@ -0,0 +1,4 @@ +,,,1,2 +x,y,z,, +1,3,5,, +2,4,6,, diff --git a/data.json b/data.json new file mode 100644 index 0000000000000..ae33afb2057e3 --- /dev/null +++ b/data.json @@ -0,0 +1 @@ +"{\"schema\":{\"fields\":[{\"name\":\"index\",\"type\":\"integer\"},{\"name\":\"a\",\"type\":\"number\"},{\"name\":\"b\",\"type\":\"number\"}],\"primaryKey\":[\"index\"],\"pandas_version\":\"1.4.0\"},\"data\":[{\"index\":0,\"a\":{\"imag\":2.0,\"real\":1.0},\"b\":{\"imag\":6.0,\"real\":5.0}},{\"index\":1,\"a\":{\"imag\":4.0,\"real\":3.0},\"b\":{\"imag\":8.0,\"real\":7.0}}]}" \ No newline at end of file diff --git a/doc/source/user_guide/style.nbconvert.ipynb b/doc/source/user_guide/style.nbconvert.ipynb new file mode 100644 index 0000000000000..3935f0c49f7fe --- /dev/null +++ b/doc/source/user_guide/style.nbconvert.ipynb @@ -0,0 +1,16030 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Table Visualization\n", + "\n", + "This section demonstrates visualization of tabular data using the [Styler][styler]\n", + "class. For information on visualization with charting please see [Chart Visualization][viz]. This document is written as a Jupyter Notebook, and can be viewed or downloaded [here][download].\n", + "\n", + "[styler]: ../reference/api/pandas.io.formats.style.Styler.rst\n", + "[viz]: visualization.rst\n", + "[download]: https://nbviewer.ipython.org/github/pandas-dev/pandas/blob/main/doc/source/user_guide/style.ipynb" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Styler Object and HTML \n", + "\n", + "Styling should be performed after the data in a DataFrame has been processed. The [Styler][styler] creates an HTML `` and leverages CSS styling language to manipulate many parameters including colors, fonts, borders, background, etc. See [here][w3schools] for more information on styling HTML tables. This allows a lot of flexibility out of the box, and even enables web developers to integrate DataFrames into their exiting user interface designs.\n", + " \n", + "The `DataFrame.style` attribute is a property that returns a [Styler][styler] object. It has a `_repr_html_` method defined on it so they are rendered automatically in Jupyter Notebook.\n", + "\n", + "[styler]: ../reference/api/pandas.io.formats.style.Styler.rst\n", + "[w3schools]: https://www.w3schools.com/html/html_tables.asp" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:37.132240Z", + "iopub.status.busy": "2023-01-25T14:32:37.131849Z", + "iopub.status.idle": "2023-01-25T14:32:37.432043Z", + "shell.execute_reply": "2023-01-25T14:32:37.431329Z" + }, + "nbsphinx": "hidden" + }, + "outputs": [], + "source": [ + "import matplotlib.pyplot\n", + "# We have this here to trigger matplotlib's font cache stuff.\n", + "# This cell is hidden from the output" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:37.437370Z", + "iopub.status.busy": "2023-01-25T14:32:37.436979Z", + "iopub.status.idle": "2023-01-25T14:32:37.735979Z", + "shell.execute_reply": "2023-01-25T14:32:37.735663Z" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "
\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Model:Decision TreeRegressionRandom
Predicted:TumourNon-TumourTumourNon-TumourTumourNon-Tumour
Actual Label:      
Tumour (Positive)38.0000002.00000018.00000022.00000021nan
Non-Tumour (Negative)19.000000439.0000006.000000452.000000226232.000000
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import pandas as pd\n", + "import numpy as np\n", + "import matplotlib as mpl\n", + "\n", + "df = pd.DataFrame([[38.0, 2.0, 18.0, 22.0, 21, np.nan],[19, 439, 6, 452, 226,232]], \n", + " index=pd.Index(['Tumour (Positive)', 'Non-Tumour (Negative)'], name='Actual Label:'), \n", + " columns=pd.MultiIndex.from_product([['Decision Tree', 'Regression', 'Random'],['Tumour', 'Non-Tumour']], names=['Model:', 'Predicted:']))\n", + "df.style" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The above output looks very similar to the standard DataFrame HTML representation. But the HTML here has already attached some CSS classes to each cell, even if we haven't yet created any styles. We can view these by calling the [.to_html()][tohtml] method, which returns the raw HTML as string, which is useful for further processing or adding to a file - read on in [More about CSS and HTML](#More-About-CSS-and-HTML). Below we will show how we can use these to format the DataFrame to be more communicative. For example how we can build `s`:\n", + "\n", + "[tohtml]: ../reference/api/pandas.io.formats.style.Styler.to_html.rst" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:37.750620Z", + "iopub.status.busy": "2023-01-25T14:32:37.750423Z", + "iopub.status.idle": "2023-01-25T14:32:37.766061Z", + "shell.execute_reply": "2023-01-25T14:32:37.765810Z" + }, + "nbsphinx": "hidden" + }, + "outputs": [], + "source": [ + "# Hidden cell to just create the below example: code is covered throughout the guide.\n", + "s = df.style\\\n", + " .hide([('Random', 'Tumour'), ('Random', 'Non-Tumour')], axis='columns')\\\n", + " .format('{:.0f}')\\\n", + " .set_table_styles([{\n", + " 'selector': '',\n", + " 'props': 'border-collapse: separate;'\n", + " },{\n", + " 'selector': 'caption',\n", + " 'props': 'caption-side: bottom; font-size:1.3em;'\n", + " },{\n", + " 'selector': '.index_name',\n", + " 'props': 'font-style: italic; color: darkgrey; font-weight:normal;'\n", + " },{\n", + " 'selector': 'th:not(.index_name)',\n", + " 'props': 'background-color: #000066; color: white;'\n", + " },{\n", + " 'selector': 'th.col_heading',\n", + " 'props': 'text-align: center;'\n", + " },{\n", + " 'selector': 'th.col_heading.level0',\n", + " 'props': 'font-size: 1.5em;'\n", + " },{\n", + " 'selector': 'th.col2',\n", + " 'props': 'border-left: 1px solid white;'\n", + " },{\n", + " 'selector': '.col2',\n", + " 'props': 'border-left: 1px solid #000066;'\n", + " },{\n", + " 'selector': 'td',\n", + " 'props': 'text-align: center; font-weight:bold;'\n", + " },{\n", + " 'selector': '.true',\n", + " 'props': 'background-color: #e6ffe6;'\n", + " },{\n", + " 'selector': '.false',\n", + " 'props': 'background-color: #ffe6e6;'\n", + " },{\n", + " 'selector': '.border-red',\n", + " 'props': 'border: 2px dashed red;'\n", + " },{\n", + " 'selector': '.border-green',\n", + " 'props': 'border: 2px dashed green;'\n", + " },{\n", + " 'selector': 'td:hover',\n", + " 'props': 'background-color: #ffffb3;'\n", + " }])\\\n", + " .set_td_classes(pd.DataFrame([['true border-green', 'false', 'true', 'false border-red', '', ''],\n", + " ['false', 'true', 'false', 'true', '', '']], \n", + " index=df.index, columns=df.columns))\\\n", + " .set_caption(\"Confusion matrix for multiple cancer prediction models.\")\\\n", + " .set_tooltips(pd.DataFrame([['This model has a very strong true positive rate', '', '', \"This model's total number of false negatives is too high\", '', ''],\n", + " ['', '', '', '', '', '']], \n", + " index=df.index, columns=df.columns),\n", + " css_class='pd-tt', props=\n", + " 'visibility: hidden; position: absolute; z-index: 1; border: 1px solid #000066;'\n", + " 'background-color: white; color: #000066; font-size: 0.8em;' \n", + " 'transform: translate(0px, -24px); padding: 0.6em; border-radius: 0.5em;')\n" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:37.767599Z", + "iopub.status.busy": "2023-01-25T14:32:37.767511Z", + "iopub.status.idle": "2023-01-25T14:32:37.779781Z", + "shell.execute_reply": "2023-01-25T14:32:37.779503Z" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Confusion matrix for multiple cancer prediction models.
Model:Decision TreeRegression
Predicted:TumourNon-TumourTumourNon-Tumour
Actual Label:    
Tumour (Positive)3821822
Non-Tumour (Negative)194396452
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "s" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Formatting the Display\n", + "\n", + "### Formatting Values\n", + "\n", + "Before adding styles it is useful to show that the [Styler][styler] can distinguish the *display* value from the *actual* value, in both datavalues and index or columns headers. To control the display value, the text is printed in each cell as string, and we can use the [.format()][formatfunc] and [.format_index()][formatfuncindex] methods to manipulate this according to a [format spec string][format] or a callable that takes a single value and returns a string. It is possible to define this for the whole table, or index, or for individual columns, or MultiIndex levels. \n", + "\n", + "Additionally, the format function has a **precision** argument to specifically help formatting floats, as well as **decimal** and **thousands** separators to support other locales, an **na_rep** argument to display missing data, and an **escape** argument to help displaying safe-HTML or safe-LaTeX. The default formatter is configured to adopt pandas' `styler.format.precision` option, controllable using `with pd.option_context('format.precision', 2):` \n", + "\n", + "[styler]: ../reference/api/pandas.io.formats.style.Styler.rst\n", + "[format]: https://docs.python.org/3/library/string.html#format-specification-mini-language\n", + "[formatfunc]: ../reference/api/pandas.io.formats.style.Styler.format.rst\n", + "[formatfuncindex]: ../reference/api/pandas.io.formats.style.Styler.format_index.rst" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:37.781543Z", + "iopub.status.busy": "2023-01-25T14:32:37.781424Z", + "iopub.status.idle": "2023-01-25T14:32:37.794309Z", + "shell.execute_reply": "2023-01-25T14:32:37.794065Z" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Model:Decision TreeRegressionRandom
Predicted:TumourNon-TumourTumourNon-TumourTumourNon-Tumour
Actual Label:      
Tumour (Positive)38.00218$ -22 000 000.021MISSING
Non-Tumour (Negative)19.004396$ -452 000 000.0226232
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.style.format(precision=0, na_rep='MISSING', thousands=\" \",\n", + " formatter={('Decision Tree', 'Tumour'): \"{:.2f}\",\n", + " ('Regression', 'Non-Tumour'): lambda x: \"$ {:,.1f}\".format(x*-1e6)\n", + " })" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Using Styler to manipulate the display is a useful feature because maintaining the indexing and datavalues for other purposes gives greater control. You do not have to overwrite your DataFrame to display it how you like. Here is an example of using the formatting functions whilst still relying on the underlying data for indexing and calculations." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:37.795897Z", + "iopub.status.busy": "2023-01-25T14:32:37.795790Z", + "iopub.status.idle": "2023-01-25T14:32:37.811010Z", + "shell.execute_reply": "2023-01-25T14:32:37.810750Z" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
TokyoBeijing
2021-01-010.6729061.168244
2021-01-021.9689161.244091
2021-01-030.2062750.542097
2021-01-041.4706160.681337
2021-01-051.4494781.433289
2021-01-061.1414244.320723
2021-01-073.0747441.239495
2021-01-081.6812944.571259
2021-01-093.0949600.967787
2021-01-103.3456151.779296
\n", + "
" + ], + "text/plain": [ + " Tokyo Beijing\n", + "2021-01-01 0.672906 1.168244\n", + "2021-01-02 1.968916 1.244091\n", + "2021-01-03 0.206275 0.542097\n", + "2021-01-04 1.470616 0.681337\n", + "2021-01-05 1.449478 1.433289\n", + "2021-01-06 1.141424 4.320723\n", + "2021-01-07 3.074744 1.239495\n", + "2021-01-08 1.681294 4.571259\n", + "2021-01-09 3.094960 0.967787\n", + "2021-01-10 3.345615 1.779296" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "weather_df = pd.DataFrame(np.random.rand(10,2)*5, \n", + " index=pd.date_range(start=\"2021-01-01\", periods=10),\n", + " columns=[\"Tokyo\", \"Beijing\"])\n", + "\n", + "def rain_condition(v): \n", + " if v < 1.75:\n", + " return \"Dry\"\n", + " elif v < 2.75:\n", + " return \"Rain\"\n", + " return \"Heavy Rain\"\n", + "\n", + "def make_pretty(styler):\n", + " styler.set_caption(\"Weather Conditions\")\n", + " styler.format(rain_condition)\n", + " styler.format_index(lambda v: v.strftime(\"%A\"))\n", + " styler.background_gradient(axis=None, vmin=1, vmax=5, cmap=\"YlGnBu\")\n", + " return styler\n", + "\n", + "weather_df" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:37.812485Z", + "iopub.status.busy": "2023-01-25T14:32:37.812374Z", + "iopub.status.idle": "2023-01-25T14:32:37.825922Z", + "shell.execute_reply": "2023-01-25T14:32:37.825657Z" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Weather Conditions
 TokyoBeijing
MondayDryDry
TuesdayDryDry
WednesdayDryHeavy Rain
ThursdayHeavy RainDry
FridayDryHeavy Rain
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "weather_df.loc[\"2021-01-04\":\"2021-01-08\"].style.pipe(make_pretty)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Hiding Data\n", + "\n", + "The index and column headers can be completely hidden, as well subselecting rows or columns that one wishes to exclude. Both these options are performed using the same methods.\n", + "\n", + "The index can be hidden from rendering by calling [.hide()][hideidx] without any arguments, which might be useful if your index is integer based. Similarly column headers can be hidden by calling [.hide(axis=\"columns\")][hideidx] without any further arguments.\n", + "\n", + "Specific rows or columns can be hidden from rendering by calling the same [.hide()][hideidx] method and passing in a row/column label, a list-like or a slice of row/column labels to for the ``subset`` argument.\n", + "\n", + "Hiding does not change the integer arrangement of CSS classes, e.g. hiding the first two columns of a DataFrame means the column class indexing will still start at `col2`, since `col0` and `col1` are simply ignored.\n", + "\n", + "We can update our `Styler` object from before to hide some data and format the values.\n", + "\n", + "[hideidx]: ../reference/api/pandas.io.formats.style.Styler.hide.rst" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:37.827473Z", + "iopub.status.busy": "2023-01-25T14:32:37.827387Z", + "iopub.status.idle": "2023-01-25T14:32:37.840226Z", + "shell.execute_reply": "2023-01-25T14:32:37.839967Z" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Model:Decision TreeRegression
Predicted:TumourNon-TumourTumourNon-Tumour
Actual Label:    
Tumour (Positive)3821822
Non-Tumour (Negative)194396452
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "s = df.style.format('{:.0f}').hide([('Random', 'Tumour'), ('Random', 'Non-Tumour')], axis=\"columns\")\n", + "s" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:37.841727Z", + "iopub.status.busy": "2023-01-25T14:32:37.841642Z", + "iopub.status.idle": "2023-01-25T14:32:37.852938Z", + "shell.execute_reply": "2023-01-25T14:32:37.852697Z" + }, + "nbsphinx": "hidden" + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Model:Decision TreeRegression
Predicted:TumourNon-TumourTumourNon-Tumour
Actual Label:    
Tumour (Positive)3821822
Non-Tumour (Negative)194396452
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Hidden cell to avoid CSS clashes and latter code upcoding previous formatting \n", + "s.set_uuid('after_hide')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Methods to Add Styles\n", + "\n", + "There are **3 primary methods of adding custom CSS styles** to [Styler][styler]:\n", + "\n", + "- Using [.set_table_styles()][table] to control broader areas of the table with specified internal CSS. Although table styles allow the flexibility to add CSS selectors and properties controlling all individual parts of the table, they are unwieldy for individual cell specifications. Also, note that table styles cannot be exported to Excel. \n", + "- Using [.set_td_classes()][td_class] to directly link either external CSS classes to your data cells or link the internal CSS classes created by [.set_table_styles()][table]. See [here](#Setting-Classes-and-Linking-to-External-CSS). These cannot be used on column header rows or indexes, and also won't export to Excel. \n", + "- Using the [.apply()][apply] and [.applymap()][applymap] functions to add direct internal CSS to specific data cells. See [here](#Styler-Functions). As of v1.4.0 there are also methods that work directly on column header rows or indexes; [.apply_index()][applyindex] and [.applymap_index()][applymapindex]. Note that only these methods add styles that will export to Excel. These methods work in a similar way to [DataFrame.apply()][dfapply] and [DataFrame.applymap()][dfapplymap].\n", + "\n", + "[table]: ../reference/api/pandas.io.formats.style.Styler.set_table_styles.rst\n", + "[styler]: ../reference/api/pandas.io.formats.style.Styler.rst\n", + "[td_class]: ../reference/api/pandas.io.formats.style.Styler.set_td_classes.rst\n", + "[apply]: ../reference/api/pandas.io.formats.style.Styler.apply.rst\n", + "[applymap]: ../reference/api/pandas.io.formats.style.Styler.applymap.rst\n", + "[applyindex]: ../reference/api/pandas.io.formats.style.Styler.apply_index.rst\n", + "[applymapindex]: ../reference/api/pandas.io.formats.style.Styler.applymap_index.rst\n", + "[dfapply]: ../reference/api/pandas.DataFrame.apply.rst\n", + "[dfapplymap]: ../reference/api/pandas.DataFrame.applymap.rst" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Table Styles\n", + "\n", + "Table styles are flexible enough to control all individual parts of the table, including column headers and indexes. \n", + "However, they can be unwieldy to type for individual data cells or for any kind of conditional formatting, so we recommend that table styles are used for broad styling, such as entire rows or columns at a time.\n", + "\n", + "Table styles are also used to control features which can apply to the whole table at once such as creating a generic hover functionality. The `:hover` pseudo-selector, as well as other pseudo-selectors, can only be used this way.\n", + "\n", + "To replicate the normal format of CSS selectors and properties (attribute value pairs), e.g. \n", + "\n", + "```\n", + "tr:hover {\n", + " background-color: #ffff99;\n", + "}\n", + "```\n", + "\n", + "the necessary format to pass styles to [.set_table_styles()][table] is as a list of dicts, each with a CSS-selector tag and CSS-properties. Properties can either be a list of 2-tuples, or a regular CSS-string, for example:\n", + "\n", + "[table]: ../reference/api/pandas.io.formats.style.Styler.set_table_styles.rst" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:37.854444Z", + "iopub.status.busy": "2023-01-25T14:32:37.854365Z", + "iopub.status.idle": "2023-01-25T14:32:37.865456Z", + "shell.execute_reply": "2023-01-25T14:32:37.865210Z" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Model:Decision TreeRegression
Predicted:TumourNon-TumourTumourNon-Tumour
Actual Label:    
Tumour (Positive)3821822
Non-Tumour (Negative)194396452
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "cell_hover = { # for row hover use instead of \n", + " 'selector': 'td:hover',\n", + " 'props': [('background-color', '#ffffb3')]\n", + "}\n", + "index_names = {\n", + " 'selector': '.index_name',\n", + " 'props': 'font-style: italic; color: darkgrey; font-weight:normal;'\n", + "}\n", + "headers = {\n", + " 'selector': 'th:not(.index_name)',\n", + " 'props': 'background-color: #000066; color: white;'\n", + "}\n", + "s.set_table_styles([cell_hover, index_names, headers])" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:37.866856Z", + "iopub.status.busy": "2023-01-25T14:32:37.866775Z", + "iopub.status.idle": "2023-01-25T14:32:37.878076Z", + "shell.execute_reply": "2023-01-25T14:32:37.877812Z" + }, + "nbsphinx": "hidden" + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Model:Decision TreeRegression
Predicted:TumourNon-TumourTumourNon-Tumour
Actual Label:    
Tumour (Positive)3821822
Non-Tumour (Negative)194396452
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Hidden cell to avoid CSS clashes and latter code upcoding previous formatting \n", + "s.set_uuid('after_tab_styles1')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Next we just add a couple more styling artifacts targeting specific parts of the table. Be careful here, since we are *chaining methods* we need to explicitly instruct the method **not to** ``overwrite`` the existing styles." + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:37.879688Z", + "iopub.status.busy": "2023-01-25T14:32:37.879574Z", + "iopub.status.idle": "2023-01-25T14:32:37.892201Z", + "shell.execute_reply": "2023-01-25T14:32:37.891918Z" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Model:Decision TreeRegression
Predicted:TumourNon-TumourTumourNon-Tumour
Actual Label:    
Tumour (Positive)3821822
Non-Tumour (Negative)194396452
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "s.set_table_styles([\n", + " {'selector': 'th.col_heading', 'props': 'text-align: center;'},\n", + " {'selector': 'th.col_heading.level0', 'props': 'font-size: 1.5em;'},\n", + " {'selector': 'td', 'props': 'text-align: center; font-weight: bold;'},\n", + "], overwrite=False)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:37.893876Z", + "iopub.status.busy": "2023-01-25T14:32:37.893737Z", + "iopub.status.idle": "2023-01-25T14:32:37.905915Z", + "shell.execute_reply": "2023-01-25T14:32:37.905661Z" + }, + "nbsphinx": "hidden" + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Model:Decision TreeRegression
Predicted:TumourNon-TumourTumourNon-Tumour
Actual Label:    
Tumour (Positive)3821822
Non-Tumour (Negative)194396452
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Hidden cell to avoid CSS clashes and latter code upcoding previous formatting \n", + "s.set_uuid('after_tab_styles2')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "As a convenience method (*since version 1.2.0*) we can also pass a **dict** to [.set_table_styles()][table] which contains row or column keys. Behind the scenes Styler just indexes the keys and adds relevant `.col` or `.row` classes as necessary to the given CSS selectors.\n", + "\n", + "[table]: ../reference/api/pandas.io.formats.style.Styler.set_table_styles.rst" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:37.907564Z", + "iopub.status.busy": "2023-01-25T14:32:37.907472Z", + "iopub.status.idle": "2023-01-25T14:32:37.919733Z", + "shell.execute_reply": "2023-01-25T14:32:37.919500Z" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Model:Decision TreeRegression
Predicted:TumourNon-TumourTumourNon-Tumour
Actual Label:    
Tumour (Positive)3821822
Non-Tumour (Negative)194396452
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "s.set_table_styles({\n", + " ('Regression', 'Tumour'): [{'selector': 'th', 'props': 'border-left: 1px solid white'},\n", + " {'selector': 'td', 'props': 'border-left: 1px solid #000066'}]\n", + "}, overwrite=False, axis=0)" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:37.921193Z", + "iopub.status.busy": "2023-01-25T14:32:37.921115Z", + "iopub.status.idle": "2023-01-25T14:32:37.936097Z", + "shell.execute_reply": "2023-01-25T14:32:37.935846Z" + }, + "nbsphinx": "hidden" + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Model:Decision TreeRegression
Predicted:TumourNon-TumourTumourNon-Tumour
Actual Label:    
Tumour (Positive)3821822
Non-Tumour (Negative)194396452
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Hidden cell to avoid CSS clashes and latter code upcoding previous formatting \n", + "s.set_uuid('xyz01')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Setting Classes and Linking to External CSS\n", + "\n", + "If you have designed a website then it is likely you will already have an external CSS file that controls the styling of table and cell objects within it. You may want to use these native files rather than duplicate all the CSS in python (and duplicate any maintenance work).\n", + "\n", + "### Table Attributes\n", + "\n", + "It is very easy to add a `class` to the main `` using [.set_table_attributes()][tableatt]. This method can also attach inline styles - read more in [CSS Hierarchies](#CSS-Hierarchies).\n", + "\n", + "[tableatt]: ../reference/api/pandas.io.formats.style.Styler.set_table_attributes.rst" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:37.937583Z", + "iopub.status.busy": "2023-01-25T14:32:37.937482Z", + "iopub.status.idle": "2023-01-25T14:32:37.947993Z", + "shell.execute_reply": "2023-01-25T14:32:37.947739Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "
\n", + " \n", + " \n", + " \n" + ] + } + ], + "source": [ + "out = s.set_table_attributes('class=\"my-table-cls\"').to_html()\n", + "print(out[out.find('` elements of the `
Model:
`. Rather than use external CSS we will create our classes internally and add them to table style. We will save adding the borders until the [section on tooltips](#Tooltips).\n", + "\n", + "[tdclass]: ../reference/api/pandas.io.formats.style.Styler.set_td_classes.rst\n", + "[styler]: ../reference/api/pandas.io.formats.style.Styler.rst" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:37.949481Z", + "iopub.status.busy": "2023-01-25T14:32:37.949400Z", + "iopub.status.idle": "2023-01-25T14:32:37.961606Z", + "shell.execute_reply": "2023-01-25T14:32:37.961363Z" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "
\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Model:Decision TreeRegression
Predicted:TumourNon-TumourTumourNon-Tumour
Actual Label:    
Tumour (Positive)3821822
Non-Tumour (Negative)194396452
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "s.set_table_styles([ # create internal CSS classes\n", + " {'selector': '.true', 'props': 'background-color: #e6ffe6;'},\n", + " {'selector': '.false', 'props': 'background-color: #ffe6e6;'},\n", + "], overwrite=False)\n", + "cell_color = pd.DataFrame([['true ', 'false ', 'true ', 'false '], \n", + " ['false ', 'true ', 'false ', 'true ']], \n", + " index=df.index, \n", + " columns=df.columns[:4])\n", + "s.set_td_classes(cell_color)" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:37.962986Z", + "iopub.status.busy": "2023-01-25T14:32:37.962909Z", + "iopub.status.idle": "2023-01-25T14:32:37.974709Z", + "shell.execute_reply": "2023-01-25T14:32:37.974450Z" + }, + "nbsphinx": "hidden" + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Model:Decision TreeRegression
Predicted:TumourNon-TumourTumourNon-Tumour
Actual Label:    
Tumour (Positive)3821822
Non-Tumour (Negative)194396452
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Hidden cell to avoid CSS clashes and latter code upcoding previous formatting \n", + "s.set_uuid('after_classes')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Styler Functions\n", + "\n", + "### Acting on Data\n", + "\n", + "We use the following methods to pass your style functions. Both of those methods take a function (and some other keyword arguments) and apply it to the DataFrame in a certain way, rendering CSS styles.\n", + "\n", + "- [.applymap()][applymap] (elementwise): accepts a function that takes a single value and returns a string with the CSS attribute-value pair.\n", + "- [.apply()][apply] (column-/row-/table-wise): accepts a function that takes a Series or DataFrame and returns a Series, DataFrame, or numpy array with an identical shape where each element is a string with a CSS attribute-value pair. This method passes each column or row of your DataFrame one-at-a-time or the entire table at once, depending on the `axis` keyword argument. For columnwise use `axis=0`, rowwise use `axis=1`, and for the entire table at once use `axis=None`.\n", + "\n", + "This method is powerful for applying multiple, complex logic to data cells. We create a new DataFrame to demonstrate this.\n", + "\n", + "[apply]: ../reference/api/pandas.io.formats.style.Styler.apply.rst\n", + "[applymap]: ../reference/api/pandas.io.formats.style.Styler.applymap.rst" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:37.976315Z", + "iopub.status.busy": "2023-01-25T14:32:37.976204Z", + "iopub.status.idle": "2023-01-25T14:32:37.987983Z", + "shell.execute_reply": "2023-01-25T14:32:37.987738Z" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
 ABCD
01.7640520.4001570.9787382.240893
11.867558-0.9772780.950088-0.151357
2-0.1032190.4105990.1440441.454274
30.7610380.1216750.4438630.333674
41.494079-0.2051580.313068-0.854096
5-2.5529900.6536190.864436-0.742165
62.269755-1.4543660.045759-0.187184
71.5327791.4693590.1549470.378163
8-0.887786-1.980796-0.3479120.156349
91.2302911.202380-0.387327-0.302303
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "np.random.seed(0)\n", + "df2 = pd.DataFrame(np.random.randn(10,4), columns=['A','B','C','D'])\n", + "df2.style" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "For example we can build a function that colors text if it is negative, and chain this with a function that partially fades cells of negligible value. Since this looks at each element in turn we use ``applymap``." + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:37.989527Z", + "iopub.status.busy": "2023-01-25T14:32:37.989448Z", + "iopub.status.idle": "2023-01-25T14:32:38.001730Z", + "shell.execute_reply": "2023-01-25T14:32:38.001470Z" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
 ABCD
01.7640520.4001570.9787382.240893
11.867558-0.9772780.950088-0.151357
2-0.1032190.4105990.1440441.454274
30.7610380.1216750.4438630.333674
41.494079-0.2051580.313068-0.854096
5-2.5529900.6536190.864436-0.742165
62.269755-1.4543660.045759-0.187184
71.5327791.4693590.1549470.378163
8-0.887786-1.980796-0.3479120.156349
91.2302911.202380-0.387327-0.302303
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def style_negative(v, props=''):\n", + " return props if v < 0 else None\n", + "s2 = df2.style.applymap(style_negative, props='color:red;')\\\n", + " .applymap(lambda v: 'opacity: 20%;' if (v < 0.3) and (v > -0.3) else None)\n", + "s2" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:38.003191Z", + "iopub.status.busy": "2023-01-25T14:32:38.003104Z", + "iopub.status.idle": "2023-01-25T14:32:38.014611Z", + "shell.execute_reply": "2023-01-25T14:32:38.014365Z" + }, + "nbsphinx": "hidden" + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
 ABCD
01.7640520.4001570.9787382.240893
11.867558-0.9772780.950088-0.151357
2-0.1032190.4105990.1440441.454274
30.7610380.1216750.4438630.333674
41.494079-0.2051580.313068-0.854096
5-2.5529900.6536190.864436-0.742165
62.269755-1.4543660.045759-0.187184
71.5327791.4693590.1549470.378163
8-0.887786-1.980796-0.3479120.156349
91.2302911.202380-0.387327-0.302303
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Hidden cell to avoid CSS clashes and latter code upcoding previous formatting \n", + "s2.set_uuid('after_applymap')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We can also build a function that highlights the maximum value across rows, cols, and the DataFrame all at once. In this case we use ``apply``. Below we highlight the maximum in a column." + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:38.016109Z", + "iopub.status.busy": "2023-01-25T14:32:38.016023Z", + "iopub.status.idle": "2023-01-25T14:32:38.028756Z", + "shell.execute_reply": "2023-01-25T14:32:38.028493Z" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
 ABCD
01.7640520.4001570.9787382.240893
11.867558-0.9772780.950088-0.151357
2-0.1032190.4105990.1440441.454274
30.7610380.1216750.4438630.333674
41.494079-0.2051580.313068-0.854096
5-2.5529900.6536190.864436-0.742165
62.269755-1.4543660.045759-0.187184
71.5327791.4693590.1549470.378163
8-0.887786-1.980796-0.3479120.156349
91.2302911.202380-0.387327-0.302303
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def highlight_max(s, props=''):\n", + " return np.where(s == np.nanmax(s.values), props, '')\n", + "s2.apply(highlight_max, props='color:white;background-color:darkblue', axis=0)" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:38.030241Z", + "iopub.status.busy": "2023-01-25T14:32:38.030149Z", + "iopub.status.idle": "2023-01-25T14:32:38.042535Z", + "shell.execute_reply": "2023-01-25T14:32:38.042293Z" + }, + "nbsphinx": "hidden" + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
 ABCD
01.7640520.4001570.9787382.240893
11.867558-0.9772780.950088-0.151357
2-0.1032190.4105990.1440441.454274
30.7610380.1216750.4438630.333674
41.494079-0.2051580.313068-0.854096
5-2.5529900.6536190.864436-0.742165
62.269755-1.4543660.045759-0.187184
71.5327791.4693590.1549470.378163
8-0.887786-1.980796-0.3479120.156349
91.2302911.202380-0.387327-0.302303
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Hidden cell to avoid CSS clashes and latter code upcoding previous formatting \n", + "s2.set_uuid('after_apply')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We can use the same function across the different axes, highlighting here the DataFrame maximum in purple, and row maximums in pink." + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:38.044098Z", + "iopub.status.busy": "2023-01-25T14:32:38.044013Z", + "iopub.status.idle": "2023-01-25T14:32:38.058598Z", + "shell.execute_reply": "2023-01-25T14:32:38.058361Z" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
 ABCD
01.7640520.4001570.9787382.240893
11.867558-0.9772780.950088-0.151357
2-0.1032190.4105990.1440441.454274
30.7610380.1216750.4438630.333674
41.494079-0.2051580.313068-0.854096
5-2.5529900.6536190.864436-0.742165
62.269755-1.4543660.045759-0.187184
71.5327791.4693590.1549470.378163
8-0.887786-1.980796-0.3479120.156349
91.2302911.202380-0.387327-0.302303
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "s2.apply(highlight_max, props='color:white;background-color:pink;', axis=1)\\\n", + " .apply(highlight_max, props='color:white;background-color:purple', axis=None)" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:38.059958Z", + "iopub.status.busy": "2023-01-25T14:32:38.059875Z", + "iopub.status.idle": "2023-01-25T14:32:38.074078Z", + "shell.execute_reply": "2023-01-25T14:32:38.073837Z" + }, + "nbsphinx": "hidden" + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
 ABCD
01.7640520.4001570.9787382.240893
11.867558-0.9772780.950088-0.151357
2-0.1032190.4105990.1440441.454274
30.7610380.1216750.4438630.333674
41.494079-0.2051580.313068-0.854096
5-2.5529900.6536190.864436-0.742165
62.269755-1.4543660.045759-0.187184
71.5327791.4693590.1549470.378163
8-0.887786-1.980796-0.3479120.156349
91.2302911.202380-0.387327-0.302303
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Hidden cell to avoid CSS clashes and latter code upcoding previous formatting \n", + "s2.set_uuid('after_apply_again')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This last example shows how some styles have been overwritten by others. In general the most recent style applied is active but you can read more in the [section on CSS hierarchies](#CSS-Hierarchies). You can also apply these styles to more granular parts of the DataFrame - read more in section on [subset slicing](#Finer-Control-with-Slicing).\n", + "\n", + "It is possible to replicate some of this functionality using just classes but it can be more cumbersome. See [item 3) of Optimization](#Optimization)\n", + "\n", + "
\n", + "\n", + "*Debugging Tip*: If you're having trouble writing your style function, try just passing it into ``DataFrame.apply``. Internally, ``Styler.apply`` uses ``DataFrame.apply`` so the result should be the same, and with ``DataFrame.apply`` you will be able to inspect the CSS string output of your intended function in each cell.\n", + "\n", + "
" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Acting on the Index and Column Headers\n", + "\n", + "Similar application is achieved for headers by using:\n", + " \n", + "- [.applymap_index()][applymapindex] (elementwise): accepts a function that takes a single value and returns a string with the CSS attribute-value pair.\n", + "- [.apply_index()][applyindex] (level-wise): accepts a function that takes a Series and returns a Series, or numpy array with an identical shape where each element is a string with a CSS attribute-value pair. This method passes each level of your Index one-at-a-time. To style the index use `axis=0` and to style the column headers use `axis=1`.\n", + "\n", + "You can select a `level` of a `MultiIndex` but currently no similar `subset` application is available for these methods.\n", + "\n", + "[applyindex]: ../reference/api/pandas.io.formats.style.Styler.apply_index.rst\n", + "[applymapindex]: ../reference/api/pandas.io.formats.style.Styler.applymap_index.rst" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:38.075627Z", + "iopub.status.busy": "2023-01-25T14:32:38.075522Z", + "iopub.status.idle": "2023-01-25T14:32:38.090386Z", + "shell.execute_reply": "2023-01-25T14:32:38.090148Z" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
 ABCD
01.7640520.4001570.9787382.240893
11.867558-0.9772780.950088-0.151357
2-0.1032190.4105990.1440441.454274
30.7610380.1216750.4438630.333674
41.494079-0.2051580.313068-0.854096
5-2.5529900.6536190.864436-0.742165
62.269755-1.4543660.045759-0.187184
71.5327791.4693590.1549470.378163
8-0.887786-1.980796-0.3479120.156349
91.2302911.202380-0.387327-0.302303
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 26, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "s2.applymap_index(lambda v: \"color:pink;\" if v>4 else \"color:darkblue;\", axis=0)\n", + "s2.apply_index(lambda s: np.where(s.isin([\"A\", \"B\"]), \"color:pink;\", \"color:darkblue;\"), axis=1)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Tooltips and Captions\n", + "\n", + "Table captions can be added with the [.set_caption()][caption] method. You can use table styles to control the CSS relevant to the caption.\n", + "\n", + "[caption]: ../reference/api/pandas.io.formats.style.Styler.set_caption.rst" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:38.091831Z", + "iopub.status.busy": "2023-01-25T14:32:38.091753Z", + "iopub.status.idle": "2023-01-25T14:32:38.103154Z", + "shell.execute_reply": "2023-01-25T14:32:38.102906Z" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Confusion matrix for multiple cancer prediction models.
Model:Decision TreeRegression
Predicted:TumourNon-TumourTumourNon-Tumour
Actual Label:    
Tumour (Positive)3821822
Non-Tumour (Negative)194396452
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "s.set_caption(\"Confusion matrix for multiple cancer prediction models.\")\\\n", + " .set_table_styles([{\n", + " 'selector': 'caption',\n", + " 'props': 'caption-side: bottom; font-size:1.25em;'\n", + " }], overwrite=False)" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:38.104657Z", + "iopub.status.busy": "2023-01-25T14:32:38.104568Z", + "iopub.status.idle": "2023-01-25T14:32:38.115249Z", + "shell.execute_reply": "2023-01-25T14:32:38.115013Z" + }, + "nbsphinx": "hidden" + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Confusion matrix for multiple cancer prediction models.
Model:Decision TreeRegression
Predicted:TumourNon-TumourTumourNon-Tumour
Actual Label:    
Tumour (Positive)3821822
Non-Tumour (Negative)194396452
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Hidden cell to avoid CSS clashes and latter code upcoding previous formatting \n", + "s.set_uuid('after_caption')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Adding tooltips (*since version 1.3.0*) can be done using the [.set_tooltips()][tooltips] method in the same way you can add CSS classes to data cells by providing a string based DataFrame with intersecting indices and columns. You don't have to specify a `css_class` name or any css `props` for the tooltips, since there are standard defaults, but the option is there if you want more visual control. \n", + "\n", + "[tooltips]: ../reference/api/pandas.io.formats.style.Styler.set_tooltips.rst" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:38.116684Z", + "iopub.status.busy": "2023-01-25T14:32:38.116603Z", + "iopub.status.idle": "2023-01-25T14:32:38.128590Z", + "shell.execute_reply": "2023-01-25T14:32:38.128332Z" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Confusion matrix for multiple cancer prediction models.
Model:Decision TreeRegression
Predicted:TumourNon-TumourTumourNon-Tumour
Actual Label:    
Tumour (Positive)3821822
Non-Tumour (Negative)194396452
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 29, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "tt = pd.DataFrame([['This model has a very strong true positive rate', \n", + " \"This model's total number of false negatives is too high\"]], \n", + " index=['Tumour (Positive)'], columns=df.columns[[0,3]])\n", + "s.set_tooltips(tt, props='visibility: hidden; position: absolute; z-index: 1; border: 1px solid #000066;'\n", + " 'background-color: white; color: #000066; font-size: 0.8em;' \n", + " 'transform: translate(0px, -24px); padding: 0.6em; border-radius: 0.5em;')" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:38.130086Z", + "iopub.status.busy": "2023-01-25T14:32:38.130001Z", + "iopub.status.idle": "2023-01-25T14:32:38.141444Z", + "shell.execute_reply": "2023-01-25T14:32:38.141199Z" + }, + "nbsphinx": "hidden" + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Confusion matrix for multiple cancer prediction models.
Model:Decision TreeRegression
Predicted:TumourNon-TumourTumourNon-Tumour
Actual Label:    
Tumour (Positive)3821822
Non-Tumour (Negative)194396452
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 30, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Hidden cell to avoid CSS clashes and latter code upcoding previous formatting \n", + "s.set_uuid('after_tooltips')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The only thing left to do for our table is to add the highlighting borders to draw the audience attention to the tooltips. We will create internal CSS classes as before using table styles. **Setting classes always overwrites** so we need to make sure we add the previous classes." + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:38.142916Z", + "iopub.status.busy": "2023-01-25T14:32:38.142833Z", + "iopub.status.idle": "2023-01-25T14:32:38.155848Z", + "shell.execute_reply": "2023-01-25T14:32:38.155603Z" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Confusion matrix for multiple cancer prediction models.
Model:Decision TreeRegression
Predicted:TumourNon-TumourTumourNon-Tumour
Actual Label:    
Tumour (Positive)3821822
Non-Tumour (Negative)194396452
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 31, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "s.set_table_styles([ # create internal CSS classes\n", + " {'selector': '.border-red', 'props': 'border: 2px dashed red;'},\n", + " {'selector': '.border-green', 'props': 'border: 2px dashed green;'},\n", + "], overwrite=False)\n", + "cell_border = pd.DataFrame([['border-green ', ' ', ' ', 'border-red '], \n", + " [' ', ' ', ' ', ' ']], \n", + " index=df.index, \n", + " columns=df.columns[:4])\n", + "s.set_td_classes(cell_color + cell_border)" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:38.157239Z", + "iopub.status.busy": "2023-01-25T14:32:38.157159Z", + "iopub.status.idle": "2023-01-25T14:32:38.169339Z", + "shell.execute_reply": "2023-01-25T14:32:38.169102Z" + }, + "nbsphinx": "hidden" + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Confusion matrix for multiple cancer prediction models.
Model:Decision TreeRegression
Predicted:TumourNon-TumourTumourNon-Tumour
Actual Label:    
Tumour (Positive)3821822
Non-Tumour (Negative)194396452
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 32, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Hidden cell to avoid CSS clashes and latter code upcoding previous formatting \n", + "s.set_uuid('after_borders')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Finer Control with Slicing\n", + "\n", + "The examples we have shown so far for the `Styler.apply` and `Styler.applymap` functions have not demonstrated the use of the ``subset`` argument. This is a useful argument which permits a lot of flexibility: it allows you to apply styles to specific rows or columns, without having to code that logic into your `style` function.\n", + "\n", + "The value passed to `subset` behaves similar to slicing a DataFrame;\n", + "\n", + "- A scalar is treated as a column label\n", + "- A list (or Series or NumPy array) is treated as multiple column labels\n", + "- A tuple is treated as `(row_indexer, column_indexer)`\n", + "\n", + "Consider using `pd.IndexSlice` to construct the tuple for the last one. We will create a MultiIndexed DataFrame to demonstrate the functionality." + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:38.170799Z", + "iopub.status.busy": "2023-01-25T14:32:38.170719Z", + "iopub.status.idle": "2023-01-25T14:32:38.183159Z", + "shell.execute_reply": "2023-01-25T14:32:38.182909Z" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
c1c2c3c4
Ar1-1.048553-1.420018-1.7062701.950775
r2-0.509652-0.438074-1.2527950.777490
Br1-1.613898-0.212740-0.8954670.386902
r2-0.510805-1.180632-0.0281820.428332
\n", + "
" + ], + "text/plain": [ + " c1 c2 c3 c4\n", + "A r1 -1.048553 -1.420018 -1.706270 1.950775\n", + " r2 -0.509652 -0.438074 -1.252795 0.777490\n", + "B r1 -1.613898 -0.212740 -0.895467 0.386902\n", + " r2 -0.510805 -1.180632 -0.028182 0.428332" + ] + }, + "execution_count": 33, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df3 = pd.DataFrame(np.random.randn(4,4), \n", + " pd.MultiIndex.from_product([['A', 'B'], ['r1', 'r2']]),\n", + " columns=['c1','c2','c3','c4'])\n", + "df3" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We will use subset to highlight the maximum in the third and fourth columns with red text. We will highlight the subset sliced region in yellow." + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:38.184657Z", + "iopub.status.busy": "2023-01-25T14:32:38.184573Z", + "iopub.status.idle": "2023-01-25T14:32:38.197221Z", + "shell.execute_reply": "2023-01-25T14:32:38.196957Z" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
  c1c2c3c4
Ar1-1.048553-1.420018-1.7062701.950775
r2-0.509652-0.438074-1.2527950.777490
Br1-1.613898-0.212740-0.8954670.386902
r2-0.510805-1.180632-0.0281820.428332
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 34, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "slice_ = ['c3', 'c4']\n", + "df3.style.apply(highlight_max, props='color:red;', axis=0, subset=slice_)\\\n", + " .set_properties(**{'background-color': '#ffffb3'}, subset=slice_)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "If combined with the ``IndexSlice`` as suggested then it can index across both dimensions with greater flexibility." + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:38.198695Z", + "iopub.status.busy": "2023-01-25T14:32:38.198614Z", + "iopub.status.idle": "2023-01-25T14:32:38.212302Z", + "shell.execute_reply": "2023-01-25T14:32:38.212036Z" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
  c1c2c3c4
Ar1-1.048553-1.420018-1.7062701.950775
r2-0.509652-0.438074-1.2527950.777490
Br1-1.613898-0.212740-0.8954670.386902
r2-0.510805-1.180632-0.0281820.428332
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 35, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "idx = pd.IndexSlice\n", + "slice_ = idx[idx[:,'r1'], idx['c2':'c4']]\n", + "df3.style.apply(highlight_max, props='color:red;', axis=0, subset=slice_)\\\n", + " .set_properties(**{'background-color': '#ffffb3'}, subset=slice_)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This also provides the flexibility to sub select rows when used with the `axis=1`." + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:38.213771Z", + "iopub.status.busy": "2023-01-25T14:32:38.213692Z", + "iopub.status.idle": "2023-01-25T14:32:38.226678Z", + "shell.execute_reply": "2023-01-25T14:32:38.226429Z" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
  c1c2c3c4
Ar1-1.048553-1.420018-1.7062701.950775
r2-0.509652-0.438074-1.2527950.777490
Br1-1.613898-0.212740-0.8954670.386902
r2-0.510805-1.180632-0.0281820.428332
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 36, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "slice_ = idx[idx[:,'r2'], :]\n", + "df3.style.apply(highlight_max, props='color:red;', axis=1, subset=slice_)\\\n", + " .set_properties(**{'background-color': '#ffffb3'}, subset=slice_)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "There is also scope to provide **conditional filtering**. \n", + "\n", + "Suppose we want to highlight the maximum across columns 2 and 4 only in the case that the sum of columns 1 and 3 is less than -2.0 *(essentially excluding rows* `(:,'r2')`*)*." + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:38.228203Z", + "iopub.status.busy": "2023-01-25T14:32:38.228116Z", + "iopub.status.idle": "2023-01-25T14:32:38.241205Z", + "shell.execute_reply": "2023-01-25T14:32:38.240960Z" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
  c1c2c3c4
Ar1-1.048553-1.420018-1.7062701.950775
r2-0.509652-0.438074-1.2527950.777490
Br1-1.613898-0.212740-0.8954670.386902
r2-0.510805-1.180632-0.0281820.428332
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 37, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "slice_ = idx[idx[(df3['c1'] + df3['c3']) < -2.0], ['c2', 'c4']]\n", + "df3.style.apply(highlight_max, props='color:red;', axis=1, subset=slice_)\\\n", + " .set_properties(**{'background-color': '#ffffb3'}, subset=slice_)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Only label-based slicing is supported right now, not positional, and not callables.\n", + "\n", + "If your style function uses a `subset` or `axis` keyword argument, consider wrapping your function in a `functools.partial`, partialing out that keyword.\n", + "\n", + "```python\n", + "my_func2 = functools.partial(my_func, subset=42)\n", + "```" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Optimization\n", + "\n", + "Generally, for smaller tables and most cases, the rendered HTML does not need to be optimized, and we don't really recommend it. There are two cases where it is worth considering:\n", + "\n", + " - If you are rendering and styling a very large HTML table, certain browsers have performance issues.\n", + " - If you are using ``Styler`` to dynamically create part of online user interfaces and want to improve network performance.\n", + " \n", + "Here we recommend the following steps to implement:" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 1. Remove UUID and cell_ids\n", + "\n", + "Ignore the `uuid` and set `cell_ids` to `False`. This will prevent unnecessary HTML." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "
\n", + "\n", + "This is sub-optimal:\n", + "\n", + "
" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:38.242920Z", + "iopub.status.busy": "2023-01-25T14:32:38.242813Z", + "iopub.status.idle": "2023-01-25T14:32:38.252636Z", + "shell.execute_reply": "2023-01-25T14:32:38.252372Z" + } + }, + "outputs": [], + "source": [ + "df4 = pd.DataFrame([[1,2],[3,4]])\n", + "s4 = df4.style" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "
\n", + "\n", + "This is better:\n", + "\n", + "
" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:38.254145Z", + "iopub.status.busy": "2023-01-25T14:32:38.254057Z", + "iopub.status.idle": "2023-01-25T14:32:38.263096Z", + "shell.execute_reply": "2023-01-25T14:32:38.262861Z" + } + }, + "outputs": [], + "source": [ + "from pandas.io.formats.style import Styler\n", + "s4 = Styler(df4, uuid_len=0, cell_ids=False)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 2. Use table styles\n", + "\n", + "Use table styles where possible (e.g. for all cells or rows or columns at a time) since the CSS is nearly always more efficient than other formats." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "
\n", + "\n", + "This is sub-optimal:\n", + "\n", + "
" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:38.264589Z", + "iopub.status.busy": "2023-01-25T14:32:38.264506Z", + "iopub.status.idle": "2023-01-25T14:32:38.275120Z", + "shell.execute_reply": "2023-01-25T14:32:38.274872Z" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
 01
012
134
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 40, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "props = 'font-family: \"Times New Roman\", Times, serif; color: #e83e8c; font-size:1.3em;'\n", + "df4.style.applymap(lambda x: props, subset=[1])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "
\n", + "\n", + "This is better:\n", + "\n", + "
" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:38.276627Z", + "iopub.status.busy": "2023-01-25T14:32:38.276546Z", + "iopub.status.idle": "2023-01-25T14:32:38.287499Z", + "shell.execute_reply": "2023-01-25T14:32:38.287231Z" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
 01
012
134
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 41, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df4.style.set_table_styles([{'selector': 'td.col1', 'props': props}])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 3. Set classes instead of using Styler functions\n", + "\n", + "For large DataFrames where the same style is applied to many cells it can be more efficient to declare the styles as classes and then apply those classes to data cells, rather than directly applying styles to cells. It is, however, probably still easier to use the Styler function api when you are not concerned about optimization." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "
\n", + "\n", + "This is sub-optimal:\n", + "\n", + "
" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:38.289173Z", + "iopub.status.busy": "2023-01-25T14:32:38.289065Z", + "iopub.status.idle": "2023-01-25T14:32:38.302777Z", + "shell.execute_reply": "2023-01-25T14:32:38.302515Z" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
 ABCD
01.7640520.4001570.9787382.240893
11.867558-0.9772780.950088-0.151357
2-0.1032190.4105990.1440441.454274
30.7610380.1216750.4438630.333674
41.494079-0.2051580.313068-0.854096
5-2.5529900.6536190.864436-0.742165
62.269755-1.4543660.045759-0.187184
71.5327791.4693590.1549470.378163
8-0.887786-1.980796-0.3479120.156349
91.2302911.202380-0.387327-0.302303
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 42, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df2.style.apply(highlight_max, props='color:white;background-color:darkblue;', axis=0)\\\n", + " .apply(highlight_max, props='color:white;background-color:pink;', axis=1)\\\n", + " .apply(highlight_max, props='color:white;background-color:purple', axis=None)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "
\n", + "\n", + "This is better:\n", + "\n", + "
" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:38.304299Z", + "iopub.status.busy": "2023-01-25T14:32:38.304215Z", + "iopub.status.idle": "2023-01-25T14:32:38.318437Z", + "shell.execute_reply": "2023-01-25T14:32:38.318184Z" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
 ABCD
01.7640520.4001570.9787382.240893
11.867558-0.9772780.950088-0.151357
2-0.1032190.4105990.1440441.454274
30.7610380.1216750.4438630.333674
41.494079-0.2051580.313068-0.854096
5-2.5529900.6536190.864436-0.742165
62.269755-1.4543660.045759-0.187184
71.5327791.4693590.1549470.378163
8-0.887786-1.980796-0.3479120.156349
91.2302911.202380-0.387327-0.302303
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 43, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "build = lambda x: pd.DataFrame(x, index=df2.index, columns=df2.columns)\n", + "cls1 = build(df2.apply(highlight_max, props='cls-1 ', axis=0))\n", + "cls2 = build(df2.apply(highlight_max, props='cls-2 ', axis=1, result_type='expand').values)\n", + "cls3 = build(highlight_max(df2, props='cls-3 '))\n", + "df2.style.set_table_styles([\n", + " {'selector': '.cls-1', 'props': 'color:white;background-color:darkblue;'},\n", + " {'selector': '.cls-2', 'props': 'color:white;background-color:pink;'},\n", + " {'selector': '.cls-3', 'props': 'color:white;background-color:purple;'}\n", + "]).set_td_classes(cls1 + cls2 + cls3)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 4. Don't use tooltips\n", + "\n", + "Tooltips require `cell_ids` to work and they generate extra HTML elements for *every* data cell." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 5. If every byte counts use string replacement\n", + "\n", + "You can remove unnecessary HTML, or shorten the default class names by replacing the default css dict. You can read a little more about CSS [below](#More-About-CSS-and-HTML)." + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:38.320001Z", + "iopub.status.busy": "2023-01-25T14:32:38.319916Z", + "iopub.status.idle": "2023-01-25T14:32:38.331000Z", + "shell.execute_reply": "2023-01-25T14:32:38.330759Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
 01
012
134
\n", + "\n" + ] + } + ], + "source": [ + "my_css = {\n", + " \"row_heading\": \"\",\n", + " \"col_heading\": \"\",\n", + " \"index_name\": \"\",\n", + " \"col\": \"c\",\n", + " \"row\": \"r\",\n", + " \"col_trim\": \"\",\n", + " \"row_trim\": \"\",\n", + " \"level\": \"l\",\n", + " \"data\": \"\",\n", + " \"blank\": \"\",\n", + "}\n", + "html = Styler(df4, uuid_len=0, cell_ids=False)\n", + "html.set_table_styles([{'selector': 'td', 'props': props},\n", + " {'selector': '.c1', 'props': 'color:green;'},\n", + " {'selector': '.l0', 'props': 'color:blue;'}],\n", + " css_class_names=my_css)\n", + "print(html.to_html())" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:38.332531Z", + "iopub.status.busy": "2023-01-25T14:32:38.332448Z", + "iopub.status.idle": "2023-01-25T14:32:38.342396Z", + "shell.execute_reply": "2023-01-25T14:32:38.342145Z" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
 01
012
134
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 45, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "html" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Builtin Styles" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "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 on their, or other, values on a numeric scale.\n", + " - [.text_gradient][textfunc]: similar method for highlighting text based on 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", + "[textfunc]: ../reference/api/pandas.io.formats.style.Styler.text_gradient.rst\n", + "[barfunc]: ../reference/api/pandas.io.formats.style.Styler.bar.rst" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Highlight Null" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:38.343938Z", + "iopub.status.busy": "2023-01-25T14:32:38.343854Z", + "iopub.status.idle": "2023-01-25T14:32:38.355069Z", + "shell.execute_reply": "2023-01-25T14:32:38.354815Z" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
 ABCD
01.7640520.400157nan2.240893
11.867558-0.9772780.950088-0.151357
2-0.1032190.4105990.1440441.454274
30.7610380.1216750.4438630.333674
41.494079-0.2051580.313068nan
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 46, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df2.iloc[0,2] = np.nan\n", + "df2.iloc[4,3] = np.nan\n", + "df2.loc[:4].style.highlight_null(color='yellow')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Highlight Min or Max" + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:38.356596Z", + "iopub.status.busy": "2023-01-25T14:32:38.356512Z", + "iopub.status.idle": "2023-01-25T14:32:38.368646Z", + "shell.execute_reply": "2023-01-25T14:32:38.368390Z" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
 ABCD
01.7640520.400157nan2.240893
11.867558-0.9772780.950088-0.151357
2-0.1032190.4105990.1440441.454274
30.7610380.1216750.4438630.333674
41.494079-0.2051580.313068nan
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 47, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df2.loc[:4].style.highlight_max(axis=1, props='color:white; font-weight:bold; background-color:darkblue;')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Highlight Between\n", + "This method accepts ranges as float, or NumPy arrays or Series provided the indexes match." + ] + }, + { + "cell_type": "code", + "execution_count": 48, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:38.370117Z", + "iopub.status.busy": "2023-01-25T14:32:38.370038Z", + "iopub.status.idle": "2023-01-25T14:32:38.383825Z", + "shell.execute_reply": "2023-01-25T14:32:38.383590Z" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
 ABCD
01.7640520.400157nan2.240893
11.867558-0.9772780.950088-0.151357
2-0.1032190.4105990.1440441.454274
30.7610380.1216750.4438630.333674
41.494079-0.2051580.313068nan
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 48, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "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" + ] + }, + { + "cell_type": "code", + "execution_count": 49, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:38.385273Z", + "iopub.status.busy": "2023-01-25T14:32:38.385192Z", + "iopub.status.idle": "2023-01-25T14:32:38.397125Z", + "shell.execute_reply": "2023-01-25T14:32:38.396863Z" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
 ABCD
01.7640520.400157nan2.240893
11.867558-0.9772780.950088-0.151357
2-0.1032190.4105990.1440441.454274
30.7610380.1216750.4438630.333674
41.494079-0.2051580.313068nan
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 49, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df2.loc[:4].style.highlight_quantile(q_left=0.85, axis=None, color='yellow')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Background Gradient and Text Gradient" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "You can create \"heatmaps\" with the `background_gradient` and `text_gradient` methods. These require matplotlib, and we'll use [Seaborn](http://seaborn.pydata.org/) to get a nice colormap." + ] + }, + { + "cell_type": "code", + "execution_count": 50, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:38.398704Z", + "iopub.status.busy": "2023-01-25T14:32:38.398617Z", + "iopub.status.idle": "2023-01-25T14:32:38.702950Z", + "shell.execute_reply": "2023-01-25T14:32:38.702688Z" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
 ABCD
01.7640520.400157nan2.240893
11.867558-0.9772780.950088-0.151357
2-0.1032190.4105990.1440441.454274
30.7610380.1216750.4438630.333674
41.494079-0.2051580.313068nan
5-2.5529900.6536190.864436-0.742165
62.269755-1.4543660.045759-0.187184
71.5327791.4693590.1549470.378163
8-0.887786-1.980796-0.3479120.156349
91.2302911.202380-0.387327-0.302303
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 50, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import seaborn as sns\n", + "cm = sns.light_palette(\"green\", as_cmap=True)\n", + "\n", + "df2.style.background_gradient(cmap=cm)" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:38.704450Z", + "iopub.status.busy": "2023-01-25T14:32:38.704364Z", + "iopub.status.idle": "2023-01-25T14:32:38.720244Z", + "shell.execute_reply": "2023-01-25T14:32:38.719996Z" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
 ABCD
01.7640520.400157nan2.240893
11.867558-0.9772780.950088-0.151357
2-0.1032190.4105990.1440441.454274
30.7610380.1216750.4438630.333674
41.494079-0.2051580.313068nan
5-2.5529900.6536190.864436-0.742165
62.269755-1.4543660.045759-0.187184
71.5327791.4693590.1549470.378163
8-0.887786-1.980796-0.3479120.156349
91.2302911.202380-0.387327-0.302303
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 51, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df2.style.text_gradient(cmap=cm)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "[.background_gradient][bgfunc] and [.text_gradient][textfunc] have a number of keyword arguments to customise the gradients and colors. See the documentation.\n", + "\n", + "[bgfunc]: ../reference/api/pandas.io.formats.style.Styler.background_gradient.rst\n", + "[textfunc]: ../reference/api/pandas.io.formats.style.Styler.text_gradient.rst" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Set properties\n", + "\n", + "Use `Styler.set_properties` when the style doesn't actually depend on the values. This is just a simple wrapper for `.applymap` where the function returns the same properties for all cells." + ] + }, + { + "cell_type": "code", + "execution_count": 52, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:38.721908Z", + "iopub.status.busy": "2023-01-25T14:32:38.721808Z", + "iopub.status.idle": "2023-01-25T14:32:38.736051Z", + "shell.execute_reply": "2023-01-25T14:32:38.735805Z" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
 ABCD
01.7640520.400157nan2.240893
11.867558-0.9772780.950088-0.151357
2-0.1032190.4105990.1440441.454274
30.7610380.1216750.4438630.333674
41.494079-0.2051580.313068nan
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 52, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df2.loc[:4].style.set_properties(**{'background-color': 'black',\n", + " 'color': 'lawngreen',\n", + " 'border-color': 'white'})" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Bar charts" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "You can include \"bar charts\" in your DataFrame." + ] + }, + { + "cell_type": "code", + "execution_count": 53, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:38.737574Z", + "iopub.status.busy": "2023-01-25T14:32:38.737498Z", + "iopub.status.idle": "2023-01-25T14:32:38.751498Z", + "shell.execute_reply": "2023-01-25T14:32:38.751232Z" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
 ABCD
01.7640520.400157nan2.240893
11.867558-0.9772780.950088-0.151357
2-0.1032190.4105990.1440441.454274
30.7610380.1216750.4438630.333674
41.494079-0.2051580.313068nan
5-2.5529900.6536190.864436-0.742165
62.269755-1.4543660.045759-0.187184
71.5327791.4693590.1549470.378163
8-0.887786-1.980796-0.3479120.156349
91.2302911.202380-0.387327-0.302303
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 53, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df2.style.bar(subset=['A', 'B'], color='#d65f5f')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Additional keyword arguments give more control on centering and positioning, and you can pass a list of `[color_negative, color_positive]` to highlight lower and higher values or a matplotlib colormap.\n", + "\n", + "To showcase an example here's how you can change the above with the new `align` option, combined with setting `vmin` and `vmax` limits, the `width` of the figure, and underlying css `props` of cells, leaving space to display the text and the bars. We also use `text_gradient` to color the text the same as the bars using a matplotlib colormap (although in this case the visualization is probably better without this additional effect)." + ] + }, + { + "cell_type": "code", + "execution_count": 54, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:38.752993Z", + "iopub.status.busy": "2023-01-25T14:32:38.752901Z", + "iopub.status.idle": "2023-01-25T14:32:38.771171Z", + "shell.execute_reply": "2023-01-25T14:32:38.770928Z" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
 ABCD
01.7640.4002.241
11.868-0.9770.950-0.151
2-0.1030.4110.1441.454
30.7610.1220.4440.334
41.494-0.2050.313
5-2.5530.6540.864-0.742
62.270-1.4540.046-0.187
71.5331.4690.1550.378
8-0.888-1.981-0.3480.156
91.2301.202-0.387-0.302
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 54, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df2.style.format('{:.3f}', na_rep=\"\")\\\n", + " .bar(align=0, vmin=-2.5, vmax=2.5, cmap=\"bwr\", height=50,\n", + " width=60, props=\"width: 120px; border-right: 1px solid black;\")\\\n", + " .text_gradient(cmap=\"bwr\", vmin=-2.5, vmax=2.5)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The following example aims to give a highlight of the behavior of the new align options:" + ] + }, + { + "cell_type": "code", + "execution_count": 55, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:38.772653Z", + "iopub.status.busy": "2023-01-25T14:32:38.772570Z", + "iopub.status.idle": "2023-01-25T14:32:38.805213Z", + "shell.execute_reply": "2023-01-25T14:32:38.804963Z" + }, + "nbsphinx": "hidden" + }, + "outputs": [], + "source": [ + "# Hide the construction of the display chart from the user\n", + "import pandas as pd\n", + "from IPython.display import HTML\n", + "\n", + "# Test series\n", + "test1 = pd.Series([-100,-60,-30,-20], name='All Negative')\n", + "test2 = pd.Series([-10,-5,0,90], name='Both Pos and Neg')\n", + "test3 = pd.Series([10,20,50,100], name='All Positive')\n", + "test4 = pd.Series([100, 103, 101, 102], name='Large Positive')\n", + "\n", + "\n", + "head = \"\"\"\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "\n", + "\"\"\"\n", + "\n", + "aligns = ['left', 'right', 'zero', 'mid', 'mean', 99]\n", + "for align in aligns:\n", + " row = \"\".format(align)\n", + " for series in [test1,test2,test3, test4]:\n", + " s = series.copy()\n", + " s.name=''\n", + " row += \"\".format(s.to_frame().style.hide(axis='index').bar(align=align, \n", + " color=['#d65f5f', '#5fba7d'], \n", + " width=100).to_html()) #testn['width']\n", + " row += ''\n", + " head += row\n", + " \n", + "head+= \"\"\"\n", + "\n", + "
AlignAll NegativeBoth Neg and PosAll PositiveLarge Positive
{}{}
\"\"\"" + ] + }, + { + "cell_type": "code", + "execution_count": 56, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:38.806727Z", + "iopub.status.busy": "2023-01-25T14:32:38.806640Z", + "iopub.status.idle": "2023-01-25T14:32:38.819385Z", + "shell.execute_reply": "2023-01-25T14:32:38.819133Z" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "\n", + "\n", + "\n", + "
AlignAll NegativeBoth Neg and PosAll PositiveLarge Positive
left\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
-100
-60
-30
-20
\n", + "
\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
-10
-5
0
90
\n", + "
\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
10
20
50
100
\n", + "
\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
100
103
101
102
\n", + "
right\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
-100
-60
-30
-20
\n", + "
\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
-10
-5
0
90
\n", + "
\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
10
20
50
100
\n", + "
\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
100
103
101
102
\n", + "
zero\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
-100
-60
-30
-20
\n", + "
\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
-10
-5
0
90
\n", + "
\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
10
20
50
100
\n", + "
\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
100
103
101
102
\n", + "
mid\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
-100
-60
-30
-20
\n", + "
\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
-10
-5
0
90
\n", + "
\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
10
20
50
100
\n", + "
\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
100
103
101
102
\n", + "
mean\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
-100
-60
-30
-20
\n", + "
\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
-10
-5
0
90
\n", + "
\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
10
20
50
100
\n", + "
\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
100
103
101
102
\n", + "
99\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
-100
-60
-30
-20
\n", + "
\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
-10
-5
0
90
\n", + "
\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
10
20
50
100
\n", + "
\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
100
103
101
102
\n", + "
" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 56, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "HTML(head)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Sharing styles" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Say you have a lovely style built up for a DataFrame, and now you want to apply the same style to a second DataFrame. Export the style with `df1.style.export`, and import it on the second DataFrame with `df1.style.set`" + ] + }, + { + "cell_type": "code", + "execution_count": 57, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:38.820959Z", + "iopub.status.busy": "2023-01-25T14:32:38.820858Z", + "iopub.status.idle": "2023-01-25T14:32:38.835897Z", + "shell.execute_reply": "2023-01-25T14:32:38.835647Z" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
ABCD
1.7640520.400157nan2.240893
1.867558-0.9772780.950088-0.151357
-0.1032190.4105990.1440441.454274
0.7610380.1216750.4438630.333674
1.494079-0.2051580.313068nan
-2.5529900.6536190.864436-0.742165
2.269755-1.4543660.045759-0.187184
1.5327791.4693590.1549470.378163
-0.887786-1.980796-0.3479120.156349
1.2302911.202380-0.387327-0.302303
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 57, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "style1 = df2.style\\\n", + " .applymap(style_negative, props='color:red;')\\\n", + " .applymap(lambda v: 'opacity: 20%;' if (v < 0.3) and (v > -0.3) else None)\\\n", + " .set_table_styles([{\"selector\": \"th\", \"props\": \"color: blue;\"}])\\\n", + " .hide(axis=\"index\")\n", + "style1" + ] + }, + { + "cell_type": "code", + "execution_count": 58, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:38.837321Z", + "iopub.status.busy": "2023-01-25T14:32:38.837244Z", + "iopub.status.idle": "2023-01-25T14:32:38.851485Z", + "shell.execute_reply": "2023-01-25T14:32:38.851245Z" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
c1c2c3c4
-1.048553-1.420018-1.7062701.950775
-0.509652-0.438074-1.2527950.777490
-1.613898-0.212740-0.8954670.386902
-0.510805-1.180632-0.0281820.428332
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 58, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "style2 = df3.style\n", + "style2.use(style1.export())\n", + "style2" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Notice that you're able to share the styles even though they're data aware. The styles are re-evaluated on the new DataFrame they've been `use`d upon." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Limitations\n", + "\n", + "- DataFrame only (use `Series.to_frame().style`)\n", + "- The index and columns do not need to be unique, but certain styling functions can only work with unique indexes.\n", + "- No large repr, and construction performance isn't great; although we have some [HTML optimizations](#Optimization)\n", + "- You can only apply styles, you can't insert new HTML entities, except via subclassing." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Other Fun and Useful Stuff\n", + "\n", + "Here are a few interesting examples." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Widgets\n", + "\n", + "`Styler` interacts pretty well with widgets. If you're viewing this online instead of running the notebook yourself, you're missing out on interactively adjusting the color palette." + ] + }, + { + "cell_type": "code", + "execution_count": 59, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:38.853142Z", + "iopub.status.busy": "2023-01-25T14:32:38.853040Z", + "iopub.status.idle": "2023-01-25T14:32:38.890100Z", + "shell.execute_reply": "2023-01-25T14:32:38.889853Z" + } + }, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "9ca04a7e7da044a99aa6dc1e31c0127a", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "interactive(children=(IntSlider(value=179, description='h_neg', max=359), IntSlider(value=179, description='h_…" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "from ipywidgets import widgets\n", + "@widgets.interact\n", + "def f(h_neg=(0, 359, 1), h_pos=(0, 359), s=(0., 99.9), l=(0., 99.9)):\n", + " return df2.style.background_gradient(\n", + " cmap=sns.palettes.diverging_palette(h_neg=h_neg, h_pos=h_pos, s=s, l=l,\n", + " as_cmap=True)\n", + " )" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Magnify" + ] + }, + { + "cell_type": "code", + "execution_count": 60, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:38.891938Z", + "iopub.status.busy": "2023-01-25T14:32:38.891846Z", + "iopub.status.idle": "2023-01-25T14:32:38.905592Z", + "shell.execute_reply": "2023-01-25T14:32:38.905316Z" + } + }, + "outputs": [], + "source": [ + "def magnify():\n", + " return [dict(selector=\"th\",\n", + " props=[(\"font-size\", \"4pt\")]),\n", + " dict(selector=\"td\",\n", + " props=[('padding', \"0em 0em\")]),\n", + " dict(selector=\"th:hover\",\n", + " props=[(\"font-size\", \"12pt\")]),\n", + " dict(selector=\"tr:hover td:hover\",\n", + " props=[('max-width', '200px'),\n", + " ('font-size', '12pt')])\n", + "]" + ] + }, + { + "cell_type": "code", + "execution_count": 61, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:38.907210Z", + "iopub.status.busy": "2023-01-25T14:32:38.907120Z", + "iopub.status.idle": "2023-01-25T14:32:38.941622Z", + "shell.execute_reply": "2023-01-25T14:32:38.941329Z" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Hover to magnify
 0123456789101112131415161718192021222324
00.231.03-0.84-0.59-0.96-0.22-0.621.84-2.050.87-0.92-0.232.15-1.330.08-1.251.20-1.051.06-0.422.29-2.592.820.68-1.58
1-1.751.56-1.13-1.101.030.00-2.463.45-1.661.27-0.52-0.021.52-1.09-1.86-1.13-0.68-0.810.35-0.061.79-2.822.260.780.44
2-0.653.22-1.760.522.20-0.37-3.003.73-1.872.460.21-0.24-0.10-0.78-3.02-0.82-0.21-0.230.86-0.681.45-4.893.031.910.61
3-1.623.71-2.310.434.17-0.43-3.864.16-2.151.080.120.60-0.890.27-3.67-2.71-0.31-1.591.35-1.830.91-5.802.812.110.28
4-3.354.48-1.86-1.705.19-1.02-3.814.72-0.721.08-0.180.83-0.22-1.08-4.27-2.88-0.97-1.781.53-1.802.21-6.343.342.492.09
5-0.844.23-1.65-2.005.34-0.99-4.133.94-1.06-0.941.240.09-1.78-0.11-4.45-0.85-2.06-1.350.80-1.631.54-6.512.802.143.77
6-0.745.35-2.11-1.134.20-1.85-3.203.76-3.22-1.230.340.57-1.820.54-4.43-1.83-4.03-2.62-0.20-4.681.93-8.463.342.525.81
7-0.444.69-2.30-0.215.93-2.63-1.835.46-4.50-3.16-1.730.180.110.04-5.99-0.45-6.20-3.890.71-3.950.67-7.262.973.396.66
80.925.80-3.33-0.655.99-3.19-1.835.63-3.53-1.30-1.610.82-2.45-0.40-6.06-0.52-6.60-3.48-0.04-4.600.51-5.853.232.405.08
90.385.54-4.49-0.807.05-2.64-0.445.35-1.96-0.33-0.800.26-3.37-0.82-6.05-2.61-8.45-4.450.41-4.711.89-6.932.143.005.16
102.065.84-3.90-0.987.78-2.49-0.595.59-2.22-0.71-0.461.80-2.790.48-5.97-3.44-7.77-5.49-0.70-4.61-0.52-7.721.545.025.81
111.864.47-2.17-1.385.90-0.490.025.78-1.04-0.600.491.96-1.471.88-5.92-4.55-8.15-3.42-2.24-4.33-1.17-7.901.365.315.83
123.194.22-3.06-2.275.93-2.640.336.72-2.84-0.201.892.63-1.530.75-5.27-4.53-7.57-2.85-2.17-4.78-1.13-8.992.116.425.60
132.314.45-3.87-2.056.76-3.25-2.177.99-2.56-0.800.712.33-0.16-0.46-5.10-3.79-7.58-4.000.33-3.67-1.05-8.712.475.876.71
143.784.33-3.88-1.586.22-3.23-1.465.57-2.93-0.33-0.971.723.610.29-4.21-4.10-6.68-4.50-2.19-2.43-1.64-9.363.366.117.53
155.645.31-3.98-2.265.91-3.30-1.035.68-3.06-0.33-1.162.194.201.01-3.22-4.31-5.74-4.44-2.30-1.36-1.20-11.272.596.695.91
164.084.34-2.44-3.306.04-2.52-0.475.28-4.841.580.230.105.791.80-3.13-3.85-5.53-2.97-2.13-1.15-0.56-13.132.076.164.94
175.644.57-3.53-3.766.58-2.58-0.756.58-4.783.63-0.290.565.762.05-2.27-2.31-4.95-3.16-3.06-2.430.84-12.573.567.364.70
185.995.82-2.85-4.157.12-3.32-1.217.93-4.851.44-0.630.357.470.87-1.52-2.09-4.23-2.55-2.46-2.891.90-9.743.437.074.39
194.036.23-4.10-4.117.19-4.10-1.526.53-5.21-0.240.011.166.43-1.97-2.64-1.66-5.20-3.25-2.87-1.651.64-10.662.837.483.94
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 61, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "np.random.seed(25)\n", + "cmap = cmap=sns.diverging_palette(5, 250, as_cmap=True)\n", + "bigdf = pd.DataFrame(np.random.randn(20, 25)).cumsum()\n", + "\n", + "bigdf.style.background_gradient(cmap, axis=1)\\\n", + " .set_properties(**{'max-width': '80px', 'font-size': '1pt'})\\\n", + " .set_caption(\"Hover to magnify\")\\\n", + " .format(precision=2)\\\n", + " .set_table_styles(magnify())" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Sticky Headers\n", + "\n", + "If you display a large matrix or DataFrame in a notebook, but you want to always see the column and row headers you can use the [.set_sticky][sticky] method which manipulates the table styles CSS.\n", + "\n", + "[sticky]: ../reference/api/pandas.io.formats.style.Styler.set_sticky.rst" + ] + }, + { + "cell_type": "code", + "execution_count": 62, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:38.943198Z", + "iopub.status.busy": "2023-01-25T14:32:38.943110Z", + "iopub.status.idle": "2023-01-25T14:32:38.971766Z", + "shell.execute_reply": "2023-01-25T14:32:38.971504Z" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
 0123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
0-0.773866-0.240521-0.2171651.1736090.6863900.0083580.6962320.1731660.6204980.5040670.428066-0.0518240.7199150.0571650.562808-0.3695360.4833990.620765-0.354342-1.469471-1.9372660.038031-1.518162-0.4175990.3867170.7161930.4899610.7339570.9144150.6798940.255448-0.5083380.332030-0.111107-0.251983-1.4566200.4096301.062320-0.5771150.718796-0.399260-1.3113890.6491220.0915660.6288720.297894-0.142290-0.542291-0.9142901.1445140.3135841.1826351.214235-0.416446-1.653940-2.5507870.4424730.052127-0.464469-0.5238520.989726-1.325539-0.199687-1.2267270.2900181.1645740.817841-0.3095090.4965990.943536-0.091850-2.8026582.126219-0.5211610.288098-0.454663-1.676143-0.357661-0.7889600.185911-0.0171062.4540201.832706-0.911743-0.655873-0.000514-2.2269970.677285-0.140249-0.408407-0.8386650.4822281.243458-0.477394-0.220343-2.4639660.237325-0.3073801.1724780.819492
10.405906-0.9789191.2675260.145250-1.066786-2.114192-1.128346-1.0825230.3722160.004127-0.2119840.937326-0.935890-1.7041180.611789-1.0300150.636123-1.5061931.7366091.3929581.0094240.3532660.697339-0.2974240.428702-0.145346-0.333553-0.9746990.6653140.9719440.121950-1.4396681.0188081.442399-0.199585-1.1659160.6456561.436466-0.9212151.293906-2.7064431.460928-0.8231970.292952-1.4489920.026692-0.9758830.3928230.4421660.7457411.187982-0.2185700.3052880.054932-1.476953-0.1144340.0141030.825394-0.060654-0.4136880.9748361.3392101.0348380.0407750.7050010.0177961.867681-0.3901732.2852772.311464-0.085070-0.6481150.576300-0.790087-1.183798-1.334558-0.4541180.3193021.7064880.8304290.502476-0.0796310.4146350.3325110.042935-0.1609100.918553-0.292697-1.303834-0.1996040.871023-1.370681-0.205701-0.4929731.123083-0.081842-0.1185270.245838-0.315742-0.511806
20.011470-0.0361041.399603-0.418176-0.412229-1.234783-1.1215001.196478-0.5695220.422022-0.2204840.8043382.892667-0.511055-0.168722-1.477996-1.9699170.4713541.6985480.137105-0.7620520.199379-0.964346-0.2566921.2652750.848762-0.7841611.863776-0.3555690.8545520.768061-2.075718-2.5010691.1098680.957545-0.6832760.3077640.7330731.706250-1.1180910.374961-1.414503-0.524183-1.6626960.6879210.5217321.451396-0.833491-0.362796-1.174444-0.813893-0.8932200.7707431.156647-0.6474440.1259290.513600-0.5378741.992052-1.946584-0.1047590.484779-0.290936-0.4410750.542993-1.0500381.6304820.239771-1.1773100.464804-0.9669950.6460860.4868991.022196-2.267827-1.2296161.3138051.0732922.324940-0.542720-1.5042920.777643-0.6185530.0113421.3850621.363552-0.5498340.6888961.361288-0.3811370.797812-1.1281980.3692080.5401320.413853-0.200308-0.9691260.981293-0.009783-0.320020
3-0.5748161.4199770.434813-1.101217-1.5862751.9795730.3782980.7823262.1789870.6575640.683774-0.091000-0.059552-0.738908-0.907653-0.7019360.580039-0.6187570.4536841.665382-0.1523210.8800770.571073-0.6047360.5323590.515031-0.959844-0.8871840.4357810.862093-0.956321-0.6259090.1944720.4424900.526503-0.2152740.0907110.9325920.811999-2.4970260.6315450.321418-0.425549-1.0788320.7534440.199790-0.360526-0.013448-0.8194760.8148690.442118-0.972048-0.060603-2.3498251.265445-0.5732570.4291241.0497831.9547730.071883-0.0942090.2656160.9483180.3316451.343401-0.167934-1.105252-0.167077-0.096576-0.838161-0.2085640.3945340.7625331.235357-0.207282-0.202946-0.4680250.2569442.5875841.186697-1.0319031.4283160.658899-0.046582-0.0754221.329359-0.684267-1.5241822.0140613.7709330.647353-1.021377-0.3454930.5828110.7978121.3260201.422857-3.0770070.1840831.478935
4-0.6001421.929561-2.346771-0.669700-1.1652580.8147880.444449-0.5767580.3530910.4088930.091391-2.2943890.485506-0.081304-0.716272-1.6480101.005361-1.4896030.3630980.758602-1.373847-0.9720571.9885370.3198291.1690600.1465851.0303881.1659841.3695630.730984-1.383696-0.515189-0.808927-1.174651-1.631502-1.123414-0.478155-1.5830671.4190741.6687771.5675170.222103-0.336040-1.3520640.251032-0.4016950.268413-0.012299-0.9189532.921208-0.5815880.6728481.2511361.3822631.4298971.290990-1.272673-0.308611-0.422988-0.6756420.8744411.305736-0.262585-1.099395-0.667101-0.646737-0.556338-0.1965910.119306-0.266455-0.5242672.6509510.097318-0.9746970.1899641.141155-0.0644341.104971-1.508908-0.0318330.803919-0.6592210.9391450.214041-0.5318050.9560600.2493280.637903-0.5101581.850287-0.3484072.001376-0.389643-0.024786-0.4709730.8693390.1706670.5980621.2172621.274013
5-0.389981-0.752441-0.7348713.517318-1.173559-0.0049560.1454192.151368-3.086037-1.5691391.449784-0.868951-1.687716-0.9944011.1532661.803045-0.8190590.8479700.227102-0.5007620.8682101.8235401.161007-0.307606-0.7134160.363560-0.8221622.427681-0.129537-0.0787161.345644-1.2860940.237242-0.1360560.596664-1.4123811.2063410.2998600.7052380.142412-1.0593820.8334681.060015-0.527045-1.135732-1.140983-0.779540-0.640875-1.217196-1.6756630.241263-0.273322-1.697936-0.5949430.1011541.391735-0.4269531.008344-0.8185771.924570-0.578900-0.457395-1.0967050.418522-0.1556230.169706-2.5337060.0189041.4341600.7440950.647626-0.7703092.329141-0.141547-1.7615940.702091-1.531450-0.788427-0.184622-1.9423211.5301130.5034061.105845-0.935120-1.115483-2.2497621.3071350.788412-0.4410910.0735610.812101-0.9161461.573714-0.3095080.4999870.1875940.5589130.9032460.317901-0.809797
61.1282481.516826-0.186735-0.6681571.132259-0.246648-0.8551670.7322830.9318021.318684-1.198418-1.1493180.586321-1.171937-0.6077312.7537471.479287-1.136365-0.0204850.320444-1.9557550.660402-1.5453710.200519-0.0172631.6346860.5992460.4629890.0237210.2255460.170972-0.027496-0.061233-0.566411-0.6695670.6016180.503656-0.678253-2.907108-1.7171230.3976311.3001080.215821-0.593075-0.225944-0.9460571.0003080.3931601.342074-0.370687-0.166413-0.419814-0.2559311.7894780.2823780.742260-0.0504981.4153090.838166-1.400292-0.937976-1.4991480.8018590.2248240.2835720.643703-1.1984650.5272060.2152020.4370481.3128680.7412430.0779880.0061230.1903700.018007-1.026036-2.378430-1.0699490.8438221.289216-1.423369-0.4628870.197330-0.9350760.4412710.414643-0.377887-0.5305150.6215921.0095720.5697180.175291-0.656279-0.112273-0.392137-1.043558-0.467318-0.384329-2.009207
70.6585980.101830-0.6827810.229349-0.3056570.4048770.252244-0.837784-0.0396240.3294570.7516941.469070-0.1571991.032628-0.584639-0.9255440.342474-0.9693630.133480-0.385974-0.6002780.2819390.8685791.129803-0.0418980.9611930.131521-0.792889-1.2857370.073934-1.333315-1.0441251.2773381.4922570.4113791.771805-1.1111281.123233-1.0194491.738357-0.690764-0.120710-0.421359-0.727294-0.857759-0.069436-0.328334-0.5581801.063474-0.519133-0.4969021.089589-1.6158010.080174-0.229938-0.498420-0.6246150.059481-0.093158-1.784549-0.503789-0.1405280.002653-0.4849300.055914-0.680948-0.9942711.2770520.0376512.155421-0.4375890.6964040.417752-0.5447851.1906900.9782620.7521020.5044720.139853-0.505089-0.264975-1.6031940.7318470.010903-1.165346-0.125195-1.032685-0.4655201.5148080.3047620.7934140.314635-1.6382790.111737-0.7770370.2517831.126303-0.8087980.422064-0.349264
8-0.356362-0.0892270.6093730.542382-0.768681-0.0480742.015458-1.5523510.2515521.4596350.9497070.339465-0.0013721.7985891.5591630.2317830.423141-0.3105300.3537952.173336-0.196247-0.375636-0.8582210.2584100.6564300.9608191.1378931.5534050.038981-0.632038-0.132009-1.834997-0.242576-0.297879-0.441559-0.7696910.224077-0.1530090.519526-0.6801880.5358510.671496-0.1830640.3012341.288256-2.478240-0.3604030.424067-0.834659-0.128464-0.489013-0.014888-1.461230-1.435223-1.3198021.0836750.979140-0.3752911.110189-1.0113510.587886-0.822775-1.1838651.4551731.1343280.239403-0.837991-1.1309320.7831681.8455201.437072-1.1984431.3790982.1291130.260096-0.0119750.0433020.7229411.028152-0.2358061.145245-1.3595980.2321890.503712-0.614264-0.530606-2.435803-0.255238-0.0644230.7846430.2563460.1280231.414103-1.1186590.8773530.5005610.463651-2.034512-0.981683-0.691944
9-1.113376-1.1694020.680539-1.5342121.653817-1.295181-0.5668260.4770141.4133710.5171051.401153-0.8726850.8309570.181507-0.1456160.694592-0.7512080.3244440.681973-0.0549720.917776-1.024810-0.206446-0.6001130.8528051.455109-0.0797690.0760760.207699-1.850458-0.124124-0.610871-0.8833620.219049-0.685094-0.645330-0.242805-0.7756020.2330702.422642-1.423040-0.5824210.968304-0.701025-0.1678500.2772641.3012310.301205-3.081249-0.5628680.192944-0.6645920.5656860.190913-0.841858-1.856545-1.0227771.2959680.4519210.6599550.065818-0.3195860.253495-1.144646-0.4834040.5559020.8070690.7141960.6611960.0536670.346833-1.288977-0.386734-1.2621270.477495-0.494034-0.9114141.152963-0.342365-0.1601870.470054-0.853063-1.387949-0.257257-1.030690-0.1102100.328911-0.5559230.987713-0.5019572.069887-0.0675030.316029-1.5062322.2016210.492097-0.085193-0.9778221.039147-0.653932
10-0.405638-1.402027-1.1662421.3061840.856283-1.236170-0.646721-1.4740640.0829600.090310-0.1699770.4063450.915427-0.9745030.2716371.539184-0.098866-0.5251491.0639330.085827-0.1296220.947959-0.072496-0.2375920.0125491.0657610.996596-0.1724812.583139-0.028578-0.2548561.328794-1.5929512.434350-0.341500-0.307719-1.333273-1.1008450.2090971.7347770.6396320.424779-0.1293270.905029-0.4829091.731628-2.783425-0.333677-0.1108951.212636-0.2084120.4271171.3485630.0438591.772519-1.4161060.4011550.8071570.303427-1.2462880.178774-0.066126-1.8622881.2412950.377021-0.822320-0.7490141.4636521.602268-1.0438771.185290-0.565783-1.0768791.360241-0.1219910.9910431.0079520.450185-0.7443761.388876-0.316847-0.841655-1.056842-0.5002260.0969591.176896-2.9396521.7922130.3163400.3032181.024967-0.590871-0.453326-0.795981-0.393301-0.374372-1.2701991.6183721.197727-0.914863
11-0.6252100.2889110.288374-1.372667-0.591395-0.4789421.335664-0.459855-1.615975-1.1896760.374767-2.4887330.586656-1.4220080.4960301.911128-0.560660-0.499614-0.372171-1.8330690.237124-0.9444460.9121400.359790-1.3592350.166966-0.047107-0.279789-0.594454-0.739013-1.5276450.4016681.791252-2.7748480.5238732.2075850.488999-0.3392830.1317110.0184091.186551-0.4243181.554994-0.205917-0.9349750.654102-1.227761-0.461025-0.421201-0.058615-0.5845630.336913-0.477102-1.3814630.757745-0.2689680.0348701.2316860.2366001.234720-0.0402470.0295821.0349050.380204-0.012108-0.859511-0.990340-1.205172-1.0301780.4266760.497796-0.8768080.9579630.1730160.131612-1.003556-1.069908-1.7992071.429598-0.116015-1.4549800.2619170.4444120.2732900.8441150.218745-1.033350-1.1882950.0583730.800523-1.6270680.8616510.871018-0.003733-0.2433540.9472960.5094060.0445460.2668961.337165
120.699142-1.9280330.1053631.0423220.715206-0.7637830.098798-1.1578980.1341050.0420410.6748260.165649-1.622970-3.1312740.597649-1.8803310.663980-0.256033-1.5240580.4927990.2211630.429622-0.6595841.264506-0.032131-2.114907-0.2640430.457835-0.676837-0.6290030.489145-0.5516860.942622-0.512043-0.4558930.021244-0.178035-2.498073-0.1712920.323510-0.545163-0.668909-0.1500310.521620-0.4289800.6764630.369081-0.7248320.7935421.2374220.4012752.1415230.2490120.486755-0.1632740.592222-0.292600-0.5471680.619104-0.0136050.7767340.1314241.189480-0.666317-0.9390361.1055150.6214521.586605-0.7609701.6496460.2831991.275812-0.4520120.301361-0.976951-0.268106-0.079255-1.2583322.216658-1.175988-0.863497-1.653022-0.5615140.4507530.4172000.094676-2.2310541.316862-0.4774410.646654-0.2002521.074354-0.0581760.1209900.222522-0.1795070.421655-0.914341-0.2341780.741524
130.9327141.423761-1.2808350.347882-0.863171-0.8525801.0449332.0945360.8062060.416201-1.1095030.145302-0.9968710.325456-0.6050811.1753261.6450540.293432-2.7668221.0328490.079115-1.4141321.4633762.3354860.411951-0.0485430.159284-0.651554-1.0931281.568390-0.077807-2.390779-0.842346-0.229675-0.999072-1.367219-0.792042-1.8785751.4514521.266250-0.7343150.2661520.735523-0.4308600.2298640.850083-2.2412411.0638500.289409-0.3543600.113063-0.1730061.3869981.8862360.587119-0.9611330.3992951.4615600.3108230.280220-0.879103-1.3263480.003337-1.085908-0.4367232.1119260.1060680.6155972.152996-0.1961550.025747-0.0390610.656823-0.3471052.5139791.7580701.288473-0.739185-0.691592-0.098728-0.2763860.4899810.516278-0.8382580.596673-0.3310530.521174-0.1450230.836693-1.0921660.361733-1.1699810.0467310.655377-0.7568521.285805-0.0950190.3602531.3706210.083010
140.8888932.288725-1.0323320.212273-1.0918261.6924981.0253670.5508540.679430-1.335712-0.7983412.265351-1.0069382.0597610.420266-1.1896570.5066740.260847-0.5331450.7272671.4122761.482106-0.9962580.588641-0.412642-0.920733-0.8746910.8390020.501668-0.342493-0.533806-2.146352-0.5973390.1157260.850683-0.7522390.377263-0.5619820.262783-0.356676-0.3674620.753611-1.267414-1.330698-0.5364530.840938-0.763108-0.268100-0.6774241.6068310.151732-2.0857011.2192960.4008630.591165-1.4852131.5019791.196569-0.2141540.339554-0.0344461.1764520.546340-1.255630-1.309210-0.4454370.189437-0.7374630.843767-0.605632-0.0607770.4093101.285569-0.6226381.0181930.8806800.046805-1.818058-0.8098290.8752240.409569-0.116621-1.2389193.305724-0.024121-1.7565001.3289580.507593-0.866554-2.240848-0.661376-0.6718240.215720-0.2963260.4814020.829645-0.7210251.2639140.549047-1.234945
15-1.9788380.721823-0.559067-1.2352430.420716-0.5988450.359576-0.619366-1.757772-1.1562510.7052120.875071-1.0203760.394760-0.1479700.2302491.3552031.7944882.678058-0.153565-0.460959-0.098108-1.407930-2.4877021.8230140.099873-0.517603-0.509311-1.833175-0.9009060.459493-0.6554401.466122-1.531389-0.4221060.4214220.5786150.2597950.018941-0.1687261.611107-1.586550-1.3849410.8583771.0332421.7013431.748344-0.371182-0.8435752.089641-0.345430-1.7405560.141915-2.1971380.689569-0.1500250.2874560.654016-1.521919-0.918008-0.5875280.2306360.2626370.6156740.600044-0.494699-0.7430890.220026-0.2422070.528216-0.328174-1.536517-1.476640-1.162114-1.2602221.106252-1.467408-0.349341-1.8412170.031296-0.076475-0.3533830.8075450.779064-2.398417-0.2678281.5497340.8143970.284770-0.6593690.761040-0.7220670.8103321.5012951.440865-1.367459-0.700301-1.5406620.159837-0.625415
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 62, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "bigdf = pd.DataFrame(np.random.randn(16, 100))\n", + "bigdf.style.set_sticky(axis=\"index\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "It is also possible to stick MultiIndexes and even only specific levels." + ] + }, + { + "cell_type": "code", + "execution_count": 63, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:38.973641Z", + "iopub.status.busy": "2023-01-25T14:32:38.973532Z", + "iopub.status.idle": "2023-01-25T14:32:39.002186Z", + "shell.execute_reply": "2023-01-25T14:32:39.001920Z" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
   0123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
A00-0.773866-0.240521-0.2171651.1736090.6863900.0083580.6962320.1731660.6204980.5040670.428066-0.0518240.7199150.0571650.562808-0.3695360.4833990.620765-0.354342-1.469471-1.9372660.038031-1.518162-0.4175990.3867170.7161930.4899610.7339570.9144150.6798940.255448-0.5083380.332030-0.111107-0.251983-1.4566200.4096301.062320-0.5771150.718796-0.399260-1.3113890.6491220.0915660.6288720.297894-0.142290-0.542291-0.9142901.1445140.3135841.1826351.214235-0.416446-1.653940-2.5507870.4424730.052127-0.464469-0.5238520.989726-1.325539-0.199687-1.2267270.2900181.1645740.817841-0.3095090.4965990.943536-0.091850-2.8026582.126219-0.5211610.288098-0.454663-1.676143-0.357661-0.7889600.185911-0.0171062.4540201.832706-0.911743-0.655873-0.000514-2.2269970.677285-0.140249-0.408407-0.8386650.4822281.243458-0.477394-0.220343-2.4639660.237325-0.3073801.1724780.819492
10.405906-0.9789191.2675260.145250-1.066786-2.114192-1.128346-1.0825230.3722160.004127-0.2119840.937326-0.935890-1.7041180.611789-1.0300150.636123-1.5061931.7366091.3929581.0094240.3532660.697339-0.2974240.428702-0.145346-0.333553-0.9746990.6653140.9719440.121950-1.4396681.0188081.442399-0.199585-1.1659160.6456561.436466-0.9212151.293906-2.7064431.460928-0.8231970.292952-1.4489920.026692-0.9758830.3928230.4421660.7457411.187982-0.2185700.3052880.054932-1.476953-0.1144340.0141030.825394-0.060654-0.4136880.9748361.3392101.0348380.0407750.7050010.0177961.867681-0.3901732.2852772.311464-0.085070-0.6481150.576300-0.790087-1.183798-1.334558-0.4541180.3193021.7064880.8304290.502476-0.0796310.4146350.3325110.042935-0.1609100.918553-0.292697-1.303834-0.1996040.871023-1.370681-0.205701-0.4929731.123083-0.081842-0.1185270.245838-0.315742-0.511806
20.011470-0.0361041.399603-0.418176-0.412229-1.234783-1.1215001.196478-0.5695220.422022-0.2204840.8043382.892667-0.511055-0.168722-1.477996-1.9699170.4713541.6985480.137105-0.7620520.199379-0.964346-0.2566921.2652750.848762-0.7841611.863776-0.3555690.8545520.768061-2.075718-2.5010691.1098680.957545-0.6832760.3077640.7330731.706250-1.1180910.374961-1.414503-0.524183-1.6626960.6879210.5217321.451396-0.833491-0.362796-1.174444-0.813893-0.8932200.7707431.156647-0.6474440.1259290.513600-0.5378741.992052-1.946584-0.1047590.484779-0.290936-0.4410750.542993-1.0500381.6304820.239771-1.1773100.464804-0.9669950.6460860.4868991.022196-2.267827-1.2296161.3138051.0732922.324940-0.542720-1.5042920.777643-0.6185530.0113421.3850621.363552-0.5498340.6888961.361288-0.3811370.797812-1.1281980.3692080.5401320.413853-0.200308-0.9691260.981293-0.009783-0.320020
3-0.5748161.4199770.434813-1.101217-1.5862751.9795730.3782980.7823262.1789870.6575640.683774-0.091000-0.059552-0.738908-0.907653-0.7019360.580039-0.6187570.4536841.665382-0.1523210.8800770.571073-0.6047360.5323590.515031-0.959844-0.8871840.4357810.862093-0.956321-0.6259090.1944720.4424900.526503-0.2152740.0907110.9325920.811999-2.4970260.6315450.321418-0.425549-1.0788320.7534440.199790-0.360526-0.013448-0.8194760.8148690.442118-0.972048-0.060603-2.3498251.265445-0.5732570.4291241.0497831.9547730.071883-0.0942090.2656160.9483180.3316451.343401-0.167934-1.105252-0.167077-0.096576-0.838161-0.2085640.3945340.7625331.235357-0.207282-0.202946-0.4680250.2569442.5875841.186697-1.0319031.4283160.658899-0.046582-0.0754221.329359-0.684267-1.5241822.0140613.7709330.647353-1.021377-0.3454930.5828110.7978121.3260201.422857-3.0770070.1840831.478935
10-0.6001421.929561-2.346771-0.669700-1.1652580.8147880.444449-0.5767580.3530910.4088930.091391-2.2943890.485506-0.081304-0.716272-1.6480101.005361-1.4896030.3630980.758602-1.373847-0.9720571.9885370.3198291.1690600.1465851.0303881.1659841.3695630.730984-1.383696-0.515189-0.808927-1.174651-1.631502-1.123414-0.478155-1.5830671.4190741.6687771.5675170.222103-0.336040-1.3520640.251032-0.4016950.268413-0.012299-0.9189532.921208-0.5815880.6728481.2511361.3822631.4298971.290990-1.272673-0.308611-0.422988-0.6756420.8744411.305736-0.262585-1.099395-0.667101-0.646737-0.556338-0.1965910.119306-0.266455-0.5242672.6509510.097318-0.9746970.1899641.141155-0.0644341.104971-1.508908-0.0318330.803919-0.6592210.9391450.214041-0.5318050.9560600.2493280.637903-0.5101581.850287-0.3484072.001376-0.389643-0.024786-0.4709730.8693390.1706670.5980621.2172621.274013
1-0.389981-0.752441-0.7348713.517318-1.173559-0.0049560.1454192.151368-3.086037-1.5691391.449784-0.868951-1.687716-0.9944011.1532661.803045-0.8190590.8479700.227102-0.5007620.8682101.8235401.161007-0.307606-0.7134160.363560-0.8221622.427681-0.129537-0.0787161.345644-1.2860940.237242-0.1360560.596664-1.4123811.2063410.2998600.7052380.142412-1.0593820.8334681.060015-0.527045-1.135732-1.140983-0.779540-0.640875-1.217196-1.6756630.241263-0.273322-1.697936-0.5949430.1011541.391735-0.4269531.008344-0.8185771.924570-0.578900-0.457395-1.0967050.418522-0.1556230.169706-2.5337060.0189041.4341600.7440950.647626-0.7703092.329141-0.141547-1.7615940.702091-1.531450-0.788427-0.184622-1.9423211.5301130.5034061.105845-0.935120-1.115483-2.2497621.3071350.788412-0.4410910.0735610.812101-0.9161461.573714-0.3095080.4999870.1875940.5589130.9032460.317901-0.809797
21.1282481.516826-0.186735-0.6681571.132259-0.246648-0.8551670.7322830.9318021.318684-1.198418-1.1493180.586321-1.171937-0.6077312.7537471.479287-1.136365-0.0204850.320444-1.9557550.660402-1.5453710.200519-0.0172631.6346860.5992460.4629890.0237210.2255460.170972-0.027496-0.061233-0.566411-0.6695670.6016180.503656-0.678253-2.907108-1.7171230.3976311.3001080.215821-0.593075-0.225944-0.9460571.0003080.3931601.342074-0.370687-0.166413-0.419814-0.2559311.7894780.2823780.742260-0.0504981.4153090.838166-1.400292-0.937976-1.4991480.8018590.2248240.2835720.643703-1.1984650.5272060.2152020.4370481.3128680.7412430.0779880.0061230.1903700.018007-1.026036-2.378430-1.0699490.8438221.289216-1.423369-0.4628870.197330-0.9350760.4412710.414643-0.377887-0.5305150.6215921.0095720.5697180.175291-0.656279-0.112273-0.392137-1.043558-0.467318-0.384329-2.009207
30.6585980.101830-0.6827810.229349-0.3056570.4048770.252244-0.837784-0.0396240.3294570.7516941.469070-0.1571991.032628-0.584639-0.9255440.342474-0.9693630.133480-0.385974-0.6002780.2819390.8685791.129803-0.0418980.9611930.131521-0.792889-1.2857370.073934-1.333315-1.0441251.2773381.4922570.4113791.771805-1.1111281.123233-1.0194491.738357-0.690764-0.120710-0.421359-0.727294-0.857759-0.069436-0.328334-0.5581801.063474-0.519133-0.4969021.089589-1.6158010.080174-0.229938-0.498420-0.6246150.059481-0.093158-1.784549-0.503789-0.1405280.002653-0.4849300.055914-0.680948-0.9942711.2770520.0376512.155421-0.4375890.6964040.417752-0.5447851.1906900.9782620.7521020.5044720.139853-0.505089-0.264975-1.6031940.7318470.010903-1.165346-0.125195-1.032685-0.4655201.5148080.3047620.7934140.314635-1.6382790.111737-0.7770370.2517831.126303-0.8087980.422064-0.349264
B00-0.356362-0.0892270.6093730.542382-0.768681-0.0480742.015458-1.5523510.2515521.4596350.9497070.339465-0.0013721.7985891.5591630.2317830.423141-0.3105300.3537952.173336-0.196247-0.375636-0.8582210.2584100.6564300.9608191.1378931.5534050.038981-0.632038-0.132009-1.834997-0.242576-0.297879-0.441559-0.7696910.224077-0.1530090.519526-0.6801880.5358510.671496-0.1830640.3012341.288256-2.478240-0.3604030.424067-0.834659-0.128464-0.489013-0.014888-1.461230-1.435223-1.3198021.0836750.979140-0.3752911.110189-1.0113510.587886-0.822775-1.1838651.4551731.1343280.239403-0.837991-1.1309320.7831681.8455201.437072-1.1984431.3790982.1291130.260096-0.0119750.0433020.7229411.028152-0.2358061.145245-1.3595980.2321890.503712-0.614264-0.530606-2.435803-0.255238-0.0644230.7846430.2563460.1280231.414103-1.1186590.8773530.5005610.463651-2.034512-0.981683-0.691944
1-1.113376-1.1694020.680539-1.5342121.653817-1.295181-0.5668260.4770141.4133710.5171051.401153-0.8726850.8309570.181507-0.1456160.694592-0.7512080.3244440.681973-0.0549720.917776-1.024810-0.206446-0.6001130.8528051.455109-0.0797690.0760760.207699-1.850458-0.124124-0.610871-0.8833620.219049-0.685094-0.645330-0.242805-0.7756020.2330702.422642-1.423040-0.5824210.968304-0.701025-0.1678500.2772641.3012310.301205-3.081249-0.5628680.192944-0.6645920.5656860.190913-0.841858-1.856545-1.0227771.2959680.4519210.6599550.065818-0.3195860.253495-1.144646-0.4834040.5559020.8070690.7141960.6611960.0536670.346833-1.288977-0.386734-1.2621270.477495-0.494034-0.9114141.152963-0.342365-0.1601870.470054-0.853063-1.387949-0.257257-1.030690-0.1102100.328911-0.5559230.987713-0.5019572.069887-0.0675030.316029-1.5062322.2016210.492097-0.085193-0.9778221.039147-0.653932
2-0.405638-1.402027-1.1662421.3061840.856283-1.236170-0.646721-1.4740640.0829600.090310-0.1699770.4063450.915427-0.9745030.2716371.539184-0.098866-0.5251491.0639330.085827-0.1296220.947959-0.072496-0.2375920.0125491.0657610.996596-0.1724812.583139-0.028578-0.2548561.328794-1.5929512.434350-0.341500-0.307719-1.333273-1.1008450.2090971.7347770.6396320.424779-0.1293270.905029-0.4829091.731628-2.783425-0.333677-0.1108951.212636-0.2084120.4271171.3485630.0438591.772519-1.4161060.4011550.8071570.303427-1.2462880.178774-0.066126-1.8622881.2412950.377021-0.822320-0.7490141.4636521.602268-1.0438771.185290-0.565783-1.0768791.360241-0.1219910.9910431.0079520.450185-0.7443761.388876-0.316847-0.841655-1.056842-0.5002260.0969591.176896-2.9396521.7922130.3163400.3032181.024967-0.590871-0.453326-0.795981-0.393301-0.374372-1.2701991.6183721.197727-0.914863
3-0.6252100.2889110.288374-1.372667-0.591395-0.4789421.335664-0.459855-1.615975-1.1896760.374767-2.4887330.586656-1.4220080.4960301.911128-0.560660-0.499614-0.372171-1.8330690.237124-0.9444460.9121400.359790-1.3592350.166966-0.047107-0.279789-0.594454-0.739013-1.5276450.4016681.791252-2.7748480.5238732.2075850.488999-0.3392830.1317110.0184091.186551-0.4243181.554994-0.205917-0.9349750.654102-1.227761-0.461025-0.421201-0.058615-0.5845630.336913-0.477102-1.3814630.757745-0.2689680.0348701.2316860.2366001.234720-0.0402470.0295821.0349050.380204-0.012108-0.859511-0.990340-1.205172-1.0301780.4266760.497796-0.8768080.9579630.1730160.131612-1.003556-1.069908-1.7992071.429598-0.116015-1.4549800.2619170.4444120.2732900.8441150.218745-1.033350-1.1882950.0583730.800523-1.6270680.8616510.871018-0.003733-0.2433540.9472960.5094060.0445460.2668961.337165
100.699142-1.9280330.1053631.0423220.715206-0.7637830.098798-1.1578980.1341050.0420410.6748260.165649-1.622970-3.1312740.597649-1.8803310.663980-0.256033-1.5240580.4927990.2211630.429622-0.6595841.264506-0.032131-2.114907-0.2640430.457835-0.676837-0.6290030.489145-0.5516860.942622-0.512043-0.4558930.021244-0.178035-2.498073-0.1712920.323510-0.545163-0.668909-0.1500310.521620-0.4289800.6764630.369081-0.7248320.7935421.2374220.4012752.1415230.2490120.486755-0.1632740.592222-0.292600-0.5471680.619104-0.0136050.7767340.1314241.189480-0.666317-0.9390361.1055150.6214521.586605-0.7609701.6496460.2831991.275812-0.4520120.301361-0.976951-0.268106-0.079255-1.2583322.216658-1.175988-0.863497-1.653022-0.5615140.4507530.4172000.094676-2.2310541.316862-0.4774410.646654-0.2002521.074354-0.0581760.1209900.222522-0.1795070.421655-0.914341-0.2341780.741524
10.9327141.423761-1.2808350.347882-0.863171-0.8525801.0449332.0945360.8062060.416201-1.1095030.145302-0.9968710.325456-0.6050811.1753261.6450540.293432-2.7668221.0328490.079115-1.4141321.4633762.3354860.411951-0.0485430.159284-0.651554-1.0931281.568390-0.077807-2.390779-0.842346-0.229675-0.999072-1.367219-0.792042-1.8785751.4514521.266250-0.7343150.2661520.735523-0.4308600.2298640.850083-2.2412411.0638500.289409-0.3543600.113063-0.1730061.3869981.8862360.587119-0.9611330.3992951.4615600.3108230.280220-0.879103-1.3263480.003337-1.085908-0.4367232.1119260.1060680.6155972.152996-0.1961550.025747-0.0390610.656823-0.3471052.5139791.7580701.288473-0.739185-0.691592-0.098728-0.2763860.4899810.516278-0.8382580.596673-0.3310530.521174-0.1450230.836693-1.0921660.361733-1.1699810.0467310.655377-0.7568521.285805-0.0950190.3602531.3706210.083010
20.8888932.288725-1.0323320.212273-1.0918261.6924981.0253670.5508540.679430-1.335712-0.7983412.265351-1.0069382.0597610.420266-1.1896570.5066740.260847-0.5331450.7272671.4122761.482106-0.9962580.588641-0.412642-0.920733-0.8746910.8390020.501668-0.342493-0.533806-2.146352-0.5973390.1157260.850683-0.7522390.377263-0.5619820.262783-0.356676-0.3674620.753611-1.267414-1.330698-0.5364530.840938-0.763108-0.268100-0.6774241.6068310.151732-2.0857011.2192960.4008630.591165-1.4852131.5019791.196569-0.2141540.339554-0.0344461.1764520.546340-1.255630-1.309210-0.4454370.189437-0.7374630.843767-0.605632-0.0607770.4093101.285569-0.6226381.0181930.8806800.046805-1.818058-0.8098290.8752240.409569-0.116621-1.2389193.305724-0.024121-1.7565001.3289580.507593-0.866554-2.240848-0.661376-0.6718240.215720-0.2963260.4814020.829645-0.7210251.2639140.549047-1.234945
3-1.9788380.721823-0.559067-1.2352430.420716-0.5988450.359576-0.619366-1.757772-1.1562510.7052120.875071-1.0203760.394760-0.1479700.2302491.3552031.7944882.678058-0.153565-0.460959-0.098108-1.407930-2.4877021.8230140.099873-0.517603-0.509311-1.833175-0.9009060.459493-0.6554401.466122-1.531389-0.4221060.4214220.5786150.2597950.018941-0.1687261.611107-1.586550-1.3849410.8583771.0332421.7013431.748344-0.371182-0.8435752.089641-0.345430-1.7405560.141915-2.1971380.689569-0.1500250.2874560.654016-1.521919-0.918008-0.5875280.2306360.2626370.6156740.600044-0.494699-0.7430890.220026-0.2422070.528216-0.328174-1.536517-1.476640-1.162114-1.2602221.106252-1.467408-0.349341-1.8412170.031296-0.076475-0.3533830.8075450.779064-2.398417-0.2678281.5497340.8143970.284770-0.6593690.761040-0.7220670.8103321.5012951.440865-1.367459-0.700301-1.5406620.159837-0.625415
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 63, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "bigdf.index = pd.MultiIndex.from_product([[\"A\",\"B\"],[0,1],[0,1,2,3]])\n", + "bigdf.style.set_sticky(axis=\"index\", pixel_size=18, levels=[1,2])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### HTML Escaping\n", + "\n", + "Suppose you have to display HTML within HTML, that can be a bit of pain when the renderer can't distinguish. You can use the `escape` formatting option to handle this, and even use it within a formatter that contains HTML itself." + ] + }, + { + "cell_type": "code", + "execution_count": 64, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:39.004072Z", + "iopub.status.busy": "2023-01-25T14:32:39.003971Z", + "iopub.status.idle": "2023-01-25T14:32:39.017834Z", + "shell.execute_reply": "2023-01-25T14:32:39.017579Z" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
 012
0
\"&other\"
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 64, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df4 = pd.DataFrame([['
', '\"&other\"', '']])\n", + "df4.style" + ] + }, + { + "cell_type": "code", + "execution_count": 65, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:39.019342Z", + "iopub.status.busy": "2023-01-25T14:32:39.019261Z", + "iopub.status.idle": "2023-01-25T14:32:39.032461Z", + "shell.execute_reply": "2023-01-25T14:32:39.032207Z" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
 012
0<div></div>"&other"<span></span>
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 65, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df4.style.format(escape=\"html\")" + ] + }, + { + "cell_type": "code", + "execution_count": 66, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:39.033933Z", + "iopub.status.busy": "2023-01-25T14:32:39.033845Z", + "iopub.status.idle": "2023-01-25T14:32:39.046802Z", + "shell.execute_reply": "2023-01-25T14:32:39.046562Z" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
 012
0<div></div>"&other"<span></span>
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 66, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df4.style.format('{}', escape=\"html\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Export to Excel\n", + "\n", + "Some support (*since version 0.20.0*) is available for exporting styled `DataFrames` to Excel worksheets using the `OpenPyXL` or `XlsxWriter` engines. CSS2.2 properties handled include:\n", + "\n", + "- `background-color`\n", + "- `border-style` properties\n", + "- `border-width` properties\n", + "- `border-color` properties\n", + "- `color`\n", + "- `font-family`\n", + "- `font-style`\n", + "- `font-weight`\n", + "- `text-align`\n", + "- `text-decoration`\n", + "- `vertical-align`\n", + "- `white-space: nowrap`\n", + "\n", + "\n", + "- Shorthand and side-specific border properties are supported (e.g. `border-style` and `border-left-style`) as well as the `border` shorthands for all sides (`border: 1px solid green`) or specified sides (`border-left: 1px solid green`). Using a `border` shorthand will override any border properties set before it (See [CSS Working Group](https://drafts.csswg.org/css-backgrounds/#border-shorthands) for more details)\n", + "\n", + "\n", + "- Only CSS2 named colors and hex colors of the form `#rgb` or `#rrggbb` are currently supported.\n", + "- The following pseudo CSS properties are also available to set Excel specific style properties:\n", + " - `number-format`\n", + " - `border-style` (for Excel-specific styles: \"hair\", \"mediumDashDot\", \"dashDotDot\", \"mediumDashDotDot\", \"dashDot\", \"slantDashDot\", or \"mediumDashed\")\n", + "\n", + "Table level styles, and data cell CSS-classes are not included in the export to Excel: individual cells must have their properties mapped by the `Styler.apply` and/or `Styler.applymap` methods." + ] + }, + { + "cell_type": "code", + "execution_count": 67, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:39.048287Z", + "iopub.status.busy": "2023-01-25T14:32:39.048204Z", + "iopub.status.idle": "2023-01-25T14:32:39.141871Z", + "shell.execute_reply": "2023-01-25T14:32:39.141606Z" + } + }, + "outputs": [], + "source": [ + "df2.style.\\\n", + " applymap(style_negative, props='color:red;').\\\n", + " highlight_max(axis=0).\\\n", + " to_excel('styled.xlsx', engine='openpyxl')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "A screenshot of the output:\n", + "\n", + "![Excel spreadsheet with styled DataFrame](../_static/style-excel.png)\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Export to LaTeX\n", + "\n", + "There is support (*since version 1.3.0*) to export `Styler` to LaTeX. The documentation for the [.to_latex][latex] method gives further detail and numerous examples.\n", + "\n", + "[latex]: ../reference/api/pandas.io.formats.style.Styler.to_latex.rst" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## More About CSS and HTML\n", + "\n", + "Cascading Style Sheet (CSS) language, which is designed to influence how a browser renders HTML elements, has its own peculiarities. It never reports errors: it just silently ignores them and doesn't render your objects how you intend so can sometimes be frustrating. Here is a very brief primer on how ``Styler`` creates HTML and interacts with CSS, with advice on common pitfalls to avoid." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### CSS Classes and Ids\n", + "\n", + "The precise structure of the CSS `class` attached to each cell is as follows.\n", + "\n", + "- Cells with Index and Column names include `index_name` and `level` where `k` is its level in a MultiIndex\n", + "- Index label cells include\n", + " + `row_heading`\n", + " + `level` where `k` is the level in a MultiIndex\n", + " + `row` where `m` is the numeric position of the row\n", + "- Column label cells include\n", + " + `col_heading`\n", + " + `level` where `k` is the level in a MultiIndex\n", + " + `col` where `n` is the numeric position of the column\n", + "- Data cells include\n", + " + `data`\n", + " + `row`, where `m` is the numeric position of the cell.\n", + " + `col`, where `n` is the numeric position of the cell.\n", + "- Blank cells include `blank`\n", + "- Trimmed cells include `col_trim` or `row_trim`\n", + "\n", + "The structure of the `id` is `T_uuid_level_row_col` where `level` is used only on headings, and headings will only have either `row` or `col` whichever is needed. By default we've also prepended each row/column identifier with a UUID unique to each DataFrame so that the style from one doesn't collide with the styling from another within the same notebook or page. You can read more about the use of UUIDs in [Optimization](#Optimization).\n", + "\n", + "We can see example of the HTML by calling the [.to_html()][tohtml] method.\n", + "\n", + "[tohtml]: ../reference/api/pandas.io.formats.style.Styler.to_html.rst" + ] + }, + { + "cell_type": "code", + "execution_count": 68, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:39.143742Z", + "iopub.status.busy": "2023-01-25T14:32:39.143631Z", + "iopub.status.idle": "2023-01-25T14:32:39.158365Z", + "shell.execute_reply": "2023-01-25T14:32:39.158123Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
 c1c2
i112
i234
\n", + "\n" + ] + } + ], + "source": [ + "print(pd.DataFrame([[1,2],[3,4]], index=['i1', 'i2'], columns=['c1', 'c2']).style.to_html())" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### CSS Hierarchies\n", + "\n", + "The examples have shown that when CSS styles overlap, the one that comes last in the HTML render, takes precedence. So the following yield different results:" + ] + }, + { + "cell_type": "code", + "execution_count": 69, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:39.159850Z", + "iopub.status.busy": "2023-01-25T14:32:39.159771Z", + "iopub.status.idle": "2023-01-25T14:32:39.174906Z", + "shell.execute_reply": "2023-01-25T14:32:39.174636Z" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
 0
0text
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 69, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df4 = pd.DataFrame([['text']])\n", + "df4.style.applymap(lambda x: 'color:green;')\\\n", + " .applymap(lambda x: 'color:red;')" + ] + }, + { + "cell_type": "code", + "execution_count": 70, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:39.176453Z", + "iopub.status.busy": "2023-01-25T14:32:39.176346Z", + "iopub.status.idle": "2023-01-25T14:32:39.191218Z", + "shell.execute_reply": "2023-01-25T14:32:39.190956Z" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
 0
0text
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 70, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df4.style.applymap(lambda x: 'color:red;')\\\n", + " .applymap(lambda x: 'color:green;')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This is only true for CSS rules that are equivalent in hierarchy, or importance. You can read more about [CSS specificity here](https://www.w3schools.com/css/css_specificity.asp) but for our purposes it suffices to summarize the key points:\n", + "\n", + "A CSS importance score for each HTML element is derived by starting at zero and adding:\n", + "\n", + " - 1000 for an inline style attribute\n", + " - 100 for each ID\n", + " - 10 for each attribute, class or pseudo-class\n", + " - 1 for each element name or pseudo-element\n", + " \n", + "Let's use this to describe the action of the following configurations" + ] + }, + { + "cell_type": "code", + "execution_count": 71, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:39.192714Z", + "iopub.status.busy": "2023-01-25T14:32:39.192634Z", + "iopub.status.idle": "2023-01-25T14:32:39.207243Z", + "shell.execute_reply": "2023-01-25T14:32:39.206983Z" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
 0
0text
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 71, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df4.style.set_uuid('a_')\\\n", + " .set_table_styles([{'selector': 'td', 'props': 'color:red;'}])\\\n", + " .applymap(lambda x: 'color:green;')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This text is red because the generated selector `#T_a_ td` is worth 101 (ID plus element), whereas `#T_a_row0_col0` is only worth 100 (ID), so is considered inferior even though in the HTML it comes after the previous." + ] + }, + { + "cell_type": "code", + "execution_count": 72, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:39.208837Z", + "iopub.status.busy": "2023-01-25T14:32:39.208728Z", + "iopub.status.idle": "2023-01-25T14:32:39.222863Z", + "shell.execute_reply": "2023-01-25T14:32:39.222605Z" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
 0
0text
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 72, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df4.style.set_uuid('b_')\\\n", + " .set_table_styles([{'selector': 'td', 'props': 'color:red;'},\n", + " {'selector': '.cls-1', 'props': 'color:blue;'}])\\\n", + " .applymap(lambda x: 'color:green;')\\\n", + " .set_td_classes(pd.DataFrame([['cls-1']]))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "In the above case the text is blue because the selector `#T_b_ .cls-1` is worth 110 (ID plus class), which takes precedence." + ] + }, + { + "cell_type": "code", + "execution_count": 73, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:39.224293Z", + "iopub.status.busy": "2023-01-25T14:32:39.224213Z", + "iopub.status.idle": "2023-01-25T14:32:39.238734Z", + "shell.execute_reply": "2023-01-25T14:32:39.238466Z" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
 0
0text
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 73, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df4.style.set_uuid('c_')\\\n", + " .set_table_styles([{'selector': 'td', 'props': 'color:red;'},\n", + " {'selector': '.cls-1', 'props': 'color:blue;'},\n", + " {'selector': 'td.data', 'props': 'color:yellow;'}])\\\n", + " .applymap(lambda x: 'color:green;')\\\n", + " .set_td_classes(pd.DataFrame([['cls-1']]))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Now we have created another table style this time the selector `T_c_ td.data` (ID plus element plus class) gets bumped up to 111. \n", + "\n", + "If your style fails to be applied, and its really frustrating, try the `!important` trump card." + ] + }, + { + "cell_type": "code", + "execution_count": 74, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:39.240317Z", + "iopub.status.busy": "2023-01-25T14:32:39.240209Z", + "iopub.status.idle": "2023-01-25T14:32:39.254735Z", + "shell.execute_reply": "2023-01-25T14:32:39.254486Z" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
 0
0text
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 74, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df4.style.set_uuid('d_')\\\n", + " .set_table_styles([{'selector': 'td', 'props': 'color:red;'},\n", + " {'selector': '.cls-1', 'props': 'color:blue;'},\n", + " {'selector': 'td.data', 'props': 'color:yellow;'}])\\\n", + " .applymap(lambda x: 'color:green !important;')\\\n", + " .set_td_classes(pd.DataFrame([['cls-1']]))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Finally got that green text after all!" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Extensibility\n", + "\n", + "The core of pandas is, and will remain, its \"high-performance, easy-to-use data structures\".\n", + "With that in mind, we hope that `DataFrame.style` accomplishes two goals\n", + "\n", + "- Provide an API that is pleasing to use interactively and is \"good enough\" for many tasks\n", + "- Provide the foundations for dedicated libraries to build on\n", + "\n", + "If you build a great library on top of this, let us know and we'll [link](https://pandas.pydata.org/pandas-docs/stable/ecosystem.html) to it.\n", + "\n", + "### Subclassing\n", + "\n", + "If the default template doesn't quite suit your needs, you can subclass Styler and extend or override the template.\n", + "We'll show an example of extending the default template to insert a custom header before each table." + ] + }, + { + "cell_type": "code", + "execution_count": 75, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:39.256259Z", + "iopub.status.busy": "2023-01-25T14:32:39.256174Z", + "iopub.status.idle": "2023-01-25T14:32:39.268879Z", + "shell.execute_reply": "2023-01-25T14:32:39.268627Z" + } + }, + "outputs": [], + "source": [ + "from jinja2 import Environment, ChoiceLoader, FileSystemLoader\n", + "from IPython.display import HTML\n", + "from pandas.io.formats.style import Styler" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We'll use the following template:" + ] + }, + { + "cell_type": "code", + "execution_count": 76, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:39.270397Z", + "iopub.status.busy": "2023-01-25T14:32:39.270323Z", + "iopub.status.idle": "2023-01-25T14:32:39.283516Z", + "shell.execute_reply": "2023-01-25T14:32:39.283277Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{% extends \"html_table.tpl\" %}\n", + "{% block table %}\n", + "

{{ table_title|default(\"My Table\") }}

\n", + "{{ super() }}\n", + "{% endblock table %}\n", + "\n" + ] + } + ], + "source": [ + "with open(\"templates/myhtml.tpl\") as f:\n", + " print(f.read())" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Now that we've created a template, we need to set up a subclass of ``Styler`` that\n", + "knows about it." + ] + }, + { + "cell_type": "code", + "execution_count": 77, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:39.285003Z", + "iopub.status.busy": "2023-01-25T14:32:39.284923Z", + "iopub.status.idle": "2023-01-25T14:32:39.298378Z", + "shell.execute_reply": "2023-01-25T14:32:39.298123Z" + } + }, + "outputs": [], + "source": [ + "class MyStyler(Styler):\n", + " env = Environment(\n", + " loader=ChoiceLoader([\n", + " FileSystemLoader(\"templates\"), # contains ours\n", + " Styler.loader, # the default\n", + " ])\n", + " )\n", + " template_html_table = env.get_template(\"myhtml.tpl\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Notice that we include the original loader in our environment's loader.\n", + "That's because we extend the original template, so the Jinja environment needs\n", + "to be able to find it.\n", + "\n", + "Now we can use that custom styler. It's `__init__` takes a DataFrame." + ] + }, + { + "cell_type": "code", + "execution_count": 78, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:39.299907Z", + "iopub.status.busy": "2023-01-25T14:32:39.299823Z", + "iopub.status.idle": "2023-01-25T14:32:39.319847Z", + "shell.execute_reply": "2023-01-25T14:32:39.319602Z" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "\n", + "

My Table

\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + " \n", + "\n", + "\n", + "\n", + " \n", + "\n", + "\n", + "\n", + " \n", + "\n", + "\n", + "\n", + " \n", + "\n", + "\n", + "\n", + " \n", + "\n", + "\n", + "\n", + " \n", + "\n", + "\n", + "\n", + " \n", + "\n", + "\n", + "\n", + " \n", + "\n", + "\n", + "\n", + " \n", + "\n", + "\n", + "\n", + " \n", + "\n", + "\n", + " \n", + "\n", + "\n", + "\n", + " \n", + "\n", + "\n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + "\n", + " \n", + "\n", + "\n", + "\n", + " \n", + "\n", + "\n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + "\n", + " \n", + "\n", + "\n", + "\n", + " \n", + "\n", + "\n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + "\n", + " \n", + "\n", + "\n", + "\n", + " \n", + "\n", + "\n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + "\n", + " \n", + "\n", + "\n", + "\n", + " \n", + "\n", + "
  c1c2c3c4
Ar1-1.048553-1.420018-1.7062701.950775
r2-0.509652-0.438074-1.2527950.777490
Br1-1.613898-0.212740-0.8954670.386902
r2-0.510805-1.180632-0.0281820.428332
\n", + "\n", + "\n" + ], + "text/plain": [ + "<__main__.MyStyler at 0x15986b100>" + ] + }, + "execution_count": 78, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "MyStyler(df3)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Our custom template accepts a `table_title` keyword. We can provide the value in the `.to_html` method." + ] + }, + { + "cell_type": "code", + "execution_count": 79, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:39.321297Z", + "iopub.status.busy": "2023-01-25T14:32:39.321218Z", + "iopub.status.idle": "2023-01-25T14:32:39.335660Z", + "shell.execute_reply": "2023-01-25T14:32:39.335413Z" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "\n", + "

Extending Example

\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + " \n", + "\n", + "\n", + "\n", + " \n", + "\n", + "\n", + "\n", + " \n", + "\n", + "\n", + "\n", + " \n", + "\n", + "\n", + "\n", + " \n", + "\n", + "\n", + "\n", + " \n", + "\n", + "\n", + "\n", + " \n", + "\n", + "\n", + "\n", + " \n", + "\n", + "\n", + "\n", + " \n", + "\n", + "\n", + "\n", + " \n", + "\n", + "\n", + " \n", + "\n", + "\n", + "\n", + " \n", + "\n", + "\n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + "\n", + " \n", + "\n", + "\n", + "\n", + " \n", + "\n", + "\n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + "\n", + " \n", + "\n", + "\n", + "\n", + " \n", + "\n", + "\n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + "\n", + " \n", + "\n", + "\n", + "\n", + " \n", + "\n", + "\n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + "\n", + " \n", + "\n", + "\n", + "\n", + " \n", + "\n", + "
  c1c2c3c4
Ar1-1.048553-1.420018-1.7062701.950775
r2-0.509652-0.438074-1.2527950.777490
Br1-1.613898-0.212740-0.8954670.386902
r2-0.510805-1.180632-0.0281820.428332
\n", + "\n", + "\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 79, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "HTML(MyStyler(df3).to_html(table_title=\"Extending Example\"))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "For convenience, we provide the `Styler.from_custom_template` method that does the same as the custom subclass." + ] + }, + { + "cell_type": "code", + "execution_count": 80, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:39.337154Z", + "iopub.status.busy": "2023-01-25T14:32:39.337069Z", + "iopub.status.idle": "2023-01-25T14:32:39.359505Z", + "shell.execute_reply": "2023-01-25T14:32:39.359234Z" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "\n", + "

Another Title

\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + " \n", + "\n", + "\n", + "\n", + " \n", + "\n", + "\n", + "\n", + " \n", + "\n", + "\n", + "\n", + " \n", + "\n", + "\n", + "\n", + " \n", + "\n", + "\n", + "\n", + " \n", + "\n", + "\n", + "\n", + " \n", + "\n", + "\n", + "\n", + " \n", + "\n", + "\n", + "\n", + " \n", + "\n", + "\n", + "\n", + " \n", + "\n", + "\n", + " \n", + "\n", + "\n", + "\n", + " \n", + "\n", + "\n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + "\n", + " \n", + "\n", + "\n", + "\n", + " \n", + "\n", + "\n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + "\n", + " \n", + "\n", + "\n", + "\n", + " \n", + "\n", + "\n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + "\n", + " \n", + "\n", + "\n", + "\n", + " \n", + "\n", + "\n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + "\n", + " \n", + "\n", + "\n", + "\n", + " \n", + "\n", + "
  c1c2c3c4
Ar1-1.048553-1.420018-1.7062701.950775
r2-0.509652-0.438074-1.2527950.777490
Br1-1.613898-0.212740-0.8954670.386902
r2-0.510805-1.180632-0.0281820.428332
\n", + "\n", + "\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 80, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "EasyStyler = Styler.from_custom_template(\"templates\", \"myhtml.tpl\")\n", + "HTML(EasyStyler(df3).to_html(table_title=\"Another Title\"))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Template Structure\n", + "\n", + "Here's the template structure for the both the style generation template and the table generation template:" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Style template:" + ] + }, + { + "cell_type": "code", + "execution_count": 81, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:39.361130Z", + "iopub.status.busy": "2023-01-25T14:32:39.361016Z", + "iopub.status.idle": "2023-01-25T14:32:39.375038Z", + "shell.execute_reply": "2023-01-25T14:32:39.374778Z" + }, + "nbsphinx": "hidden" + }, + "outputs": [], + "source": [ + "with open(\"templates/html_style_structure.html\") as f:\n", + " style_structure = f.read()" + ] + }, + { + "cell_type": "code", + "execution_count": 82, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:39.376468Z", + "iopub.status.busy": "2023-01-25T14:32:39.376388Z", + "iopub.status.idle": "2023-01-25T14:32:39.388926Z", + "shell.execute_reply": "2023-01-25T14:32:39.388689Z" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "\n", + "
before_style
\n", + "
style\n", + "
<style type="text/css">
\n", + "
table_styles
\n", + "
before_cellstyle
\n", + "
cellstyle
\n", + "
</style>
\n", + "
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 82, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "HTML(style_structure)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Table template:" + ] + }, + { + "cell_type": "code", + "execution_count": 83, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:39.390367Z", + "iopub.status.busy": "2023-01-25T14:32:39.390279Z", + "iopub.status.idle": "2023-01-25T14:32:39.402874Z", + "shell.execute_reply": "2023-01-25T14:32:39.402618Z" + }, + "nbsphinx": "hidden" + }, + "outputs": [], + "source": [ + "with open(\"templates/html_table_structure.html\") as f:\n", + " table_structure = f.read()" + ] + }, + { + "cell_type": "code", + "execution_count": 84, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:39.404290Z", + "iopub.status.busy": "2023-01-25T14:32:39.404190Z", + "iopub.status.idle": "2023-01-25T14:32:39.416613Z", + "shell.execute_reply": "2023-01-25T14:32:39.416388Z" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "\n", + "
before_table
\n", + "\n", + "
table\n", + "
<table ...>
\n", + "
caption
\n", + "\n", + "
thead\n", + "
before_head_rows
\n", + "
head_tr (loop over headers)
\n", + "
after_head_rows
\n", + "
\n", + "\n", + "
tbody\n", + "
before_rows
\n", + "
tr (loop over data rows)
\n", + "
after_rows
\n", + "
\n", + "
</table>
\n", + "
\n", + "\n", + "
after_table
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 84, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "HTML(table_structure)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "See the template in the [GitHub repo](https://github.com/pandas-dev/pandas) for more details." + ] + }, + { + "cell_type": "code", + "execution_count": 85, + "metadata": { + "execution": { + "iopub.execute_input": "2023-01-25T14:32:39.418110Z", + "iopub.status.busy": "2023-01-25T14:32:39.418031Z", + "iopub.status.idle": "2023-01-25T14:32:39.429900Z", + "shell.execute_reply": "2023-01-25T14:32:39.429653Z" + }, + "nbsphinx": "hidden" + }, + "outputs": [], + "source": [ + "# # Hack to get the same style in the notebook as the\n", + "# # main site. This is hidden in the docs.\n", + "# from IPython.display import HTML\n", + "# with open(\"themes/nature_with_gtoc/static/nature.css_t\") as f:\n", + "# css = f.read()\n", + " \n", + "# HTML(''.format(css))" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.7" + }, + "widgets": { + "application/vnd.jupyter.widget-state+json": { + "state": { + "03cc60499bd6413f83ca0aeef1ee3127": { + "model_module": "@jupyter-widgets/controls", + "model_module_version": "1.5.0", + "model_name": "FloatSliderModel", + "state": { + "_dom_classes": [], + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "FloatSliderModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/controls", + "_view_module_version": "1.5.0", + "_view_name": "FloatSliderView", + "continuous_update": true, + "description": "", + "description_tooltip": null, + "disabled": false, + "layout": "IPY_MODEL_a653b4b8ecee44789c2168105b6b4ac1", + "max": 99.9, + "min": 0.0, + "orientation": "horizontal", + "readout": true, + "readout_format": ".2f", + "step": 0.1, + "style": "IPY_MODEL_d38ed46cf67f4270a86a4b8d2a333242", + "value": 49.95 + } + }, + "19c78c6691d34efc8302c28a1cf3ef4f": { + "model_module": "@jupyter-widgets/base", + "model_module_version": "1.2.0", + "model_name": "LayoutModel", + "state": { + "_model_module": "@jupyter-widgets/base", + "_model_module_version": "1.2.0", + "_model_name": "LayoutModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "LayoutView", + "align_content": null, + "align_items": null, + "align_self": null, + "border": null, + "bottom": null, + "display": null, + "flex": null, + "flex_flow": null, + "grid_area": null, + "grid_auto_columns": null, + "grid_auto_flow": null, + "grid_auto_rows": null, + "grid_column": null, + "grid_gap": null, + "grid_row": null, + "grid_template_areas": null, + "grid_template_columns": null, + "grid_template_rows": null, + "height": null, + "justify_content": null, + "justify_items": null, + "left": null, + "margin": null, + "max_height": null, + "max_width": null, + "min_height": null, + "min_width": null, + "object_fit": null, + "object_position": null, + "order": null, + "overflow": null, + "overflow_x": null, + "overflow_y": null, + "padding": null, + "right": null, + "top": null, + "visibility": null, + "width": null + } + }, + "1e7f2a13a3d44cb4908d1952f601d90f": { + "model_module": "@jupyter-widgets/controls", + "model_module_version": "1.5.0", + "model_name": "IntSliderModel", + "state": { + "_dom_classes": [], + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "IntSliderModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/controls", + "_view_module_version": "1.5.0", + "_view_name": "IntSliderView", + "continuous_update": true, + "description": "h_neg", + "description_tooltip": null, + "disabled": false, + "layout": "IPY_MODEL_4db00ffd8bbc444fac8dede2469d743a", + "max": 359, + "min": 0, + "orientation": "horizontal", + "readout": true, + "readout_format": "d", + "step": 1, + "style": "IPY_MODEL_9e5af469fab14fcf81523ee1a7bac2ab", + "value": 179 + } + }, + "2b4d3eeb52584f6f8a44f1077061e19c": { + "model_module": "@jupyter-widgets/controls", + "model_module_version": "1.5.0", + "model_name": "SliderStyleModel", + "state": { + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "SliderStyleModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "StyleView", + "description_width": "", + "handle_color": null + } + }, + "3e46ecb64d66422cb30385f8a2a11edb": { + "model_module": "@jupyter-widgets/output", + "model_module_version": "1.0.0", + "model_name": "OutputModel", + "state": { + "_dom_classes": [], + "_model_module": "@jupyter-widgets/output", + "_model_module_version": "1.0.0", + "_model_name": "OutputModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/output", + "_view_module_version": "1.0.0", + "_view_name": "OutputView", + "layout": "IPY_MODEL_618834f84d1440258917df7846021262", + "msg_id": "", + "outputs": [] + } + }, + "4db00ffd8bbc444fac8dede2469d743a": { + "model_module": "@jupyter-widgets/base", + "model_module_version": "1.2.0", + "model_name": "LayoutModel", + "state": { + "_model_module": "@jupyter-widgets/base", + "_model_module_version": "1.2.0", + "_model_name": "LayoutModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "LayoutView", + "align_content": null, + "align_items": null, + "align_self": null, + "border": null, + "bottom": null, + "display": null, + "flex": null, + "flex_flow": null, + "grid_area": null, + "grid_auto_columns": null, + "grid_auto_flow": null, + "grid_auto_rows": null, + "grid_column": null, + "grid_gap": null, + "grid_row": null, + "grid_template_areas": null, + "grid_template_columns": null, + "grid_template_rows": null, + "height": null, + "justify_content": null, + "justify_items": null, + "left": null, + "margin": null, + "max_height": null, + "max_width": null, + "min_height": null, + "min_width": null, + "object_fit": null, + "object_position": null, + "order": null, + "overflow": null, + "overflow_x": null, + "overflow_y": null, + "padding": null, + "right": null, + "top": null, + "visibility": null, + "width": null + } + }, + "4f5f5d8749bb4ff6aa9b420219dd1c23": { + "model_module": "@jupyter-widgets/controls", + "model_module_version": "1.5.0", + "model_name": "FloatSliderModel", + "state": { + "_dom_classes": [], + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "FloatSliderModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/controls", + "_view_module_version": "1.5.0", + "_view_name": "FloatSliderView", + "continuous_update": true, + "description": "", + "description_tooltip": null, + "disabled": false, + "layout": "IPY_MODEL_d8f1a40b21c34c1e832dd3496bfd7ef6", + "max": 99.9, + "min": 0.0, + "orientation": "horizontal", + "readout": true, + "readout_format": ".2f", + "step": 0.1, + "style": "IPY_MODEL_2b4d3eeb52584f6f8a44f1077061e19c", + "value": 49.95 + } + }, + "5470024c5cdd4d058229278a678a1bc8": { + "model_module": "@jupyter-widgets/controls", + "model_module_version": "1.5.0", + "model_name": "FloatSliderModel", + "state": { + "_dom_classes": [], + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "FloatSliderModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/controls", + "_view_module_version": "1.5.0", + "_view_name": "FloatSliderView", + "continuous_update": true, + "description": "l", + "description_tooltip": null, + "disabled": false, + "layout": "IPY_MODEL_d8f1a40b21c34c1e832dd3496bfd7ef6", + "max": 99.9, + "min": 0.0, + "orientation": "horizontal", + "readout": true, + "readout_format": ".2f", + "step": 0.1, + "style": "IPY_MODEL_2b4d3eeb52584f6f8a44f1077061e19c", + "value": 49.95 + } + }, + "5721ff8684484320a09017bfc24c68c4": { + "model_module": "@jupyter-widgets/base", + "model_module_version": "1.2.0", + "model_name": "LayoutModel", + "state": { + "_model_module": "@jupyter-widgets/base", + "_model_module_version": "1.2.0", + "_model_name": "LayoutModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "LayoutView", + "align_content": null, + "align_items": null, + "align_self": null, + "border": null, + "bottom": null, + "display": null, + "flex": null, + "flex_flow": null, + "grid_area": null, + "grid_auto_columns": null, + "grid_auto_flow": null, + "grid_auto_rows": null, + "grid_column": null, + "grid_gap": null, + "grid_row": null, + "grid_template_areas": null, + "grid_template_columns": null, + "grid_template_rows": null, + "height": null, + "justify_content": null, + "justify_items": null, + "left": null, + "margin": null, + "max_height": null, + "max_width": null, + "min_height": null, + "min_width": null, + "object_fit": null, + "object_position": null, + "order": null, + "overflow": null, + "overflow_x": null, + "overflow_y": null, + "padding": null, + "right": null, + "top": null, + "visibility": null, + "width": null + } + }, + "5ae1c99066914006b2ae4d4991c09d84": { + "model_module": "@jupyter-widgets/output", + "model_module_version": "1.0.0", + "model_name": "OutputModel", + "state": { + "_dom_classes": [], + "_model_module": "@jupyter-widgets/output", + "_model_module_version": "1.0.0", + "_model_name": "OutputModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/output", + "_view_module_version": "1.0.0", + "_view_name": "OutputView", + "layout": "IPY_MODEL_618834f84d1440258917df7846021262", + "msg_id": "", + "outputs": [ + { + "data": { + "text/html": "\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
 ABCD
01.7640520.400157nan2.240893
11.867558-0.9772780.950088-0.151357
2-0.1032190.4105990.1440441.454274
30.7610380.1216750.4438630.333674
41.494079-0.2051580.313068nan
5-2.5529900.6536190.864436-0.742165
62.269755-1.4543660.045759-0.187184
71.5327791.4693590.1549470.378163
8-0.887786-1.980796-0.3479120.156349
91.2302911.202380-0.387327-0.302303
\n", + "text/plain": "" + }, + "metadata": {}, + "output_type": "display_data" + } + ] + } + }, + "5e43fbb84b9540f1a6c6ad76efe2c7c0": { + "model_module": "@jupyter-widgets/controls", + "model_module_version": "1.5.0", + "model_name": "SliderStyleModel", + "state": { + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "SliderStyleModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "StyleView", + "description_width": "", + "handle_color": null + } + }, + "618834f84d1440258917df7846021262": { + "model_module": "@jupyter-widgets/base", + "model_module_version": "1.2.0", + "model_name": "LayoutModel", + "state": { + "_model_module": "@jupyter-widgets/base", + "_model_module_version": "1.2.0", + "_model_name": "LayoutModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "LayoutView", + "align_content": null, + "align_items": null, + "align_self": null, + "border": null, + "bottom": null, + "display": null, + "flex": null, + "flex_flow": null, + "grid_area": null, + "grid_auto_columns": null, + "grid_auto_flow": null, + "grid_auto_rows": null, + "grid_column": null, + "grid_gap": null, + "grid_row": null, + "grid_template_areas": null, + "grid_template_columns": null, + "grid_template_rows": null, + "height": null, + "justify_content": null, + "justify_items": null, + "left": null, + "margin": null, + "max_height": null, + "max_width": null, + "min_height": null, + "min_width": null, + "object_fit": null, + "object_position": null, + "order": null, + "overflow": null, + "overflow_x": null, + "overflow_y": null, + "padding": null, + "right": null, + "top": null, + "visibility": null, + "width": null + } + }, + "64a8388cf50e4ebead4a6f109539f10e": { + "model_module": "@jupyter-widgets/controls", + "model_module_version": "1.5.0", + "model_name": "VBoxModel", + "state": { + "_dom_classes": [ + "widget-interact" + ], + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "VBoxModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/controls", + "_view_module_version": "1.5.0", + "_view_name": "VBoxView", + "box_style": "", + "children": [], + "layout": "IPY_MODEL_19c78c6691d34efc8302c28a1cf3ef4f" + } + }, + "6535634e0b2448f5b641cee4336c1a84": { + "model_module": "@jupyter-widgets/controls", + "model_module_version": "1.5.0", + "model_name": "IntSliderModel", + "state": { + "_dom_classes": [], + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "IntSliderModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/controls", + "_view_module_version": "1.5.0", + "_view_name": "IntSliderView", + "continuous_update": true, + "description": "", + "description_tooltip": null, + "disabled": false, + "layout": "IPY_MODEL_a1bad22bdfb64c0f85a4156e914b5a36", + "max": 359, + "min": 0, + "orientation": "horizontal", + "readout": true, + "readout_format": "d", + "step": 1, + "style": "IPY_MODEL_e49df24ec5e544f19cecf232034f2319", + "value": 179 + } + }, + "77dfb0ad9bd446778dbffc0d8201373b": { + "model_module": "@jupyter-widgets/controls", + "model_module_version": "1.5.0", + "model_name": "SliderStyleModel", + "state": { + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "SliderStyleModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "StyleView", + "description_width": "", + "handle_color": null + } + }, + "7cb492a6543f45b9b0f767ca197b0dc5": { + "model_module": "@jupyter-widgets/base", + "model_module_version": "1.2.0", + "model_name": "LayoutModel", + "state": { + "_model_module": "@jupyter-widgets/base", + "_model_module_version": "1.2.0", + "_model_name": "LayoutModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "LayoutView", + "align_content": null, + "align_items": null, + "align_self": null, + "border": null, + "bottom": null, + "display": null, + "flex": null, + "flex_flow": null, + "grid_area": null, + "grid_auto_columns": null, + "grid_auto_flow": null, + "grid_auto_rows": null, + "grid_column": null, + "grid_gap": null, + "grid_row": null, + "grid_template_areas": null, + "grid_template_columns": null, + "grid_template_rows": null, + "height": null, + "justify_content": null, + "justify_items": null, + "left": null, + "margin": null, + "max_height": null, + "max_width": null, + "min_height": null, + "min_width": null, + "object_fit": null, + "object_position": null, + "order": null, + "overflow": null, + "overflow_x": null, + "overflow_y": null, + "padding": null, + "right": null, + "top": null, + "visibility": null, + "width": null + } + }, + "9ca04a7e7da044a99aa6dc1e31c0127a": { + "model_module": "@jupyter-widgets/controls", + "model_module_version": "1.5.0", + "model_name": "VBoxModel", + "state": { + "_dom_classes": [ + "widget-interact" + ], + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "VBoxModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/controls", + "_view_module_version": "1.5.0", + "_view_name": "VBoxView", + "box_style": "", + "children": [ + "IPY_MODEL_1e7f2a13a3d44cb4908d1952f601d90f", + "IPY_MODEL_a72d733698d94389824fed752fb35e9c", + "IPY_MODEL_c1d450968de641ee86032e20cc08acd1", + "IPY_MODEL_5470024c5cdd4d058229278a678a1bc8", + "IPY_MODEL_5ae1c99066914006b2ae4d4991c09d84" + ], + "layout": "IPY_MODEL_19c78c6691d34efc8302c28a1cf3ef4f" + } + }, + "9e5af469fab14fcf81523ee1a7bac2ab": { + "model_module": "@jupyter-widgets/controls", + "model_module_version": "1.5.0", + "model_name": "SliderStyleModel", + "state": { + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "SliderStyleModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "StyleView", + "description_width": "", + "handle_color": null + } + }, + "a1bad22bdfb64c0f85a4156e914b5a36": { + "model_module": "@jupyter-widgets/base", + "model_module_version": "1.2.0", + "model_name": "LayoutModel", + "state": { + "_model_module": "@jupyter-widgets/base", + "_model_module_version": "1.2.0", + "_model_name": "LayoutModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "LayoutView", + "align_content": null, + "align_items": null, + "align_self": null, + "border": null, + "bottom": null, + "display": null, + "flex": null, + "flex_flow": null, + "grid_area": null, + "grid_auto_columns": null, + "grid_auto_flow": null, + "grid_auto_rows": null, + "grid_column": null, + "grid_gap": null, + "grid_row": null, + "grid_template_areas": null, + "grid_template_columns": null, + "grid_template_rows": null, + "height": null, + "justify_content": null, + "justify_items": null, + "left": null, + "margin": null, + "max_height": null, + "max_width": null, + "min_height": null, + "min_width": null, + "object_fit": null, + "object_position": null, + "order": null, + "overflow": null, + "overflow_x": null, + "overflow_y": null, + "padding": null, + "right": null, + "top": null, + "visibility": null, + "width": null + } + }, + "a653b4b8ecee44789c2168105b6b4ac1": { + "model_module": "@jupyter-widgets/base", + "model_module_version": "1.2.0", + "model_name": "LayoutModel", + "state": { + "_model_module": "@jupyter-widgets/base", + "_model_module_version": "1.2.0", + "_model_name": "LayoutModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "LayoutView", + "align_content": null, + "align_items": null, + "align_self": null, + "border": null, + "bottom": null, + "display": null, + "flex": null, + "flex_flow": null, + "grid_area": null, + "grid_auto_columns": null, + "grid_auto_flow": null, + "grid_auto_rows": null, + "grid_column": null, + "grid_gap": null, + "grid_row": null, + "grid_template_areas": null, + "grid_template_columns": null, + "grid_template_rows": null, + "height": null, + "justify_content": null, + "justify_items": null, + "left": null, + "margin": null, + "max_height": null, + "max_width": null, + "min_height": null, + "min_width": null, + "object_fit": null, + "object_position": null, + "order": null, + "overflow": null, + "overflow_x": null, + "overflow_y": null, + "padding": null, + "right": null, + "top": null, + "visibility": null, + "width": null + } + }, + "a72d733698d94389824fed752fb35e9c": { + "model_module": "@jupyter-widgets/controls", + "model_module_version": "1.5.0", + "model_name": "IntSliderModel", + "state": { + "_dom_classes": [], + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "IntSliderModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/controls", + "_view_module_version": "1.5.0", + "_view_name": "IntSliderView", + "continuous_update": true, + "description": "h_pos", + "description_tooltip": null, + "disabled": false, + "layout": "IPY_MODEL_a1bad22bdfb64c0f85a4156e914b5a36", + "max": 359, + "min": 0, + "orientation": "horizontal", + "readout": true, + "readout_format": "d", + "step": 1, + "style": "IPY_MODEL_e49df24ec5e544f19cecf232034f2319", + "value": 179 + } + }, + "b539ddb2c2f9406fbe35ab10f4a7564a": { + "model_module": "@jupyter-widgets/base", + "model_module_version": "1.2.0", + "model_name": "LayoutModel", + "state": { + "_model_module": "@jupyter-widgets/base", + "_model_module_version": "1.2.0", + "_model_name": "LayoutModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "LayoutView", + "align_content": null, + "align_items": null, + "align_self": null, + "border": null, + "bottom": null, + "display": null, + "flex": null, + "flex_flow": null, + "grid_area": null, + "grid_auto_columns": null, + "grid_auto_flow": null, + "grid_auto_rows": null, + "grid_column": null, + "grid_gap": null, + "grid_row": null, + "grid_template_areas": null, + "grid_template_columns": null, + "grid_template_rows": null, + "height": null, + "justify_content": null, + "justify_items": null, + "left": null, + "margin": null, + "max_height": null, + "max_width": null, + "min_height": null, + "min_width": null, + "object_fit": null, + "object_position": null, + "order": null, + "overflow": null, + "overflow_x": null, + "overflow_y": null, + "padding": null, + "right": null, + "top": null, + "visibility": null, + "width": null + } + }, + "bff79996e7d14fe8a4991062eb0a2724": { + "model_module": "@jupyter-widgets/base", + "model_module_version": "1.2.0", + "model_name": "LayoutModel", + "state": { + "_model_module": "@jupyter-widgets/base", + "_model_module_version": "1.2.0", + "_model_name": "LayoutModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "LayoutView", + "align_content": null, + "align_items": null, + "align_self": null, + "border": null, + "bottom": null, + "display": null, + "flex": null, + "flex_flow": null, + "grid_area": null, + "grid_auto_columns": null, + "grid_auto_flow": null, + "grid_auto_rows": null, + "grid_column": null, + "grid_gap": null, + "grid_row": null, + "grid_template_areas": null, + "grid_template_columns": null, + "grid_template_rows": null, + "height": null, + "justify_content": null, + "justify_items": null, + "left": null, + "margin": null, + "max_height": null, + "max_width": null, + "min_height": null, + "min_width": null, + "object_fit": null, + "object_position": null, + "order": null, + "overflow": null, + "overflow_x": null, + "overflow_y": null, + "padding": null, + "right": null, + "top": null, + "visibility": null, + "width": null + } + }, + "c1d450968de641ee86032e20cc08acd1": { + "model_module": "@jupyter-widgets/controls", + "model_module_version": "1.5.0", + "model_name": "FloatSliderModel", + "state": { + "_dom_classes": [], + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "FloatSliderModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/controls", + "_view_module_version": "1.5.0", + "_view_name": "FloatSliderView", + "continuous_update": true, + "description": "s", + "description_tooltip": null, + "disabled": false, + "layout": "IPY_MODEL_a653b4b8ecee44789c2168105b6b4ac1", + "max": 99.9, + "min": 0.0, + "orientation": "horizontal", + "readout": true, + "readout_format": ".2f", + "step": 0.1, + "style": "IPY_MODEL_d38ed46cf67f4270a86a4b8d2a333242", + "value": 49.95 + } + }, + "c40aef508c204d968c4026e35961d3f2": { + "model_module": "@jupyter-widgets/base", + "model_module_version": "1.2.0", + "model_name": "LayoutModel", + "state": { + "_model_module": "@jupyter-widgets/base", + "_model_module_version": "1.2.0", + "_model_name": "LayoutModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "LayoutView", + "align_content": null, + "align_items": null, + "align_self": null, + "border": null, + "bottom": null, + "display": null, + "flex": null, + "flex_flow": null, + "grid_area": null, + "grid_auto_columns": null, + "grid_auto_flow": null, + "grid_auto_rows": null, + "grid_column": null, + "grid_gap": null, + "grid_row": null, + "grid_template_areas": null, + "grid_template_columns": null, + "grid_template_rows": null, + "height": null, + "justify_content": null, + "justify_items": null, + "left": null, + "margin": null, + "max_height": null, + "max_width": null, + "min_height": null, + "min_width": null, + "object_fit": null, + "object_position": null, + "order": null, + "overflow": null, + "overflow_x": null, + "overflow_y": null, + "padding": null, + "right": null, + "top": null, + "visibility": null, + "width": null + } + }, + "c62d9dc168a44e3b909bdda066173284": { + "model_module": "@jupyter-widgets/base", + "model_module_version": "1.2.0", + "model_name": "LayoutModel", + "state": { + "_model_module": "@jupyter-widgets/base", + "_model_module_version": "1.2.0", + "_model_name": "LayoutModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "LayoutView", + "align_content": null, + "align_items": null, + "align_self": null, + "border": null, + "bottom": null, + "display": null, + "flex": null, + "flex_flow": null, + "grid_area": null, + "grid_auto_columns": null, + "grid_auto_flow": null, + "grid_auto_rows": null, + "grid_column": null, + "grid_gap": null, + "grid_row": null, + "grid_template_areas": null, + "grid_template_columns": null, + "grid_template_rows": null, + "height": null, + "justify_content": null, + "justify_items": null, + "left": null, + "margin": null, + "max_height": null, + "max_width": null, + "min_height": null, + "min_width": null, + "object_fit": null, + "object_position": null, + "order": null, + "overflow": null, + "overflow_x": null, + "overflow_y": null, + "padding": null, + "right": null, + "top": null, + "visibility": null, + "width": null + } + }, + "d38ed46cf67f4270a86a4b8d2a333242": { + "model_module": "@jupyter-widgets/controls", + "model_module_version": "1.5.0", + "model_name": "SliderStyleModel", + "state": { + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "SliderStyleModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "StyleView", + "description_width": "", + "handle_color": null + } + }, + "d8f1a40b21c34c1e832dd3496bfd7ef6": { + "model_module": "@jupyter-widgets/base", + "model_module_version": "1.2.0", + "model_name": "LayoutModel", + "state": { + "_model_module": "@jupyter-widgets/base", + "_model_module_version": "1.2.0", + "_model_name": "LayoutModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "LayoutView", + "align_content": null, + "align_items": null, + "align_self": null, + "border": null, + "bottom": null, + "display": null, + "flex": null, + "flex_flow": null, + "grid_area": null, + "grid_auto_columns": null, + "grid_auto_flow": null, + "grid_auto_rows": null, + "grid_column": null, + "grid_gap": null, + "grid_row": null, + "grid_template_areas": null, + "grid_template_columns": null, + "grid_template_rows": null, + "height": null, + "justify_content": null, + "justify_items": null, + "left": null, + "margin": null, + "max_height": null, + "max_width": null, + "min_height": null, + "min_width": null, + "object_fit": null, + "object_position": null, + "order": null, + "overflow": null, + "overflow_x": null, + "overflow_y": null, + "padding": null, + "right": null, + "top": null, + "visibility": null, + "width": null + } + }, + "da5e66c57d70414dbe0734a4d36529cc": { + "model_module": "@jupyter-widgets/controls", + "model_module_version": "1.5.0", + "model_name": "SliderStyleModel", + "state": { + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "SliderStyleModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "StyleView", + "description_width": "", + "handle_color": null + } + }, + "e49df24ec5e544f19cecf232034f2319": { + "model_module": "@jupyter-widgets/controls", + "model_module_version": "1.5.0", + "model_name": "SliderStyleModel", + "state": { + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "SliderStyleModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "StyleView", + "description_width": "", + "handle_color": null + } + }, + "f255f802b3184e0b8374ea33f3be4502": { + "model_module": "@jupyter-widgets/controls", + "model_module_version": "1.5.0", + "model_name": "IntSliderModel", + "state": { + "_dom_classes": [], + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "IntSliderModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/controls", + "_view_module_version": "1.5.0", + "_view_name": "IntSliderView", + "continuous_update": true, + "description": "", + "description_tooltip": null, + "disabled": false, + "layout": "IPY_MODEL_4db00ffd8bbc444fac8dede2469d743a", + "max": 359, + "min": 0, + "orientation": "horizontal", + "readout": true, + "readout_format": "d", + "step": 1, + "style": "IPY_MODEL_9e5af469fab14fcf81523ee1a7bac2ab", + "value": 179 + } + }, + "f8e6893e62a24b489d804297d0047c57": { + "model_module": "@jupyter-widgets/controls", + "model_module_version": "1.5.0", + "model_name": "SliderStyleModel", + "state": { + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "SliderStyleModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "StyleView", + "description_width": "", + "handle_color": null + } + } + }, + "version_major": 2, + "version_minor": 0 + } + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 76aa426cc1cee..c1d9b2744b27e 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -637,6 +637,7 @@ Deprecations - :meth:`Index.is_floating` has been deprecated. Use :func:`pandas.api.types.is_float_dtype` instead (:issue:`50042`) - :meth:`Index.holds_integer` has been deprecated. Use :func:`pandas.api.types.infer_dtype` instead (:issue:`50243`) - :meth:`Index.is_categorical` has been deprecated. Use :func:`pandas.api.types.is_categorical_dtype` instead (:issue:`50042`) +- :meth:`Index.is_object` has been deprecated. Use :func:`pandas.api.types.is_object_dtype` instead (:issue:`50042`) - :meth:`Index.is_interval` has been deprecated. Use :func:`pandas.api.types.is_intterval_dtype` instead (:issue:`50042`) - diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index dbd70b8f4db62..5bd6dbc8c16fb 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -2258,7 +2258,7 @@ def is_boolean(self) -> bool: is_integer : Check if the Index only consists of integers (deprecated). is_floating : Check if the Index is a floating type (deprecated). is_numeric : Check if the Index only consists of numeric data. - is_object : Check if the Index is of the object dtype. + is_object : Check if the Index is of the object dtype. (deprecated) is_categorical : Check if the Index holds categorical data. is_interval : Check if the Index holds Interval objects (deprecated). @@ -2302,7 +2302,7 @@ def is_integer(self) -> bool: is_boolean : Check if the Index only consists of booleans (deprecated). is_floating : Check if the Index is a floating type (deprecated). is_numeric : Check if the Index only consists of numeric data. - is_object : Check if the Index is of the object dtype. + is_object : Check if the Index is of the object dtype. (deprecated) is_categorical : Check if the Index holds categorical data (deprecated). is_interval : Check if the Index holds Interval objects (deprecated). @@ -2350,7 +2350,7 @@ def is_floating(self) -> bool: is_boolean : Check if the Index only consists of booleans (deprecated). is_integer : Check if the Index only consists of integers (deprecated). is_numeric : Check if the Index only consists of numeric data. - is_object : Check if the Index is of the object dtype. + is_object : Check if the Index is of the object dtype. (deprecated) is_categorical : Check if the Index holds categorical data (deprecated). is_interval : Check if the Index holds Interval objects (deprecated). @@ -2395,7 +2395,7 @@ def is_numeric(self) -> bool: is_boolean : Check if the Index only consists of booleans (deprecated). is_integer : Check if the Index only consists of integers (deprecated). is_floating : Check if the Index is a floating type (deprecated). - is_object : Check if the Index is of the object dtype. + is_object : Check if the Index is of the object dtype. (deprecated) is_categorical : Check if the Index holds categorical data (deprecated). is_interval : Check if the Index holds Interval objects (deprecated). @@ -2427,6 +2427,8 @@ def is_numeric(self) -> bool: def is_object(self) -> bool: """ Check if the Index is of the object dtype. + .. deprecated:: 2.0.0 + Use `pandas.api.types.is_object_dtype` instead. Returns ------- @@ -2461,6 +2463,14 @@ def is_object(self) -> bool: >>> idx.is_object() False """ + + warnings.warn( + f"{type(self).__name__}.is_object is deprecated." + "Use pandas.api.types.is_object_dtype instead", + FutureWarning, + stacklevel=find_stack_level(), + ) + return is_object_dtype(self.dtype) @final @@ -2483,7 +2493,7 @@ def is_categorical(self) -> bool: is_integer : Check if the Index only consists of integers (deprecated). is_floating : Check if the Index is a floating type (deprecated). is_numeric : Check if the Index only consists of numeric data. - is_object : Check if the Index is of the object dtype. + is_object : Check if the Index is of the object dtype. (deprecated) is_interval : Check if the Index holds Interval objects (deprecated). Examples @@ -2536,7 +2546,7 @@ def is_interval(self) -> bool: is_integer : Check if the Index only consists of integers (deprecated). is_floating : Check if the Index is a floating type (deprecated). is_numeric : Check if the Index only consists of numeric data. - is_object : Check if the Index is of the object dtype. + is_object : Check if the Index is of the object dtype. (deprecated) is_categorical : Check if the Index holds categorical data (deprecated). Examples @@ -5018,7 +5028,7 @@ def _is_memory_usage_qualified(self) -> bool: """ Return a boolean if we need a qualified .info display. """ - return self.is_object() + return is_object_dtype(self.dtype) def __contains__(self, key: Any) -> bool: """ @@ -5132,7 +5142,7 @@ def _can_hold_identifiers_and_holds_name(self, name) -> bool: https://github.com/pandas-dev/pandas/issues/19764 """ if ( - self.is_object() + is_object_dtype(self.dtype) or is_string_dtype(self.dtype) or is_categorical_dtype(self.dtype) ): diff --git a/pandas/tests/indexes/common.py b/pandas/tests/indexes/common.py index cd4cf9dd61b97..870d99ce67a40 100644 --- a/pandas/tests/indexes/common.py +++ b/pandas/tests/indexes/common.py @@ -829,6 +829,12 @@ def test_is_interval_is_deprecated(self, simple_index): with tm.assert_produces_warning(FutureWarning): idx.is_interval() + def test_is_object_is_deprecated(self, simple_index): + # GH50042 + idx = simple_index + with tm.assert_produces_warning(FutureWarning): + idx.is_object() + class NumericBase(Base): """ diff --git a/pandas/tests/indexing/test_indexing.py b/pandas/tests/indexing/test_indexing.py index 2bd11fbb85d13..19e0e656dd847 100644 --- a/pandas/tests/indexing/test_indexing.py +++ b/pandas/tests/indexing/test_indexing.py @@ -13,6 +13,7 @@ from pandas.core.dtypes.common import ( is_float_dtype, is_integer_dtype, + is_object_dtype ) import pandas as pd @@ -618,7 +619,7 @@ def test_index_type_coercion(self, indexer): s2 = s.copy() indexer(s2)["0"] = 0 - assert s2.index.is_object() + assert is_object_dtype(s2.index) for s in [Series(range(5), index=np.arange(5.0))]: @@ -635,7 +636,7 @@ def test_index_type_coercion(self, indexer): s2 = s.copy() indexer(s2)["0"] = 0 - assert s2.index.is_object() + assert is_object_dtype(s2.index) class TestMisc: From 1071a6abeb4fab95940bce84a4808d9b77d0a1a2 Mon Sep 17 00:00:00 2001 From: bang128 <71242233+bang128@users.noreply.github.com> Date: Tue, 13 Dec 2022 02:39:16 -0800 Subject: [PATCH 02/11] Fix pre-commit --- pandas/tests/indexing/test_indexing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/indexing/test_indexing.py b/pandas/tests/indexing/test_indexing.py index 19e0e656dd847..230605d2f3235 100644 --- a/pandas/tests/indexing/test_indexing.py +++ b/pandas/tests/indexing/test_indexing.py @@ -13,7 +13,7 @@ from pandas.core.dtypes.common import ( is_float_dtype, is_integer_dtype, - is_object_dtype + is_object_dtype, ) import pandas as pd From 379251be038a571aa75d0661b722a24c8434349c Mon Sep 17 00:00:00 2001 From: bang128 <71242233+bang128@users.noreply.github.com> Date: Tue, 13 Dec 2022 03:20:19 -0800 Subject: [PATCH 03/11] Fix docstring --- pandas/core/indexes/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 5bd6dbc8c16fb..7acd5204acc4f 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -2258,7 +2258,7 @@ def is_boolean(self) -> bool: is_integer : Check if the Index only consists of integers (deprecated). is_floating : Check if the Index is a floating type (deprecated). is_numeric : Check if the Index only consists of numeric data. - is_object : Check if the Index is of the object dtype. (deprecated) + is_object : Check if the Index is of the object dtype (deprecated). is_categorical : Check if the Index holds categorical data. is_interval : Check if the Index holds Interval objects (deprecated). From d1ba4c6bc68121f2c213193ec0c7cfdb93f88000 Mon Sep 17 00:00:00 2001 From: bang128 <71242233+bang128@users.noreply.github.com> Date: Tue, 13 Dec 2022 14:37:55 -0800 Subject: [PATCH 04/11] Update --- pandas/_testing/asserters.py | 1 - pandas/tests/indexes/test_base.py | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/pandas/_testing/asserters.py b/pandas/_testing/asserters.py index de28342c0d526..95d052382014a 100644 --- a/pandas/_testing/asserters.py +++ b/pandas/_testing/asserters.py @@ -6,7 +6,6 @@ ) import numpy as np - from pandas._libs.missing import is_matching_na from pandas._libs.sparse import SparseIndex import pandas._libs.testing as _testing diff --git a/pandas/tests/indexes/test_base.py b/pandas/tests/indexes/test_base.py index 1012734bab234..32255e150cddc 100644 --- a/pandas/tests/indexes/test_base.py +++ b/pandas/tests/indexes/test_base.py @@ -43,7 +43,7 @@ ensure_index_from_sequences, ) from pandas.tests.indexes.common import Base - +from pandas.core.dtypes.common import is_object_dtype class TestIndex(Base): _index_cls = Index @@ -677,7 +677,7 @@ def test_is_numeric(self, index, expected): indirect=["index"], ) def test_is_object(self, index, expected): - assert index.is_object() is expected + assert is_object_dtype(index) is expected def test_summary(self, index): index._summary() From 022da187407a90cd6da104e04ff9db8ffdb541c6 Mon Sep 17 00:00:00 2001 From: bang128 <71242233+bang128@users.noreply.github.com> Date: Thu, 15 Dec 2022 01:09:51 -0800 Subject: [PATCH 05/11] Update is_object --- pandas/core/indexes/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 7acd5204acc4f..cdf04c4ef3c59 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1348,7 +1348,7 @@ def _format_native_types( return formatter.get_result_as_array() mask = isna(self) - if not self.is_object() and not quoting: + if not is_object_dtype(self) and not quoting: values = np.asarray(self).astype(str) else: values = np.array(self, dtype=object, copy=True) From f0aa55382a5e1c2a3bb1ad1b5e52697e90b02eae Mon Sep 17 00:00:00 2001 From: bang128 <71242233+bang128@users.noreply.github.com> Date: Thu, 15 Dec 2022 20:27:51 -0800 Subject: [PATCH 06/11] Update --- pandas/core/indexes/base.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index cdf04c4ef3c59..bb5c844ad8e4c 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -2427,6 +2427,7 @@ def is_numeric(self) -> bool: def is_object(self) -> bool: """ Check if the Index is of the object dtype. + .. deprecated:: 2.0.0 Use `pandas.api.types.is_object_dtype` instead. @@ -2463,14 +2464,12 @@ def is_object(self) -> bool: >>> idx.is_object() False """ - warnings.warn( f"{type(self).__name__}.is_object is deprecated." "Use pandas.api.types.is_object_dtype instead", FutureWarning, stacklevel=find_stack_level(), ) - return is_object_dtype(self.dtype) @final From f12c14d9c7e3e32cc9097c406748820554e7a278 Mon Sep 17 00:00:00 2001 From: Terji Petersen Date: Wed, 25 Jan 2023 12:44:43 +0000 Subject: [PATCH 07/11] isort fix --- pandas/_testing/asserters.py | 1 + pandas/tests/indexes/test_base.py | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pandas/_testing/asserters.py b/pandas/_testing/asserters.py index 95d052382014a..de28342c0d526 100644 --- a/pandas/_testing/asserters.py +++ b/pandas/_testing/asserters.py @@ -6,6 +6,7 @@ ) import numpy as np + from pandas._libs.missing import is_matching_na from pandas._libs.sparse import SparseIndex import pandas._libs.testing as _testing diff --git a/pandas/tests/indexes/test_base.py b/pandas/tests/indexes/test_base.py index 32255e150cddc..92a3cbd46266c 100644 --- a/pandas/tests/indexes/test_base.py +++ b/pandas/tests/indexes/test_base.py @@ -18,7 +18,10 @@ ) from pandas.util._test_decorators import async_mark -from pandas.core.dtypes.common import is_numeric_dtype +from pandas.core.dtypes.common import ( + is_numeric_dtype, + is_object_dtype, +) import pandas as pd from pandas import ( @@ -43,7 +46,7 @@ ensure_index_from_sequences, ) from pandas.tests.indexes.common import Base -from pandas.core.dtypes.common import is_object_dtype + class TestIndex(Base): _index_cls = Index From af32b9173282f1143d4e26d801a9362ed263c2fc Mon Sep 17 00:00:00 2001 From: Terji Petersen Date: Wed, 25 Jan 2023 14:41:04 +0000 Subject: [PATCH 08/11] fix errors --- pandas/core/indexes/base.py | 8 ++++---- pandas/tests/series/methods/test_drop.py | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index bb5c844ad8e4c..e7344882ff646 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -2302,7 +2302,7 @@ def is_integer(self) -> bool: is_boolean : Check if the Index only consists of booleans (deprecated). is_floating : Check if the Index is a floating type (deprecated). is_numeric : Check if the Index only consists of numeric data. - is_object : Check if the Index is of the object dtype. (deprecated) + is_object : Check if the Index is of the object dtype. (deprecated). is_categorical : Check if the Index holds categorical data (deprecated). is_interval : Check if the Index holds Interval objects (deprecated). @@ -2350,7 +2350,7 @@ def is_floating(self) -> bool: is_boolean : Check if the Index only consists of booleans (deprecated). is_integer : Check if the Index only consists of integers (deprecated). is_numeric : Check if the Index only consists of numeric data. - is_object : Check if the Index is of the object dtype. (deprecated) + is_object : Check if the Index is of the object dtype. (deprecated). is_categorical : Check if the Index holds categorical data (deprecated). is_interval : Check if the Index holds Interval objects (deprecated). @@ -2395,7 +2395,7 @@ def is_numeric(self) -> bool: is_boolean : Check if the Index only consists of booleans (deprecated). is_integer : Check if the Index only consists of integers (deprecated). is_floating : Check if the Index is a floating type (deprecated). - is_object : Check if the Index is of the object dtype. (deprecated) + is_object : Check if the Index is of the object dtype. (deprecated). is_categorical : Check if the Index holds categorical data (deprecated). is_interval : Check if the Index holds Interval objects (deprecated). @@ -2545,7 +2545,7 @@ def is_interval(self) -> bool: is_integer : Check if the Index only consists of integers (deprecated). is_floating : Check if the Index is a floating type (deprecated). is_numeric : Check if the Index only consists of numeric data. - is_object : Check if the Index is of the object dtype. (deprecated) + is_object : Check if the Index is of the object dtype. (deprecated). is_categorical : Check if the Index holds categorical data (deprecated). Examples diff --git a/pandas/tests/series/methods/test_drop.py b/pandas/tests/series/methods/test_drop.py index dc4a11fd881fb..83d257605c487 100644 --- a/pandas/tests/series/methods/test_drop.py +++ b/pandas/tests/series/methods/test_drop.py @@ -5,6 +5,7 @@ Series, ) import pandas._testing as tm +from pandas.api.types import is_bool_dtype @pytest.mark.parametrize( @@ -57,7 +58,7 @@ def test_drop_with_ignore_errors(): # GH 8522 ser = Series([2, 3], index=[True, False]) - assert not ser.index.is_object() + assert is_bool_dtype(ser.index) assert ser.index.dtype == bool result = ser.drop(True) expected = Series([3], index=[False]) From fe151e064e99dbac2986b77bbd443ab2273399ff Mon Sep 17 00:00:00 2001 From: Terji Petersen Date: Wed, 25 Jan 2023 21:25:06 +0000 Subject: [PATCH 09/11] fix docstring --- pandas/core/indexes/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index e7344882ff646..5250ff19552ec 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -2492,7 +2492,7 @@ def is_categorical(self) -> bool: is_integer : Check if the Index only consists of integers (deprecated). is_floating : Check if the Index is a floating type (deprecated). is_numeric : Check if the Index only consists of numeric data. - is_object : Check if the Index is of the object dtype. (deprecated) + is_object : Check if the Index is of the object dtype. (deprecated). is_interval : Check if the Index holds Interval objects (deprecated). Examples From 419f93293f557d38e5f621648c4718e58a72ea7f Mon Sep 17 00:00:00 2001 From: Terji Petersen Date: Thu, 26 Jan 2023 05:57:47 +0000 Subject: [PATCH 10/11] fix --- pandas/io/pytables.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index efc7392eb00ba..55be16e0787c8 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -72,6 +72,7 @@ is_extension_array_dtype, is_integer_dtype, is_list_like, + is_object_dtype, is_string_dtype, is_timedelta64_dtype, needs_i8_conversion, @@ -2560,7 +2561,7 @@ class DataIndexableCol(DataCol): is_data_indexable = True def validate_names(self) -> None: - if not Index(self.values).is_object(): + if not is_object_dtype(Index(self.values)): # TODO: should the message here be more specifically non-str? raise ValueError("cannot have non-object label DataIndexableCol") From c162bebcaf16033388ce24d30004429abe17cd40 Mon Sep 17 00:00:00 2001 From: Terji Petersen Date: Fri, 27 Jan 2023 00:09:37 +0000 Subject: [PATCH 11/11] remove unneeded files --- data.csv | 4 - data.json | 1 - doc/source/user_guide/style.nbconvert.ipynb | 16030 ------------------ 3 files changed, 16035 deletions(-) delete mode 100644 data.csv delete mode 100644 data.json delete mode 100644 doc/source/user_guide/style.nbconvert.ipynb diff --git a/data.csv b/data.csv deleted file mode 100644 index 436430591f70f..0000000000000 --- a/data.csv +++ /dev/null @@ -1,4 +0,0 @@ -,,,1,2 -x,y,z,, -1,3,5,, -2,4,6,, diff --git a/data.json b/data.json deleted file mode 100644 index ae33afb2057e3..0000000000000 --- a/data.json +++ /dev/null @@ -1 +0,0 @@ -"{\"schema\":{\"fields\":[{\"name\":\"index\",\"type\":\"integer\"},{\"name\":\"a\",\"type\":\"number\"},{\"name\":\"b\",\"type\":\"number\"}],\"primaryKey\":[\"index\"],\"pandas_version\":\"1.4.0\"},\"data\":[{\"index\":0,\"a\":{\"imag\":2.0,\"real\":1.0},\"b\":{\"imag\":6.0,\"real\":5.0}},{\"index\":1,\"a\":{\"imag\":4.0,\"real\":3.0},\"b\":{\"imag\":8.0,\"real\":7.0}}]}" \ No newline at end of file diff --git a/doc/source/user_guide/style.nbconvert.ipynb b/doc/source/user_guide/style.nbconvert.ipynb deleted file mode 100644 index 3935f0c49f7fe..0000000000000 --- a/doc/source/user_guide/style.nbconvert.ipynb +++ /dev/null @@ -1,16030 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Table Visualization\n", - "\n", - "This section demonstrates visualization of tabular data using the [Styler][styler]\n", - "class. For information on visualization with charting please see [Chart Visualization][viz]. This document is written as a Jupyter Notebook, and can be viewed or downloaded [here][download].\n", - "\n", - "[styler]: ../reference/api/pandas.io.formats.style.Styler.rst\n", - "[viz]: visualization.rst\n", - "[download]: https://nbviewer.ipython.org/github/pandas-dev/pandas/blob/main/doc/source/user_guide/style.ipynb" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Styler Object and HTML \n", - "\n", - "Styling should be performed after the data in a DataFrame has been processed. The [Styler][styler] creates an HTML `` and leverages CSS styling language to manipulate many parameters including colors, fonts, borders, background, etc. See [here][w3schools] for more information on styling HTML tables. This allows a lot of flexibility out of the box, and even enables web developers to integrate DataFrames into their exiting user interface designs.\n", - " \n", - "The `DataFrame.style` attribute is a property that returns a [Styler][styler] object. It has a `_repr_html_` method defined on it so they are rendered automatically in Jupyter Notebook.\n", - "\n", - "[styler]: ../reference/api/pandas.io.formats.style.Styler.rst\n", - "[w3schools]: https://www.w3schools.com/html/html_tables.asp" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:37.132240Z", - "iopub.status.busy": "2023-01-25T14:32:37.131849Z", - "iopub.status.idle": "2023-01-25T14:32:37.432043Z", - "shell.execute_reply": "2023-01-25T14:32:37.431329Z" - }, - "nbsphinx": "hidden" - }, - "outputs": [], - "source": [ - "import matplotlib.pyplot\n", - "# We have this here to trigger matplotlib's font cache stuff.\n", - "# This cell is hidden from the output" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:37.437370Z", - "iopub.status.busy": "2023-01-25T14:32:37.436979Z", - "iopub.status.idle": "2023-01-25T14:32:37.735979Z", - "shell.execute_reply": "2023-01-25T14:32:37.735663Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "
\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
Model:Decision TreeRegressionRandom
Predicted:TumourNon-TumourTumourNon-TumourTumourNon-Tumour
Actual Label:      
Tumour (Positive)38.0000002.00000018.00000022.00000021nan
Non-Tumour (Negative)19.000000439.0000006.000000452.000000226232.000000
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 2, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "import pandas as pd\n", - "import numpy as np\n", - "import matplotlib as mpl\n", - "\n", - "df = pd.DataFrame([[38.0, 2.0, 18.0, 22.0, 21, np.nan],[19, 439, 6, 452, 226,232]], \n", - " index=pd.Index(['Tumour (Positive)', 'Non-Tumour (Negative)'], name='Actual Label:'), \n", - " columns=pd.MultiIndex.from_product([['Decision Tree', 'Regression', 'Random'],['Tumour', 'Non-Tumour']], names=['Model:', 'Predicted:']))\n", - "df.style" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The above output looks very similar to the standard DataFrame HTML representation. But the HTML here has already attached some CSS classes to each cell, even if we haven't yet created any styles. We can view these by calling the [.to_html()][tohtml] method, which returns the raw HTML as string, which is useful for further processing or adding to a file - read on in [More about CSS and HTML](#More-About-CSS-and-HTML). Below we will show how we can use these to format the DataFrame to be more communicative. For example how we can build `s`:\n", - "\n", - "[tohtml]: ../reference/api/pandas.io.formats.style.Styler.to_html.rst" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:37.750620Z", - "iopub.status.busy": "2023-01-25T14:32:37.750423Z", - "iopub.status.idle": "2023-01-25T14:32:37.766061Z", - "shell.execute_reply": "2023-01-25T14:32:37.765810Z" - }, - "nbsphinx": "hidden" - }, - "outputs": [], - "source": [ - "# Hidden cell to just create the below example: code is covered throughout the guide.\n", - "s = df.style\\\n", - " .hide([('Random', 'Tumour'), ('Random', 'Non-Tumour')], axis='columns')\\\n", - " .format('{:.0f}')\\\n", - " .set_table_styles([{\n", - " 'selector': '',\n", - " 'props': 'border-collapse: separate;'\n", - " },{\n", - " 'selector': 'caption',\n", - " 'props': 'caption-side: bottom; font-size:1.3em;'\n", - " },{\n", - " 'selector': '.index_name',\n", - " 'props': 'font-style: italic; color: darkgrey; font-weight:normal;'\n", - " },{\n", - " 'selector': 'th:not(.index_name)',\n", - " 'props': 'background-color: #000066; color: white;'\n", - " },{\n", - " 'selector': 'th.col_heading',\n", - " 'props': 'text-align: center;'\n", - " },{\n", - " 'selector': 'th.col_heading.level0',\n", - " 'props': 'font-size: 1.5em;'\n", - " },{\n", - " 'selector': 'th.col2',\n", - " 'props': 'border-left: 1px solid white;'\n", - " },{\n", - " 'selector': '.col2',\n", - " 'props': 'border-left: 1px solid #000066;'\n", - " },{\n", - " 'selector': 'td',\n", - " 'props': 'text-align: center; font-weight:bold;'\n", - " },{\n", - " 'selector': '.true',\n", - " 'props': 'background-color: #e6ffe6;'\n", - " },{\n", - " 'selector': '.false',\n", - " 'props': 'background-color: #ffe6e6;'\n", - " },{\n", - " 'selector': '.border-red',\n", - " 'props': 'border: 2px dashed red;'\n", - " },{\n", - " 'selector': '.border-green',\n", - " 'props': 'border: 2px dashed green;'\n", - " },{\n", - " 'selector': 'td:hover',\n", - " 'props': 'background-color: #ffffb3;'\n", - " }])\\\n", - " .set_td_classes(pd.DataFrame([['true border-green', 'false', 'true', 'false border-red', '', ''],\n", - " ['false', 'true', 'false', 'true', '', '']], \n", - " index=df.index, columns=df.columns))\\\n", - " .set_caption(\"Confusion matrix for multiple cancer prediction models.\")\\\n", - " .set_tooltips(pd.DataFrame([['This model has a very strong true positive rate', '', '', \"This model's total number of false negatives is too high\", '', ''],\n", - " ['', '', '', '', '', '']], \n", - " index=df.index, columns=df.columns),\n", - " css_class='pd-tt', props=\n", - " 'visibility: hidden; position: absolute; z-index: 1; border: 1px solid #000066;'\n", - " 'background-color: white; color: #000066; font-size: 0.8em;' \n", - " 'transform: translate(0px, -24px); padding: 0.6em; border-radius: 0.5em;')\n" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:37.767599Z", - "iopub.status.busy": "2023-01-25T14:32:37.767511Z", - "iopub.status.idle": "2023-01-25T14:32:37.779781Z", - "shell.execute_reply": "2023-01-25T14:32:37.779503Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
Confusion matrix for multiple cancer prediction models.
Model:Decision TreeRegression
Predicted:TumourNon-TumourTumourNon-Tumour
Actual Label:    
Tumour (Positive)3821822
Non-Tumour (Negative)194396452
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "s" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Formatting the Display\n", - "\n", - "### Formatting Values\n", - "\n", - "Before adding styles it is useful to show that the [Styler][styler] can distinguish the *display* value from the *actual* value, in both datavalues and index or columns headers. To control the display value, the text is printed in each cell as string, and we can use the [.format()][formatfunc] and [.format_index()][formatfuncindex] methods to manipulate this according to a [format spec string][format] or a callable that takes a single value and returns a string. It is possible to define this for the whole table, or index, or for individual columns, or MultiIndex levels. \n", - "\n", - "Additionally, the format function has a **precision** argument to specifically help formatting floats, as well as **decimal** and **thousands** separators to support other locales, an **na_rep** argument to display missing data, and an **escape** argument to help displaying safe-HTML or safe-LaTeX. The default formatter is configured to adopt pandas' `styler.format.precision` option, controllable using `with pd.option_context('format.precision', 2):` \n", - "\n", - "[styler]: ../reference/api/pandas.io.formats.style.Styler.rst\n", - "[format]: https://docs.python.org/3/library/string.html#format-specification-mini-language\n", - "[formatfunc]: ../reference/api/pandas.io.formats.style.Styler.format.rst\n", - "[formatfuncindex]: ../reference/api/pandas.io.formats.style.Styler.format_index.rst" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:37.781543Z", - "iopub.status.busy": "2023-01-25T14:32:37.781424Z", - "iopub.status.idle": "2023-01-25T14:32:37.794309Z", - "shell.execute_reply": "2023-01-25T14:32:37.794065Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
Model:Decision TreeRegressionRandom
Predicted:TumourNon-TumourTumourNon-TumourTumourNon-Tumour
Actual Label:      
Tumour (Positive)38.00218$ -22 000 000.021MISSING
Non-Tumour (Negative)19.004396$ -452 000 000.0226232
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 5, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df.style.format(precision=0, na_rep='MISSING', thousands=\" \",\n", - " formatter={('Decision Tree', 'Tumour'): \"{:.2f}\",\n", - " ('Regression', 'Non-Tumour'): lambda x: \"$ {:,.1f}\".format(x*-1e6)\n", - " })" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Using Styler to manipulate the display is a useful feature because maintaining the indexing and datavalues for other purposes gives greater control. You do not have to overwrite your DataFrame to display it how you like. Here is an example of using the formatting functions whilst still relying on the underlying data for indexing and calculations." - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:37.795897Z", - "iopub.status.busy": "2023-01-25T14:32:37.795790Z", - "iopub.status.idle": "2023-01-25T14:32:37.811010Z", - "shell.execute_reply": "2023-01-25T14:32:37.810750Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
TokyoBeijing
2021-01-010.6729061.168244
2021-01-021.9689161.244091
2021-01-030.2062750.542097
2021-01-041.4706160.681337
2021-01-051.4494781.433289
2021-01-061.1414244.320723
2021-01-073.0747441.239495
2021-01-081.6812944.571259
2021-01-093.0949600.967787
2021-01-103.3456151.779296
\n", - "
" - ], - "text/plain": [ - " Tokyo Beijing\n", - "2021-01-01 0.672906 1.168244\n", - "2021-01-02 1.968916 1.244091\n", - "2021-01-03 0.206275 0.542097\n", - "2021-01-04 1.470616 0.681337\n", - "2021-01-05 1.449478 1.433289\n", - "2021-01-06 1.141424 4.320723\n", - "2021-01-07 3.074744 1.239495\n", - "2021-01-08 1.681294 4.571259\n", - "2021-01-09 3.094960 0.967787\n", - "2021-01-10 3.345615 1.779296" - ] - }, - "execution_count": 6, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "weather_df = pd.DataFrame(np.random.rand(10,2)*5, \n", - " index=pd.date_range(start=\"2021-01-01\", periods=10),\n", - " columns=[\"Tokyo\", \"Beijing\"])\n", - "\n", - "def rain_condition(v): \n", - " if v < 1.75:\n", - " return \"Dry\"\n", - " elif v < 2.75:\n", - " return \"Rain\"\n", - " return \"Heavy Rain\"\n", - "\n", - "def make_pretty(styler):\n", - " styler.set_caption(\"Weather Conditions\")\n", - " styler.format(rain_condition)\n", - " styler.format_index(lambda v: v.strftime(\"%A\"))\n", - " styler.background_gradient(axis=None, vmin=1, vmax=5, cmap=\"YlGnBu\")\n", - " return styler\n", - "\n", - "weather_df" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:37.812485Z", - "iopub.status.busy": "2023-01-25T14:32:37.812374Z", - "iopub.status.idle": "2023-01-25T14:32:37.825922Z", - "shell.execute_reply": "2023-01-25T14:32:37.825657Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
Weather Conditions
 TokyoBeijing
MondayDryDry
TuesdayDryDry
WednesdayDryHeavy Rain
ThursdayHeavy RainDry
FridayDryHeavy Rain
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 7, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "weather_df.loc[\"2021-01-04\":\"2021-01-08\"].style.pipe(make_pretty)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Hiding Data\n", - "\n", - "The index and column headers can be completely hidden, as well subselecting rows or columns that one wishes to exclude. Both these options are performed using the same methods.\n", - "\n", - "The index can be hidden from rendering by calling [.hide()][hideidx] without any arguments, which might be useful if your index is integer based. Similarly column headers can be hidden by calling [.hide(axis=\"columns\")][hideidx] without any further arguments.\n", - "\n", - "Specific rows or columns can be hidden from rendering by calling the same [.hide()][hideidx] method and passing in a row/column label, a list-like or a slice of row/column labels to for the ``subset`` argument.\n", - "\n", - "Hiding does not change the integer arrangement of CSS classes, e.g. hiding the first two columns of a DataFrame means the column class indexing will still start at `col2`, since `col0` and `col1` are simply ignored.\n", - "\n", - "We can update our `Styler` object from before to hide some data and format the values.\n", - "\n", - "[hideidx]: ../reference/api/pandas.io.formats.style.Styler.hide.rst" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:37.827473Z", - "iopub.status.busy": "2023-01-25T14:32:37.827387Z", - "iopub.status.idle": "2023-01-25T14:32:37.840226Z", - "shell.execute_reply": "2023-01-25T14:32:37.839967Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
Model:Decision TreeRegression
Predicted:TumourNon-TumourTumourNon-Tumour
Actual Label:    
Tumour (Positive)3821822
Non-Tumour (Negative)194396452
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 8, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "s = df.style.format('{:.0f}').hide([('Random', 'Tumour'), ('Random', 'Non-Tumour')], axis=\"columns\")\n", - "s" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:37.841727Z", - "iopub.status.busy": "2023-01-25T14:32:37.841642Z", - "iopub.status.idle": "2023-01-25T14:32:37.852938Z", - "shell.execute_reply": "2023-01-25T14:32:37.852697Z" - }, - "nbsphinx": "hidden" - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
Model:Decision TreeRegression
Predicted:TumourNon-TumourTumourNon-Tumour
Actual Label:    
Tumour (Positive)3821822
Non-Tumour (Negative)194396452
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 9, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Hidden cell to avoid CSS clashes and latter code upcoding previous formatting \n", - "s.set_uuid('after_hide')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Methods to Add Styles\n", - "\n", - "There are **3 primary methods of adding custom CSS styles** to [Styler][styler]:\n", - "\n", - "- Using [.set_table_styles()][table] to control broader areas of the table with specified internal CSS. Although table styles allow the flexibility to add CSS selectors and properties controlling all individual parts of the table, they are unwieldy for individual cell specifications. Also, note that table styles cannot be exported to Excel. \n", - "- Using [.set_td_classes()][td_class] to directly link either external CSS classes to your data cells or link the internal CSS classes created by [.set_table_styles()][table]. See [here](#Setting-Classes-and-Linking-to-External-CSS). These cannot be used on column header rows or indexes, and also won't export to Excel. \n", - "- Using the [.apply()][apply] and [.applymap()][applymap] functions to add direct internal CSS to specific data cells. See [here](#Styler-Functions). As of v1.4.0 there are also methods that work directly on column header rows or indexes; [.apply_index()][applyindex] and [.applymap_index()][applymapindex]. Note that only these methods add styles that will export to Excel. These methods work in a similar way to [DataFrame.apply()][dfapply] and [DataFrame.applymap()][dfapplymap].\n", - "\n", - "[table]: ../reference/api/pandas.io.formats.style.Styler.set_table_styles.rst\n", - "[styler]: ../reference/api/pandas.io.formats.style.Styler.rst\n", - "[td_class]: ../reference/api/pandas.io.formats.style.Styler.set_td_classes.rst\n", - "[apply]: ../reference/api/pandas.io.formats.style.Styler.apply.rst\n", - "[applymap]: ../reference/api/pandas.io.formats.style.Styler.applymap.rst\n", - "[applyindex]: ../reference/api/pandas.io.formats.style.Styler.apply_index.rst\n", - "[applymapindex]: ../reference/api/pandas.io.formats.style.Styler.applymap_index.rst\n", - "[dfapply]: ../reference/api/pandas.DataFrame.apply.rst\n", - "[dfapplymap]: ../reference/api/pandas.DataFrame.applymap.rst" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Table Styles\n", - "\n", - "Table styles are flexible enough to control all individual parts of the table, including column headers and indexes. \n", - "However, they can be unwieldy to type for individual data cells or for any kind of conditional formatting, so we recommend that table styles are used for broad styling, such as entire rows or columns at a time.\n", - "\n", - "Table styles are also used to control features which can apply to the whole table at once such as creating a generic hover functionality. The `:hover` pseudo-selector, as well as other pseudo-selectors, can only be used this way.\n", - "\n", - "To replicate the normal format of CSS selectors and properties (attribute value pairs), e.g. \n", - "\n", - "```\n", - "tr:hover {\n", - " background-color: #ffff99;\n", - "}\n", - "```\n", - "\n", - "the necessary format to pass styles to [.set_table_styles()][table] is as a list of dicts, each with a CSS-selector tag and CSS-properties. Properties can either be a list of 2-tuples, or a regular CSS-string, for example:\n", - "\n", - "[table]: ../reference/api/pandas.io.formats.style.Styler.set_table_styles.rst" - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:37.854444Z", - "iopub.status.busy": "2023-01-25T14:32:37.854365Z", - "iopub.status.idle": "2023-01-25T14:32:37.865456Z", - "shell.execute_reply": "2023-01-25T14:32:37.865210Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
Model:Decision TreeRegression
Predicted:TumourNon-TumourTumourNon-Tumour
Actual Label:    
Tumour (Positive)3821822
Non-Tumour (Negative)194396452
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 10, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "cell_hover = { # for row hover use instead of \n", - " 'selector': 'td:hover',\n", - " 'props': [('background-color', '#ffffb3')]\n", - "}\n", - "index_names = {\n", - " 'selector': '.index_name',\n", - " 'props': 'font-style: italic; color: darkgrey; font-weight:normal;'\n", - "}\n", - "headers = {\n", - " 'selector': 'th:not(.index_name)',\n", - " 'props': 'background-color: #000066; color: white;'\n", - "}\n", - "s.set_table_styles([cell_hover, index_names, headers])" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:37.866856Z", - "iopub.status.busy": "2023-01-25T14:32:37.866775Z", - "iopub.status.idle": "2023-01-25T14:32:37.878076Z", - "shell.execute_reply": "2023-01-25T14:32:37.877812Z" - }, - "nbsphinx": "hidden" - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
Model:Decision TreeRegression
Predicted:TumourNon-TumourTumourNon-Tumour
Actual Label:    
Tumour (Positive)3821822
Non-Tumour (Negative)194396452
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 11, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Hidden cell to avoid CSS clashes and latter code upcoding previous formatting \n", - "s.set_uuid('after_tab_styles1')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Next we just add a couple more styling artifacts targeting specific parts of the table. Be careful here, since we are *chaining methods* we need to explicitly instruct the method **not to** ``overwrite`` the existing styles." - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:37.879688Z", - "iopub.status.busy": "2023-01-25T14:32:37.879574Z", - "iopub.status.idle": "2023-01-25T14:32:37.892201Z", - "shell.execute_reply": "2023-01-25T14:32:37.891918Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
Model:Decision TreeRegression
Predicted:TumourNon-TumourTumourNon-Tumour
Actual Label:    
Tumour (Positive)3821822
Non-Tumour (Negative)194396452
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 12, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "s.set_table_styles([\n", - " {'selector': 'th.col_heading', 'props': 'text-align: center;'},\n", - " {'selector': 'th.col_heading.level0', 'props': 'font-size: 1.5em;'},\n", - " {'selector': 'td', 'props': 'text-align: center; font-weight: bold;'},\n", - "], overwrite=False)" - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:37.893876Z", - "iopub.status.busy": "2023-01-25T14:32:37.893737Z", - "iopub.status.idle": "2023-01-25T14:32:37.905915Z", - "shell.execute_reply": "2023-01-25T14:32:37.905661Z" - }, - "nbsphinx": "hidden" - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
Model:Decision TreeRegression
Predicted:TumourNon-TumourTumourNon-Tumour
Actual Label:    
Tumour (Positive)3821822
Non-Tumour (Negative)194396452
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 13, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Hidden cell to avoid CSS clashes and latter code upcoding previous formatting \n", - "s.set_uuid('after_tab_styles2')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "As a convenience method (*since version 1.2.0*) we can also pass a **dict** to [.set_table_styles()][table] which contains row or column keys. Behind the scenes Styler just indexes the keys and adds relevant `.col` or `.row` classes as necessary to the given CSS selectors.\n", - "\n", - "[table]: ../reference/api/pandas.io.formats.style.Styler.set_table_styles.rst" - ] - }, - { - "cell_type": "code", - "execution_count": 14, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:37.907564Z", - "iopub.status.busy": "2023-01-25T14:32:37.907472Z", - "iopub.status.idle": "2023-01-25T14:32:37.919733Z", - "shell.execute_reply": "2023-01-25T14:32:37.919500Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
Model:Decision TreeRegression
Predicted:TumourNon-TumourTumourNon-Tumour
Actual Label:    
Tumour (Positive)3821822
Non-Tumour (Negative)194396452
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 14, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "s.set_table_styles({\n", - " ('Regression', 'Tumour'): [{'selector': 'th', 'props': 'border-left: 1px solid white'},\n", - " {'selector': 'td', 'props': 'border-left: 1px solid #000066'}]\n", - "}, overwrite=False, axis=0)" - ] - }, - { - "cell_type": "code", - "execution_count": 15, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:37.921193Z", - "iopub.status.busy": "2023-01-25T14:32:37.921115Z", - "iopub.status.idle": "2023-01-25T14:32:37.936097Z", - "shell.execute_reply": "2023-01-25T14:32:37.935846Z" - }, - "nbsphinx": "hidden" - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
Model:Decision TreeRegression
Predicted:TumourNon-TumourTumourNon-Tumour
Actual Label:    
Tumour (Positive)3821822
Non-Tumour (Negative)194396452
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 15, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Hidden cell to avoid CSS clashes and latter code upcoding previous formatting \n", - "s.set_uuid('xyz01')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Setting Classes and Linking to External CSS\n", - "\n", - "If you have designed a website then it is likely you will already have an external CSS file that controls the styling of table and cell objects within it. You may want to use these native files rather than duplicate all the CSS in python (and duplicate any maintenance work).\n", - "\n", - "### Table Attributes\n", - "\n", - "It is very easy to add a `class` to the main `` using [.set_table_attributes()][tableatt]. This method can also attach inline styles - read more in [CSS Hierarchies](#CSS-Hierarchies).\n", - "\n", - "[tableatt]: ../reference/api/pandas.io.formats.style.Styler.set_table_attributes.rst" - ] - }, - { - "cell_type": "code", - "execution_count": 16, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:37.937583Z", - "iopub.status.busy": "2023-01-25T14:32:37.937482Z", - "iopub.status.idle": "2023-01-25T14:32:37.947993Z", - "shell.execute_reply": "2023-01-25T14:32:37.947739Z" - } - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "
\n", - " \n", - " \n", - " \n" - ] - } - ], - "source": [ - "out = s.set_table_attributes('class=\"my-table-cls\"').to_html()\n", - "print(out[out.find('` elements of the `
Model:
`. Rather than use external CSS we will create our classes internally and add them to table style. We will save adding the borders until the [section on tooltips](#Tooltips).\n", - "\n", - "[tdclass]: ../reference/api/pandas.io.formats.style.Styler.set_td_classes.rst\n", - "[styler]: ../reference/api/pandas.io.formats.style.Styler.rst" - ] - }, - { - "cell_type": "code", - "execution_count": 17, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:37.949481Z", - "iopub.status.busy": "2023-01-25T14:32:37.949400Z", - "iopub.status.idle": "2023-01-25T14:32:37.961606Z", - "shell.execute_reply": "2023-01-25T14:32:37.961363Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "
\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
Model:Decision TreeRegression
Predicted:TumourNon-TumourTumourNon-Tumour
Actual Label:    
Tumour (Positive)3821822
Non-Tumour (Negative)194396452
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 17, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "s.set_table_styles([ # create internal CSS classes\n", - " {'selector': '.true', 'props': 'background-color: #e6ffe6;'},\n", - " {'selector': '.false', 'props': 'background-color: #ffe6e6;'},\n", - "], overwrite=False)\n", - "cell_color = pd.DataFrame([['true ', 'false ', 'true ', 'false '], \n", - " ['false ', 'true ', 'false ', 'true ']], \n", - " index=df.index, \n", - " columns=df.columns[:4])\n", - "s.set_td_classes(cell_color)" - ] - }, - { - "cell_type": "code", - "execution_count": 18, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:37.962986Z", - "iopub.status.busy": "2023-01-25T14:32:37.962909Z", - "iopub.status.idle": "2023-01-25T14:32:37.974709Z", - "shell.execute_reply": "2023-01-25T14:32:37.974450Z" - }, - "nbsphinx": "hidden" - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
Model:Decision TreeRegression
Predicted:TumourNon-TumourTumourNon-Tumour
Actual Label:    
Tumour (Positive)3821822
Non-Tumour (Negative)194396452
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 18, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Hidden cell to avoid CSS clashes and latter code upcoding previous formatting \n", - "s.set_uuid('after_classes')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Styler Functions\n", - "\n", - "### Acting on Data\n", - "\n", - "We use the following methods to pass your style functions. Both of those methods take a function (and some other keyword arguments) and apply it to the DataFrame in a certain way, rendering CSS styles.\n", - "\n", - "- [.applymap()][applymap] (elementwise): accepts a function that takes a single value and returns a string with the CSS attribute-value pair.\n", - "- [.apply()][apply] (column-/row-/table-wise): accepts a function that takes a Series or DataFrame and returns a Series, DataFrame, or numpy array with an identical shape where each element is a string with a CSS attribute-value pair. This method passes each column or row of your DataFrame one-at-a-time or the entire table at once, depending on the `axis` keyword argument. For columnwise use `axis=0`, rowwise use `axis=1`, and for the entire table at once use `axis=None`.\n", - "\n", - "This method is powerful for applying multiple, complex logic to data cells. We create a new DataFrame to demonstrate this.\n", - "\n", - "[apply]: ../reference/api/pandas.io.formats.style.Styler.apply.rst\n", - "[applymap]: ../reference/api/pandas.io.formats.style.Styler.applymap.rst" - ] - }, - { - "cell_type": "code", - "execution_count": 19, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:37.976315Z", - "iopub.status.busy": "2023-01-25T14:32:37.976204Z", - "iopub.status.idle": "2023-01-25T14:32:37.987983Z", - "shell.execute_reply": "2023-01-25T14:32:37.987738Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
 ABCD
01.7640520.4001570.9787382.240893
11.867558-0.9772780.950088-0.151357
2-0.1032190.4105990.1440441.454274
30.7610380.1216750.4438630.333674
41.494079-0.2051580.313068-0.854096
5-2.5529900.6536190.864436-0.742165
62.269755-1.4543660.045759-0.187184
71.5327791.4693590.1549470.378163
8-0.887786-1.980796-0.3479120.156349
91.2302911.202380-0.387327-0.302303
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 19, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "np.random.seed(0)\n", - "df2 = pd.DataFrame(np.random.randn(10,4), columns=['A','B','C','D'])\n", - "df2.style" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "For example we can build a function that colors text if it is negative, and chain this with a function that partially fades cells of negligible value. Since this looks at each element in turn we use ``applymap``." - ] - }, - { - "cell_type": "code", - "execution_count": 20, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:37.989527Z", - "iopub.status.busy": "2023-01-25T14:32:37.989448Z", - "iopub.status.idle": "2023-01-25T14:32:38.001730Z", - "shell.execute_reply": "2023-01-25T14:32:38.001470Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
 ABCD
01.7640520.4001570.9787382.240893
11.867558-0.9772780.950088-0.151357
2-0.1032190.4105990.1440441.454274
30.7610380.1216750.4438630.333674
41.494079-0.2051580.313068-0.854096
5-2.5529900.6536190.864436-0.742165
62.269755-1.4543660.045759-0.187184
71.5327791.4693590.1549470.378163
8-0.887786-1.980796-0.3479120.156349
91.2302911.202380-0.387327-0.302303
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 20, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "def style_negative(v, props=''):\n", - " return props if v < 0 else None\n", - "s2 = df2.style.applymap(style_negative, props='color:red;')\\\n", - " .applymap(lambda v: 'opacity: 20%;' if (v < 0.3) and (v > -0.3) else None)\n", - "s2" - ] - }, - { - "cell_type": "code", - "execution_count": 21, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:38.003191Z", - "iopub.status.busy": "2023-01-25T14:32:38.003104Z", - "iopub.status.idle": "2023-01-25T14:32:38.014611Z", - "shell.execute_reply": "2023-01-25T14:32:38.014365Z" - }, - "nbsphinx": "hidden" - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
 ABCD
01.7640520.4001570.9787382.240893
11.867558-0.9772780.950088-0.151357
2-0.1032190.4105990.1440441.454274
30.7610380.1216750.4438630.333674
41.494079-0.2051580.313068-0.854096
5-2.5529900.6536190.864436-0.742165
62.269755-1.4543660.045759-0.187184
71.5327791.4693590.1549470.378163
8-0.887786-1.980796-0.3479120.156349
91.2302911.202380-0.387327-0.302303
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 21, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Hidden cell to avoid CSS clashes and latter code upcoding previous formatting \n", - "s2.set_uuid('after_applymap')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We can also build a function that highlights the maximum value across rows, cols, and the DataFrame all at once. In this case we use ``apply``. Below we highlight the maximum in a column." - ] - }, - { - "cell_type": "code", - "execution_count": 22, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:38.016109Z", - "iopub.status.busy": "2023-01-25T14:32:38.016023Z", - "iopub.status.idle": "2023-01-25T14:32:38.028756Z", - "shell.execute_reply": "2023-01-25T14:32:38.028493Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
 ABCD
01.7640520.4001570.9787382.240893
11.867558-0.9772780.950088-0.151357
2-0.1032190.4105990.1440441.454274
30.7610380.1216750.4438630.333674
41.494079-0.2051580.313068-0.854096
5-2.5529900.6536190.864436-0.742165
62.269755-1.4543660.045759-0.187184
71.5327791.4693590.1549470.378163
8-0.887786-1.980796-0.3479120.156349
91.2302911.202380-0.387327-0.302303
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 22, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "def highlight_max(s, props=''):\n", - " return np.where(s == np.nanmax(s.values), props, '')\n", - "s2.apply(highlight_max, props='color:white;background-color:darkblue', axis=0)" - ] - }, - { - "cell_type": "code", - "execution_count": 23, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:38.030241Z", - "iopub.status.busy": "2023-01-25T14:32:38.030149Z", - "iopub.status.idle": "2023-01-25T14:32:38.042535Z", - "shell.execute_reply": "2023-01-25T14:32:38.042293Z" - }, - "nbsphinx": "hidden" - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
 ABCD
01.7640520.4001570.9787382.240893
11.867558-0.9772780.950088-0.151357
2-0.1032190.4105990.1440441.454274
30.7610380.1216750.4438630.333674
41.494079-0.2051580.313068-0.854096
5-2.5529900.6536190.864436-0.742165
62.269755-1.4543660.045759-0.187184
71.5327791.4693590.1549470.378163
8-0.887786-1.980796-0.3479120.156349
91.2302911.202380-0.387327-0.302303
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 23, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Hidden cell to avoid CSS clashes and latter code upcoding previous formatting \n", - "s2.set_uuid('after_apply')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We can use the same function across the different axes, highlighting here the DataFrame maximum in purple, and row maximums in pink." - ] - }, - { - "cell_type": "code", - "execution_count": 24, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:38.044098Z", - "iopub.status.busy": "2023-01-25T14:32:38.044013Z", - "iopub.status.idle": "2023-01-25T14:32:38.058598Z", - "shell.execute_reply": "2023-01-25T14:32:38.058361Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
 ABCD
01.7640520.4001570.9787382.240893
11.867558-0.9772780.950088-0.151357
2-0.1032190.4105990.1440441.454274
30.7610380.1216750.4438630.333674
41.494079-0.2051580.313068-0.854096
5-2.5529900.6536190.864436-0.742165
62.269755-1.4543660.045759-0.187184
71.5327791.4693590.1549470.378163
8-0.887786-1.980796-0.3479120.156349
91.2302911.202380-0.387327-0.302303
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 24, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "s2.apply(highlight_max, props='color:white;background-color:pink;', axis=1)\\\n", - " .apply(highlight_max, props='color:white;background-color:purple', axis=None)" - ] - }, - { - "cell_type": "code", - "execution_count": 25, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:38.059958Z", - "iopub.status.busy": "2023-01-25T14:32:38.059875Z", - "iopub.status.idle": "2023-01-25T14:32:38.074078Z", - "shell.execute_reply": "2023-01-25T14:32:38.073837Z" - }, - "nbsphinx": "hidden" - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
 ABCD
01.7640520.4001570.9787382.240893
11.867558-0.9772780.950088-0.151357
2-0.1032190.4105990.1440441.454274
30.7610380.1216750.4438630.333674
41.494079-0.2051580.313068-0.854096
5-2.5529900.6536190.864436-0.742165
62.269755-1.4543660.045759-0.187184
71.5327791.4693590.1549470.378163
8-0.887786-1.980796-0.3479120.156349
91.2302911.202380-0.387327-0.302303
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 25, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Hidden cell to avoid CSS clashes and latter code upcoding previous formatting \n", - "s2.set_uuid('after_apply_again')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "This last example shows how some styles have been overwritten by others. In general the most recent style applied is active but you can read more in the [section on CSS hierarchies](#CSS-Hierarchies). You can also apply these styles to more granular parts of the DataFrame - read more in section on [subset slicing](#Finer-Control-with-Slicing).\n", - "\n", - "It is possible to replicate some of this functionality using just classes but it can be more cumbersome. See [item 3) of Optimization](#Optimization)\n", - "\n", - "
\n", - "\n", - "*Debugging Tip*: If you're having trouble writing your style function, try just passing it into ``DataFrame.apply``. Internally, ``Styler.apply`` uses ``DataFrame.apply`` so the result should be the same, and with ``DataFrame.apply`` you will be able to inspect the CSS string output of your intended function in each cell.\n", - "\n", - "
" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Acting on the Index and Column Headers\n", - "\n", - "Similar application is achieved for headers by using:\n", - " \n", - "- [.applymap_index()][applymapindex] (elementwise): accepts a function that takes a single value and returns a string with the CSS attribute-value pair.\n", - "- [.apply_index()][applyindex] (level-wise): accepts a function that takes a Series and returns a Series, or numpy array with an identical shape where each element is a string with a CSS attribute-value pair. This method passes each level of your Index one-at-a-time. To style the index use `axis=0` and to style the column headers use `axis=1`.\n", - "\n", - "You can select a `level` of a `MultiIndex` but currently no similar `subset` application is available for these methods.\n", - "\n", - "[applyindex]: ../reference/api/pandas.io.formats.style.Styler.apply_index.rst\n", - "[applymapindex]: ../reference/api/pandas.io.formats.style.Styler.applymap_index.rst" - ] - }, - { - "cell_type": "code", - "execution_count": 26, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:38.075627Z", - "iopub.status.busy": "2023-01-25T14:32:38.075522Z", - "iopub.status.idle": "2023-01-25T14:32:38.090386Z", - "shell.execute_reply": "2023-01-25T14:32:38.090148Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
 ABCD
01.7640520.4001570.9787382.240893
11.867558-0.9772780.950088-0.151357
2-0.1032190.4105990.1440441.454274
30.7610380.1216750.4438630.333674
41.494079-0.2051580.313068-0.854096
5-2.5529900.6536190.864436-0.742165
62.269755-1.4543660.045759-0.187184
71.5327791.4693590.1549470.378163
8-0.887786-1.980796-0.3479120.156349
91.2302911.202380-0.387327-0.302303
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 26, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "s2.applymap_index(lambda v: \"color:pink;\" if v>4 else \"color:darkblue;\", axis=0)\n", - "s2.apply_index(lambda s: np.where(s.isin([\"A\", \"B\"]), \"color:pink;\", \"color:darkblue;\"), axis=1)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Tooltips and Captions\n", - "\n", - "Table captions can be added with the [.set_caption()][caption] method. You can use table styles to control the CSS relevant to the caption.\n", - "\n", - "[caption]: ../reference/api/pandas.io.formats.style.Styler.set_caption.rst" - ] - }, - { - "cell_type": "code", - "execution_count": 27, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:38.091831Z", - "iopub.status.busy": "2023-01-25T14:32:38.091753Z", - "iopub.status.idle": "2023-01-25T14:32:38.103154Z", - "shell.execute_reply": "2023-01-25T14:32:38.102906Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
Confusion matrix for multiple cancer prediction models.
Model:Decision TreeRegression
Predicted:TumourNon-TumourTumourNon-Tumour
Actual Label:    
Tumour (Positive)3821822
Non-Tumour (Negative)194396452
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 27, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "s.set_caption(\"Confusion matrix for multiple cancer prediction models.\")\\\n", - " .set_table_styles([{\n", - " 'selector': 'caption',\n", - " 'props': 'caption-side: bottom; font-size:1.25em;'\n", - " }], overwrite=False)" - ] - }, - { - "cell_type": "code", - "execution_count": 28, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:38.104657Z", - "iopub.status.busy": "2023-01-25T14:32:38.104568Z", - "iopub.status.idle": "2023-01-25T14:32:38.115249Z", - "shell.execute_reply": "2023-01-25T14:32:38.115013Z" - }, - "nbsphinx": "hidden" - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
Confusion matrix for multiple cancer prediction models.
Model:Decision TreeRegression
Predicted:TumourNon-TumourTumourNon-Tumour
Actual Label:    
Tumour (Positive)3821822
Non-Tumour (Negative)194396452
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 28, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Hidden cell to avoid CSS clashes and latter code upcoding previous formatting \n", - "s.set_uuid('after_caption')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Adding tooltips (*since version 1.3.0*) can be done using the [.set_tooltips()][tooltips] method in the same way you can add CSS classes to data cells by providing a string based DataFrame with intersecting indices and columns. You don't have to specify a `css_class` name or any css `props` for the tooltips, since there are standard defaults, but the option is there if you want more visual control. \n", - "\n", - "[tooltips]: ../reference/api/pandas.io.formats.style.Styler.set_tooltips.rst" - ] - }, - { - "cell_type": "code", - "execution_count": 29, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:38.116684Z", - "iopub.status.busy": "2023-01-25T14:32:38.116603Z", - "iopub.status.idle": "2023-01-25T14:32:38.128590Z", - "shell.execute_reply": "2023-01-25T14:32:38.128332Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
Confusion matrix for multiple cancer prediction models.
Model:Decision TreeRegression
Predicted:TumourNon-TumourTumourNon-Tumour
Actual Label:    
Tumour (Positive)3821822
Non-Tumour (Negative)194396452
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 29, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "tt = pd.DataFrame([['This model has a very strong true positive rate', \n", - " \"This model's total number of false negatives is too high\"]], \n", - " index=['Tumour (Positive)'], columns=df.columns[[0,3]])\n", - "s.set_tooltips(tt, props='visibility: hidden; position: absolute; z-index: 1; border: 1px solid #000066;'\n", - " 'background-color: white; color: #000066; font-size: 0.8em;' \n", - " 'transform: translate(0px, -24px); padding: 0.6em; border-radius: 0.5em;')" - ] - }, - { - "cell_type": "code", - "execution_count": 30, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:38.130086Z", - "iopub.status.busy": "2023-01-25T14:32:38.130001Z", - "iopub.status.idle": "2023-01-25T14:32:38.141444Z", - "shell.execute_reply": "2023-01-25T14:32:38.141199Z" - }, - "nbsphinx": "hidden" - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
Confusion matrix for multiple cancer prediction models.
Model:Decision TreeRegression
Predicted:TumourNon-TumourTumourNon-Tumour
Actual Label:    
Tumour (Positive)3821822
Non-Tumour (Negative)194396452
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 30, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Hidden cell to avoid CSS clashes and latter code upcoding previous formatting \n", - "s.set_uuid('after_tooltips')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The only thing left to do for our table is to add the highlighting borders to draw the audience attention to the tooltips. We will create internal CSS classes as before using table styles. **Setting classes always overwrites** so we need to make sure we add the previous classes." - ] - }, - { - "cell_type": "code", - "execution_count": 31, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:38.142916Z", - "iopub.status.busy": "2023-01-25T14:32:38.142833Z", - "iopub.status.idle": "2023-01-25T14:32:38.155848Z", - "shell.execute_reply": "2023-01-25T14:32:38.155603Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
Confusion matrix for multiple cancer prediction models.
Model:Decision TreeRegression
Predicted:TumourNon-TumourTumourNon-Tumour
Actual Label:    
Tumour (Positive)3821822
Non-Tumour (Negative)194396452
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 31, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "s.set_table_styles([ # create internal CSS classes\n", - " {'selector': '.border-red', 'props': 'border: 2px dashed red;'},\n", - " {'selector': '.border-green', 'props': 'border: 2px dashed green;'},\n", - "], overwrite=False)\n", - "cell_border = pd.DataFrame([['border-green ', ' ', ' ', 'border-red '], \n", - " [' ', ' ', ' ', ' ']], \n", - " index=df.index, \n", - " columns=df.columns[:4])\n", - "s.set_td_classes(cell_color + cell_border)" - ] - }, - { - "cell_type": "code", - "execution_count": 32, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:38.157239Z", - "iopub.status.busy": "2023-01-25T14:32:38.157159Z", - "iopub.status.idle": "2023-01-25T14:32:38.169339Z", - "shell.execute_reply": "2023-01-25T14:32:38.169102Z" - }, - "nbsphinx": "hidden" - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
Confusion matrix for multiple cancer prediction models.
Model:Decision TreeRegression
Predicted:TumourNon-TumourTumourNon-Tumour
Actual Label:    
Tumour (Positive)3821822
Non-Tumour (Negative)194396452
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 32, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Hidden cell to avoid CSS clashes and latter code upcoding previous formatting \n", - "s.set_uuid('after_borders')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Finer Control with Slicing\n", - "\n", - "The examples we have shown so far for the `Styler.apply` and `Styler.applymap` functions have not demonstrated the use of the ``subset`` argument. This is a useful argument which permits a lot of flexibility: it allows you to apply styles to specific rows or columns, without having to code that logic into your `style` function.\n", - "\n", - "The value passed to `subset` behaves similar to slicing a DataFrame;\n", - "\n", - "- A scalar is treated as a column label\n", - "- A list (or Series or NumPy array) is treated as multiple column labels\n", - "- A tuple is treated as `(row_indexer, column_indexer)`\n", - "\n", - "Consider using `pd.IndexSlice` to construct the tuple for the last one. We will create a MultiIndexed DataFrame to demonstrate the functionality." - ] - }, - { - "cell_type": "code", - "execution_count": 33, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:38.170799Z", - "iopub.status.busy": "2023-01-25T14:32:38.170719Z", - "iopub.status.idle": "2023-01-25T14:32:38.183159Z", - "shell.execute_reply": "2023-01-25T14:32:38.182909Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
c1c2c3c4
Ar1-1.048553-1.420018-1.7062701.950775
r2-0.509652-0.438074-1.2527950.777490
Br1-1.613898-0.212740-0.8954670.386902
r2-0.510805-1.180632-0.0281820.428332
\n", - "
" - ], - "text/plain": [ - " c1 c2 c3 c4\n", - "A r1 -1.048553 -1.420018 -1.706270 1.950775\n", - " r2 -0.509652 -0.438074 -1.252795 0.777490\n", - "B r1 -1.613898 -0.212740 -0.895467 0.386902\n", - " r2 -0.510805 -1.180632 -0.028182 0.428332" - ] - }, - "execution_count": 33, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df3 = pd.DataFrame(np.random.randn(4,4), \n", - " pd.MultiIndex.from_product([['A', 'B'], ['r1', 'r2']]),\n", - " columns=['c1','c2','c3','c4'])\n", - "df3" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We will use subset to highlight the maximum in the third and fourth columns with red text. We will highlight the subset sliced region in yellow." - ] - }, - { - "cell_type": "code", - "execution_count": 34, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:38.184657Z", - "iopub.status.busy": "2023-01-25T14:32:38.184573Z", - "iopub.status.idle": "2023-01-25T14:32:38.197221Z", - "shell.execute_reply": "2023-01-25T14:32:38.196957Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
  c1c2c3c4
Ar1-1.048553-1.420018-1.7062701.950775
r2-0.509652-0.438074-1.2527950.777490
Br1-1.613898-0.212740-0.8954670.386902
r2-0.510805-1.180632-0.0281820.428332
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 34, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "slice_ = ['c3', 'c4']\n", - "df3.style.apply(highlight_max, props='color:red;', axis=0, subset=slice_)\\\n", - " .set_properties(**{'background-color': '#ffffb3'}, subset=slice_)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "If combined with the ``IndexSlice`` as suggested then it can index across both dimensions with greater flexibility." - ] - }, - { - "cell_type": "code", - "execution_count": 35, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:38.198695Z", - "iopub.status.busy": "2023-01-25T14:32:38.198614Z", - "iopub.status.idle": "2023-01-25T14:32:38.212302Z", - "shell.execute_reply": "2023-01-25T14:32:38.212036Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
  c1c2c3c4
Ar1-1.048553-1.420018-1.7062701.950775
r2-0.509652-0.438074-1.2527950.777490
Br1-1.613898-0.212740-0.8954670.386902
r2-0.510805-1.180632-0.0281820.428332
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 35, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "idx = pd.IndexSlice\n", - "slice_ = idx[idx[:,'r1'], idx['c2':'c4']]\n", - "df3.style.apply(highlight_max, props='color:red;', axis=0, subset=slice_)\\\n", - " .set_properties(**{'background-color': '#ffffb3'}, subset=slice_)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "This also provides the flexibility to sub select rows when used with the `axis=1`." - ] - }, - { - "cell_type": "code", - "execution_count": 36, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:38.213771Z", - "iopub.status.busy": "2023-01-25T14:32:38.213692Z", - "iopub.status.idle": "2023-01-25T14:32:38.226678Z", - "shell.execute_reply": "2023-01-25T14:32:38.226429Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
  c1c2c3c4
Ar1-1.048553-1.420018-1.7062701.950775
r2-0.509652-0.438074-1.2527950.777490
Br1-1.613898-0.212740-0.8954670.386902
r2-0.510805-1.180632-0.0281820.428332
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 36, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "slice_ = idx[idx[:,'r2'], :]\n", - "df3.style.apply(highlight_max, props='color:red;', axis=1, subset=slice_)\\\n", - " .set_properties(**{'background-color': '#ffffb3'}, subset=slice_)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "There is also scope to provide **conditional filtering**. \n", - "\n", - "Suppose we want to highlight the maximum across columns 2 and 4 only in the case that the sum of columns 1 and 3 is less than -2.0 *(essentially excluding rows* `(:,'r2')`*)*." - ] - }, - { - "cell_type": "code", - "execution_count": 37, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:38.228203Z", - "iopub.status.busy": "2023-01-25T14:32:38.228116Z", - "iopub.status.idle": "2023-01-25T14:32:38.241205Z", - "shell.execute_reply": "2023-01-25T14:32:38.240960Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
  c1c2c3c4
Ar1-1.048553-1.420018-1.7062701.950775
r2-0.509652-0.438074-1.2527950.777490
Br1-1.613898-0.212740-0.8954670.386902
r2-0.510805-1.180632-0.0281820.428332
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 37, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "slice_ = idx[idx[(df3['c1'] + df3['c3']) < -2.0], ['c2', 'c4']]\n", - "df3.style.apply(highlight_max, props='color:red;', axis=1, subset=slice_)\\\n", - " .set_properties(**{'background-color': '#ffffb3'}, subset=slice_)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Only label-based slicing is supported right now, not positional, and not callables.\n", - "\n", - "If your style function uses a `subset` or `axis` keyword argument, consider wrapping your function in a `functools.partial`, partialing out that keyword.\n", - "\n", - "```python\n", - "my_func2 = functools.partial(my_func, subset=42)\n", - "```" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Optimization\n", - "\n", - "Generally, for smaller tables and most cases, the rendered HTML does not need to be optimized, and we don't really recommend it. There are two cases where it is worth considering:\n", - "\n", - " - If you are rendering and styling a very large HTML table, certain browsers have performance issues.\n", - " - If you are using ``Styler`` to dynamically create part of online user interfaces and want to improve network performance.\n", - " \n", - "Here we recommend the following steps to implement:" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### 1. Remove UUID and cell_ids\n", - "\n", - "Ignore the `uuid` and set `cell_ids` to `False`. This will prevent unnecessary HTML." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "
\n", - "\n", - "This is sub-optimal:\n", - "\n", - "
" - ] - }, - { - "cell_type": "code", - "execution_count": 38, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:38.242920Z", - "iopub.status.busy": "2023-01-25T14:32:38.242813Z", - "iopub.status.idle": "2023-01-25T14:32:38.252636Z", - "shell.execute_reply": "2023-01-25T14:32:38.252372Z" - } - }, - "outputs": [], - "source": [ - "df4 = pd.DataFrame([[1,2],[3,4]])\n", - "s4 = df4.style" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "
\n", - "\n", - "This is better:\n", - "\n", - "
" - ] - }, - { - "cell_type": "code", - "execution_count": 39, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:38.254145Z", - "iopub.status.busy": "2023-01-25T14:32:38.254057Z", - "iopub.status.idle": "2023-01-25T14:32:38.263096Z", - "shell.execute_reply": "2023-01-25T14:32:38.262861Z" - } - }, - "outputs": [], - "source": [ - "from pandas.io.formats.style import Styler\n", - "s4 = Styler(df4, uuid_len=0, cell_ids=False)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### 2. Use table styles\n", - "\n", - "Use table styles where possible (e.g. for all cells or rows or columns at a time) since the CSS is nearly always more efficient than other formats." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "
\n", - "\n", - "This is sub-optimal:\n", - "\n", - "
" - ] - }, - { - "cell_type": "code", - "execution_count": 40, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:38.264589Z", - "iopub.status.busy": "2023-01-25T14:32:38.264506Z", - "iopub.status.idle": "2023-01-25T14:32:38.275120Z", - "shell.execute_reply": "2023-01-25T14:32:38.274872Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
 01
012
134
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 40, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "props = 'font-family: \"Times New Roman\", Times, serif; color: #e83e8c; font-size:1.3em;'\n", - "df4.style.applymap(lambda x: props, subset=[1])" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "
\n", - "\n", - "This is better:\n", - "\n", - "
" - ] - }, - { - "cell_type": "code", - "execution_count": 41, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:38.276627Z", - "iopub.status.busy": "2023-01-25T14:32:38.276546Z", - "iopub.status.idle": "2023-01-25T14:32:38.287499Z", - "shell.execute_reply": "2023-01-25T14:32:38.287231Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
 01
012
134
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 41, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df4.style.set_table_styles([{'selector': 'td.col1', 'props': props}])" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### 3. Set classes instead of using Styler functions\n", - "\n", - "For large DataFrames where the same style is applied to many cells it can be more efficient to declare the styles as classes and then apply those classes to data cells, rather than directly applying styles to cells. It is, however, probably still easier to use the Styler function api when you are not concerned about optimization." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "
\n", - "\n", - "This is sub-optimal:\n", - "\n", - "
" - ] - }, - { - "cell_type": "code", - "execution_count": 42, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:38.289173Z", - "iopub.status.busy": "2023-01-25T14:32:38.289065Z", - "iopub.status.idle": "2023-01-25T14:32:38.302777Z", - "shell.execute_reply": "2023-01-25T14:32:38.302515Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
 ABCD
01.7640520.4001570.9787382.240893
11.867558-0.9772780.950088-0.151357
2-0.1032190.4105990.1440441.454274
30.7610380.1216750.4438630.333674
41.494079-0.2051580.313068-0.854096
5-2.5529900.6536190.864436-0.742165
62.269755-1.4543660.045759-0.187184
71.5327791.4693590.1549470.378163
8-0.887786-1.980796-0.3479120.156349
91.2302911.202380-0.387327-0.302303
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 42, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df2.style.apply(highlight_max, props='color:white;background-color:darkblue;', axis=0)\\\n", - " .apply(highlight_max, props='color:white;background-color:pink;', axis=1)\\\n", - " .apply(highlight_max, props='color:white;background-color:purple', axis=None)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "
\n", - "\n", - "This is better:\n", - "\n", - "
" - ] - }, - { - "cell_type": "code", - "execution_count": 43, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:38.304299Z", - "iopub.status.busy": "2023-01-25T14:32:38.304215Z", - "iopub.status.idle": "2023-01-25T14:32:38.318437Z", - "shell.execute_reply": "2023-01-25T14:32:38.318184Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
 ABCD
01.7640520.4001570.9787382.240893
11.867558-0.9772780.950088-0.151357
2-0.1032190.4105990.1440441.454274
30.7610380.1216750.4438630.333674
41.494079-0.2051580.313068-0.854096
5-2.5529900.6536190.864436-0.742165
62.269755-1.4543660.045759-0.187184
71.5327791.4693590.1549470.378163
8-0.887786-1.980796-0.3479120.156349
91.2302911.202380-0.387327-0.302303
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 43, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "build = lambda x: pd.DataFrame(x, index=df2.index, columns=df2.columns)\n", - "cls1 = build(df2.apply(highlight_max, props='cls-1 ', axis=0))\n", - "cls2 = build(df2.apply(highlight_max, props='cls-2 ', axis=1, result_type='expand').values)\n", - "cls3 = build(highlight_max(df2, props='cls-3 '))\n", - "df2.style.set_table_styles([\n", - " {'selector': '.cls-1', 'props': 'color:white;background-color:darkblue;'},\n", - " {'selector': '.cls-2', 'props': 'color:white;background-color:pink;'},\n", - " {'selector': '.cls-3', 'props': 'color:white;background-color:purple;'}\n", - "]).set_td_classes(cls1 + cls2 + cls3)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### 4. Don't use tooltips\n", - "\n", - "Tooltips require `cell_ids` to work and they generate extra HTML elements for *every* data cell." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### 5. If every byte counts use string replacement\n", - "\n", - "You can remove unnecessary HTML, or shorten the default class names by replacing the default css dict. You can read a little more about CSS [below](#More-About-CSS-and-HTML)." - ] - }, - { - "cell_type": "code", - "execution_count": 44, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:38.320001Z", - "iopub.status.busy": "2023-01-25T14:32:38.319916Z", - "iopub.status.idle": "2023-01-25T14:32:38.331000Z", - "shell.execute_reply": "2023-01-25T14:32:38.330759Z" - } - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
 01
012
134
\n", - "\n" - ] - } - ], - "source": [ - "my_css = {\n", - " \"row_heading\": \"\",\n", - " \"col_heading\": \"\",\n", - " \"index_name\": \"\",\n", - " \"col\": \"c\",\n", - " \"row\": \"r\",\n", - " \"col_trim\": \"\",\n", - " \"row_trim\": \"\",\n", - " \"level\": \"l\",\n", - " \"data\": \"\",\n", - " \"blank\": \"\",\n", - "}\n", - "html = Styler(df4, uuid_len=0, cell_ids=False)\n", - "html.set_table_styles([{'selector': 'td', 'props': props},\n", - " {'selector': '.c1', 'props': 'color:green;'},\n", - " {'selector': '.l0', 'props': 'color:blue;'}],\n", - " css_class_names=my_css)\n", - "print(html.to_html())" - ] - }, - { - "cell_type": "code", - "execution_count": 45, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:38.332531Z", - "iopub.status.busy": "2023-01-25T14:32:38.332448Z", - "iopub.status.idle": "2023-01-25T14:32:38.342396Z", - "shell.execute_reply": "2023-01-25T14:32:38.342145Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
 01
012
134
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 45, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "html" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Builtin Styles" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "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 on their, or other, values on a numeric scale.\n", - " - [.text_gradient][textfunc]: similar method for highlighting text based on 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", - "[textfunc]: ../reference/api/pandas.io.formats.style.Styler.text_gradient.rst\n", - "[barfunc]: ../reference/api/pandas.io.formats.style.Styler.bar.rst" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Highlight Null" - ] - }, - { - "cell_type": "code", - "execution_count": 46, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:38.343938Z", - "iopub.status.busy": "2023-01-25T14:32:38.343854Z", - "iopub.status.idle": "2023-01-25T14:32:38.355069Z", - "shell.execute_reply": "2023-01-25T14:32:38.354815Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
 ABCD
01.7640520.400157nan2.240893
11.867558-0.9772780.950088-0.151357
2-0.1032190.4105990.1440441.454274
30.7610380.1216750.4438630.333674
41.494079-0.2051580.313068nan
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 46, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df2.iloc[0,2] = np.nan\n", - "df2.iloc[4,3] = np.nan\n", - "df2.loc[:4].style.highlight_null(color='yellow')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Highlight Min or Max" - ] - }, - { - "cell_type": "code", - "execution_count": 47, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:38.356596Z", - "iopub.status.busy": "2023-01-25T14:32:38.356512Z", - "iopub.status.idle": "2023-01-25T14:32:38.368646Z", - "shell.execute_reply": "2023-01-25T14:32:38.368390Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
 ABCD
01.7640520.400157nan2.240893
11.867558-0.9772780.950088-0.151357
2-0.1032190.4105990.1440441.454274
30.7610380.1216750.4438630.333674
41.494079-0.2051580.313068nan
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 47, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df2.loc[:4].style.highlight_max(axis=1, props='color:white; font-weight:bold; background-color:darkblue;')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Highlight Between\n", - "This method accepts ranges as float, or NumPy arrays or Series provided the indexes match." - ] - }, - { - "cell_type": "code", - "execution_count": 48, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:38.370117Z", - "iopub.status.busy": "2023-01-25T14:32:38.370038Z", - "iopub.status.idle": "2023-01-25T14:32:38.383825Z", - "shell.execute_reply": "2023-01-25T14:32:38.383590Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
 ABCD
01.7640520.400157nan2.240893
11.867558-0.9772780.950088-0.151357
2-0.1032190.4105990.1440441.454274
30.7610380.1216750.4438630.333674
41.494079-0.2051580.313068nan
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 48, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "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" - ] - }, - { - "cell_type": "code", - "execution_count": 49, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:38.385273Z", - "iopub.status.busy": "2023-01-25T14:32:38.385192Z", - "iopub.status.idle": "2023-01-25T14:32:38.397125Z", - "shell.execute_reply": "2023-01-25T14:32:38.396863Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
 ABCD
01.7640520.400157nan2.240893
11.867558-0.9772780.950088-0.151357
2-0.1032190.4105990.1440441.454274
30.7610380.1216750.4438630.333674
41.494079-0.2051580.313068nan
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 49, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df2.loc[:4].style.highlight_quantile(q_left=0.85, axis=None, color='yellow')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Background Gradient and Text Gradient" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "You can create \"heatmaps\" with the `background_gradient` and `text_gradient` methods. These require matplotlib, and we'll use [Seaborn](http://seaborn.pydata.org/) to get a nice colormap." - ] - }, - { - "cell_type": "code", - "execution_count": 50, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:38.398704Z", - "iopub.status.busy": "2023-01-25T14:32:38.398617Z", - "iopub.status.idle": "2023-01-25T14:32:38.702950Z", - "shell.execute_reply": "2023-01-25T14:32:38.702688Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
 ABCD
01.7640520.400157nan2.240893
11.867558-0.9772780.950088-0.151357
2-0.1032190.4105990.1440441.454274
30.7610380.1216750.4438630.333674
41.494079-0.2051580.313068nan
5-2.5529900.6536190.864436-0.742165
62.269755-1.4543660.045759-0.187184
71.5327791.4693590.1549470.378163
8-0.887786-1.980796-0.3479120.156349
91.2302911.202380-0.387327-0.302303
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 50, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "import seaborn as sns\n", - "cm = sns.light_palette(\"green\", as_cmap=True)\n", - "\n", - "df2.style.background_gradient(cmap=cm)" - ] - }, - { - "cell_type": "code", - "execution_count": 51, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:38.704450Z", - "iopub.status.busy": "2023-01-25T14:32:38.704364Z", - "iopub.status.idle": "2023-01-25T14:32:38.720244Z", - "shell.execute_reply": "2023-01-25T14:32:38.719996Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
 ABCD
01.7640520.400157nan2.240893
11.867558-0.9772780.950088-0.151357
2-0.1032190.4105990.1440441.454274
30.7610380.1216750.4438630.333674
41.494079-0.2051580.313068nan
5-2.5529900.6536190.864436-0.742165
62.269755-1.4543660.045759-0.187184
71.5327791.4693590.1549470.378163
8-0.887786-1.980796-0.3479120.156349
91.2302911.202380-0.387327-0.302303
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 51, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df2.style.text_gradient(cmap=cm)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "[.background_gradient][bgfunc] and [.text_gradient][textfunc] have a number of keyword arguments to customise the gradients and colors. See the documentation.\n", - "\n", - "[bgfunc]: ../reference/api/pandas.io.formats.style.Styler.background_gradient.rst\n", - "[textfunc]: ../reference/api/pandas.io.formats.style.Styler.text_gradient.rst" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Set properties\n", - "\n", - "Use `Styler.set_properties` when the style doesn't actually depend on the values. This is just a simple wrapper for `.applymap` where the function returns the same properties for all cells." - ] - }, - { - "cell_type": "code", - "execution_count": 52, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:38.721908Z", - "iopub.status.busy": "2023-01-25T14:32:38.721808Z", - "iopub.status.idle": "2023-01-25T14:32:38.736051Z", - "shell.execute_reply": "2023-01-25T14:32:38.735805Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
 ABCD
01.7640520.400157nan2.240893
11.867558-0.9772780.950088-0.151357
2-0.1032190.4105990.1440441.454274
30.7610380.1216750.4438630.333674
41.494079-0.2051580.313068nan
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 52, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df2.loc[:4].style.set_properties(**{'background-color': 'black',\n", - " 'color': 'lawngreen',\n", - " 'border-color': 'white'})" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Bar charts" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "You can include \"bar charts\" in your DataFrame." - ] - }, - { - "cell_type": "code", - "execution_count": 53, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:38.737574Z", - "iopub.status.busy": "2023-01-25T14:32:38.737498Z", - "iopub.status.idle": "2023-01-25T14:32:38.751498Z", - "shell.execute_reply": "2023-01-25T14:32:38.751232Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
 ABCD
01.7640520.400157nan2.240893
11.867558-0.9772780.950088-0.151357
2-0.1032190.4105990.1440441.454274
30.7610380.1216750.4438630.333674
41.494079-0.2051580.313068nan
5-2.5529900.6536190.864436-0.742165
62.269755-1.4543660.045759-0.187184
71.5327791.4693590.1549470.378163
8-0.887786-1.980796-0.3479120.156349
91.2302911.202380-0.387327-0.302303
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 53, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df2.style.bar(subset=['A', 'B'], color='#d65f5f')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Additional keyword arguments give more control on centering and positioning, and you can pass a list of `[color_negative, color_positive]` to highlight lower and higher values or a matplotlib colormap.\n", - "\n", - "To showcase an example here's how you can change the above with the new `align` option, combined with setting `vmin` and `vmax` limits, the `width` of the figure, and underlying css `props` of cells, leaving space to display the text and the bars. We also use `text_gradient` to color the text the same as the bars using a matplotlib colormap (although in this case the visualization is probably better without this additional effect)." - ] - }, - { - "cell_type": "code", - "execution_count": 54, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:38.752993Z", - "iopub.status.busy": "2023-01-25T14:32:38.752901Z", - "iopub.status.idle": "2023-01-25T14:32:38.771171Z", - "shell.execute_reply": "2023-01-25T14:32:38.770928Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
 ABCD
01.7640.4002.241
11.868-0.9770.950-0.151
2-0.1030.4110.1441.454
30.7610.1220.4440.334
41.494-0.2050.313
5-2.5530.6540.864-0.742
62.270-1.4540.046-0.187
71.5331.4690.1550.378
8-0.888-1.981-0.3480.156
91.2301.202-0.387-0.302
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 54, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df2.style.format('{:.3f}', na_rep=\"\")\\\n", - " .bar(align=0, vmin=-2.5, vmax=2.5, cmap=\"bwr\", height=50,\n", - " width=60, props=\"width: 120px; border-right: 1px solid black;\")\\\n", - " .text_gradient(cmap=\"bwr\", vmin=-2.5, vmax=2.5)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The following example aims to give a highlight of the behavior of the new align options:" - ] - }, - { - "cell_type": "code", - "execution_count": 55, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:38.772653Z", - "iopub.status.busy": "2023-01-25T14:32:38.772570Z", - "iopub.status.idle": "2023-01-25T14:32:38.805213Z", - "shell.execute_reply": "2023-01-25T14:32:38.804963Z" - }, - "nbsphinx": "hidden" - }, - "outputs": [], - "source": [ - "# Hide the construction of the display chart from the user\n", - "import pandas as pd\n", - "from IPython.display import HTML\n", - "\n", - "# Test series\n", - "test1 = pd.Series([-100,-60,-30,-20], name='All Negative')\n", - "test2 = pd.Series([-10,-5,0,90], name='Both Pos and Neg')\n", - "test3 = pd.Series([10,20,50,100], name='All Positive')\n", - "test4 = pd.Series([100, 103, 101, 102], name='Large Positive')\n", - "\n", - "\n", - "head = \"\"\"\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "\n", - "\"\"\"\n", - "\n", - "aligns = ['left', 'right', 'zero', 'mid', 'mean', 99]\n", - "for align in aligns:\n", - " row = \"\".format(align)\n", - " for series in [test1,test2,test3, test4]:\n", - " s = series.copy()\n", - " s.name=''\n", - " row += \"\".format(s.to_frame().style.hide(axis='index').bar(align=align, \n", - " color=['#d65f5f', '#5fba7d'], \n", - " width=100).to_html()) #testn['width']\n", - " row += ''\n", - " head += row\n", - " \n", - "head+= \"\"\"\n", - "\n", - "
AlignAll NegativeBoth Neg and PosAll PositiveLarge Positive
{}{}
\"\"\"" - ] - }, - { - "cell_type": "code", - "execution_count": 56, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:38.806727Z", - "iopub.status.busy": "2023-01-25T14:32:38.806640Z", - "iopub.status.idle": "2023-01-25T14:32:38.819385Z", - "shell.execute_reply": "2023-01-25T14:32:38.819133Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "\n", - "\n", - "\n", - "
AlignAll NegativeBoth Neg and PosAll PositiveLarge Positive
left\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
-100
-60
-30
-20
\n", - "
\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
-10
-5
0
90
\n", - "
\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
10
20
50
100
\n", - "
\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
100
103
101
102
\n", - "
right\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
-100
-60
-30
-20
\n", - "
\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
-10
-5
0
90
\n", - "
\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
10
20
50
100
\n", - "
\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
100
103
101
102
\n", - "
zero\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
-100
-60
-30
-20
\n", - "
\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
-10
-5
0
90
\n", - "
\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
10
20
50
100
\n", - "
\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
100
103
101
102
\n", - "
mid\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
-100
-60
-30
-20
\n", - "
\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
-10
-5
0
90
\n", - "
\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
10
20
50
100
\n", - "
\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
100
103
101
102
\n", - "
mean\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
-100
-60
-30
-20
\n", - "
\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
-10
-5
0
90
\n", - "
\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
10
20
50
100
\n", - "
\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
100
103
101
102
\n", - "
99\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
-100
-60
-30
-20
\n", - "
\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
-10
-5
0
90
\n", - "
\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
10
20
50
100
\n", - "
\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
100
103
101
102
\n", - "
" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 56, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "HTML(head)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Sharing styles" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Say you have a lovely style built up for a DataFrame, and now you want to apply the same style to a second DataFrame. Export the style with `df1.style.export`, and import it on the second DataFrame with `df1.style.set`" - ] - }, - { - "cell_type": "code", - "execution_count": 57, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:38.820959Z", - "iopub.status.busy": "2023-01-25T14:32:38.820858Z", - "iopub.status.idle": "2023-01-25T14:32:38.835897Z", - "shell.execute_reply": "2023-01-25T14:32:38.835647Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
ABCD
1.7640520.400157nan2.240893
1.867558-0.9772780.950088-0.151357
-0.1032190.4105990.1440441.454274
0.7610380.1216750.4438630.333674
1.494079-0.2051580.313068nan
-2.5529900.6536190.864436-0.742165
2.269755-1.4543660.045759-0.187184
1.5327791.4693590.1549470.378163
-0.887786-1.980796-0.3479120.156349
1.2302911.202380-0.387327-0.302303
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 57, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "style1 = df2.style\\\n", - " .applymap(style_negative, props='color:red;')\\\n", - " .applymap(lambda v: 'opacity: 20%;' if (v < 0.3) and (v > -0.3) else None)\\\n", - " .set_table_styles([{\"selector\": \"th\", \"props\": \"color: blue;\"}])\\\n", - " .hide(axis=\"index\")\n", - "style1" - ] - }, - { - "cell_type": "code", - "execution_count": 58, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:38.837321Z", - "iopub.status.busy": "2023-01-25T14:32:38.837244Z", - "iopub.status.idle": "2023-01-25T14:32:38.851485Z", - "shell.execute_reply": "2023-01-25T14:32:38.851245Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
c1c2c3c4
-1.048553-1.420018-1.7062701.950775
-0.509652-0.438074-1.2527950.777490
-1.613898-0.212740-0.8954670.386902
-0.510805-1.180632-0.0281820.428332
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 58, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "style2 = df3.style\n", - "style2.use(style1.export())\n", - "style2" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Notice that you're able to share the styles even though they're data aware. The styles are re-evaluated on the new DataFrame they've been `use`d upon." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Limitations\n", - "\n", - "- DataFrame only (use `Series.to_frame().style`)\n", - "- The index and columns do not need to be unique, but certain styling functions can only work with unique indexes.\n", - "- No large repr, and construction performance isn't great; although we have some [HTML optimizations](#Optimization)\n", - "- You can only apply styles, you can't insert new HTML entities, except via subclassing." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Other Fun and Useful Stuff\n", - "\n", - "Here are a few interesting examples." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Widgets\n", - "\n", - "`Styler` interacts pretty well with widgets. If you're viewing this online instead of running the notebook yourself, you're missing out on interactively adjusting the color palette." - ] - }, - { - "cell_type": "code", - "execution_count": 59, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:38.853142Z", - "iopub.status.busy": "2023-01-25T14:32:38.853040Z", - "iopub.status.idle": "2023-01-25T14:32:38.890100Z", - "shell.execute_reply": "2023-01-25T14:32:38.889853Z" - } - }, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "9ca04a7e7da044a99aa6dc1e31c0127a", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "interactive(children=(IntSlider(value=179, description='h_neg', max=359), IntSlider(value=179, description='h_…" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "from ipywidgets import widgets\n", - "@widgets.interact\n", - "def f(h_neg=(0, 359, 1), h_pos=(0, 359), s=(0., 99.9), l=(0., 99.9)):\n", - " return df2.style.background_gradient(\n", - " cmap=sns.palettes.diverging_palette(h_neg=h_neg, h_pos=h_pos, s=s, l=l,\n", - " as_cmap=True)\n", - " )" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Magnify" - ] - }, - { - "cell_type": "code", - "execution_count": 60, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:38.891938Z", - "iopub.status.busy": "2023-01-25T14:32:38.891846Z", - "iopub.status.idle": "2023-01-25T14:32:38.905592Z", - "shell.execute_reply": "2023-01-25T14:32:38.905316Z" - } - }, - "outputs": [], - "source": [ - "def magnify():\n", - " return [dict(selector=\"th\",\n", - " props=[(\"font-size\", \"4pt\")]),\n", - " dict(selector=\"td\",\n", - " props=[('padding', \"0em 0em\")]),\n", - " dict(selector=\"th:hover\",\n", - " props=[(\"font-size\", \"12pt\")]),\n", - " dict(selector=\"tr:hover td:hover\",\n", - " props=[('max-width', '200px'),\n", - " ('font-size', '12pt')])\n", - "]" - ] - }, - { - "cell_type": "code", - "execution_count": 61, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:38.907210Z", - "iopub.status.busy": "2023-01-25T14:32:38.907120Z", - "iopub.status.idle": "2023-01-25T14:32:38.941622Z", - "shell.execute_reply": "2023-01-25T14:32:38.941329Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
Hover to magnify
 0123456789101112131415161718192021222324
00.231.03-0.84-0.59-0.96-0.22-0.621.84-2.050.87-0.92-0.232.15-1.330.08-1.251.20-1.051.06-0.422.29-2.592.820.68-1.58
1-1.751.56-1.13-1.101.030.00-2.463.45-1.661.27-0.52-0.021.52-1.09-1.86-1.13-0.68-0.810.35-0.061.79-2.822.260.780.44
2-0.653.22-1.760.522.20-0.37-3.003.73-1.872.460.21-0.24-0.10-0.78-3.02-0.82-0.21-0.230.86-0.681.45-4.893.031.910.61
3-1.623.71-2.310.434.17-0.43-3.864.16-2.151.080.120.60-0.890.27-3.67-2.71-0.31-1.591.35-1.830.91-5.802.812.110.28
4-3.354.48-1.86-1.705.19-1.02-3.814.72-0.721.08-0.180.83-0.22-1.08-4.27-2.88-0.97-1.781.53-1.802.21-6.343.342.492.09
5-0.844.23-1.65-2.005.34-0.99-4.133.94-1.06-0.941.240.09-1.78-0.11-4.45-0.85-2.06-1.350.80-1.631.54-6.512.802.143.77
6-0.745.35-2.11-1.134.20-1.85-3.203.76-3.22-1.230.340.57-1.820.54-4.43-1.83-4.03-2.62-0.20-4.681.93-8.463.342.525.81
7-0.444.69-2.30-0.215.93-2.63-1.835.46-4.50-3.16-1.730.180.110.04-5.99-0.45-6.20-3.890.71-3.950.67-7.262.973.396.66
80.925.80-3.33-0.655.99-3.19-1.835.63-3.53-1.30-1.610.82-2.45-0.40-6.06-0.52-6.60-3.48-0.04-4.600.51-5.853.232.405.08
90.385.54-4.49-0.807.05-2.64-0.445.35-1.96-0.33-0.800.26-3.37-0.82-6.05-2.61-8.45-4.450.41-4.711.89-6.932.143.005.16
102.065.84-3.90-0.987.78-2.49-0.595.59-2.22-0.71-0.461.80-2.790.48-5.97-3.44-7.77-5.49-0.70-4.61-0.52-7.721.545.025.81
111.864.47-2.17-1.385.90-0.490.025.78-1.04-0.600.491.96-1.471.88-5.92-4.55-8.15-3.42-2.24-4.33-1.17-7.901.365.315.83
123.194.22-3.06-2.275.93-2.640.336.72-2.84-0.201.892.63-1.530.75-5.27-4.53-7.57-2.85-2.17-4.78-1.13-8.992.116.425.60
132.314.45-3.87-2.056.76-3.25-2.177.99-2.56-0.800.712.33-0.16-0.46-5.10-3.79-7.58-4.000.33-3.67-1.05-8.712.475.876.71
143.784.33-3.88-1.586.22-3.23-1.465.57-2.93-0.33-0.971.723.610.29-4.21-4.10-6.68-4.50-2.19-2.43-1.64-9.363.366.117.53
155.645.31-3.98-2.265.91-3.30-1.035.68-3.06-0.33-1.162.194.201.01-3.22-4.31-5.74-4.44-2.30-1.36-1.20-11.272.596.695.91
164.084.34-2.44-3.306.04-2.52-0.475.28-4.841.580.230.105.791.80-3.13-3.85-5.53-2.97-2.13-1.15-0.56-13.132.076.164.94
175.644.57-3.53-3.766.58-2.58-0.756.58-4.783.63-0.290.565.762.05-2.27-2.31-4.95-3.16-3.06-2.430.84-12.573.567.364.70
185.995.82-2.85-4.157.12-3.32-1.217.93-4.851.44-0.630.357.470.87-1.52-2.09-4.23-2.55-2.46-2.891.90-9.743.437.074.39
194.036.23-4.10-4.117.19-4.10-1.526.53-5.21-0.240.011.166.43-1.97-2.64-1.66-5.20-3.25-2.87-1.651.64-10.662.837.483.94
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 61, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "np.random.seed(25)\n", - "cmap = cmap=sns.diverging_palette(5, 250, as_cmap=True)\n", - "bigdf = pd.DataFrame(np.random.randn(20, 25)).cumsum()\n", - "\n", - "bigdf.style.background_gradient(cmap, axis=1)\\\n", - " .set_properties(**{'max-width': '80px', 'font-size': '1pt'})\\\n", - " .set_caption(\"Hover to magnify\")\\\n", - " .format(precision=2)\\\n", - " .set_table_styles(magnify())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Sticky Headers\n", - "\n", - "If you display a large matrix or DataFrame in a notebook, but you want to always see the column and row headers you can use the [.set_sticky][sticky] method which manipulates the table styles CSS.\n", - "\n", - "[sticky]: ../reference/api/pandas.io.formats.style.Styler.set_sticky.rst" - ] - }, - { - "cell_type": "code", - "execution_count": 62, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:38.943198Z", - "iopub.status.busy": "2023-01-25T14:32:38.943110Z", - "iopub.status.idle": "2023-01-25T14:32:38.971766Z", - "shell.execute_reply": "2023-01-25T14:32:38.971504Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
 0123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
0-0.773866-0.240521-0.2171651.1736090.6863900.0083580.6962320.1731660.6204980.5040670.428066-0.0518240.7199150.0571650.562808-0.3695360.4833990.620765-0.354342-1.469471-1.9372660.038031-1.518162-0.4175990.3867170.7161930.4899610.7339570.9144150.6798940.255448-0.5083380.332030-0.111107-0.251983-1.4566200.4096301.062320-0.5771150.718796-0.399260-1.3113890.6491220.0915660.6288720.297894-0.142290-0.542291-0.9142901.1445140.3135841.1826351.214235-0.416446-1.653940-2.5507870.4424730.052127-0.464469-0.5238520.989726-1.325539-0.199687-1.2267270.2900181.1645740.817841-0.3095090.4965990.943536-0.091850-2.8026582.126219-0.5211610.288098-0.454663-1.676143-0.357661-0.7889600.185911-0.0171062.4540201.832706-0.911743-0.655873-0.000514-2.2269970.677285-0.140249-0.408407-0.8386650.4822281.243458-0.477394-0.220343-2.4639660.237325-0.3073801.1724780.819492
10.405906-0.9789191.2675260.145250-1.066786-2.114192-1.128346-1.0825230.3722160.004127-0.2119840.937326-0.935890-1.7041180.611789-1.0300150.636123-1.5061931.7366091.3929581.0094240.3532660.697339-0.2974240.428702-0.145346-0.333553-0.9746990.6653140.9719440.121950-1.4396681.0188081.442399-0.199585-1.1659160.6456561.436466-0.9212151.293906-2.7064431.460928-0.8231970.292952-1.4489920.026692-0.9758830.3928230.4421660.7457411.187982-0.2185700.3052880.054932-1.476953-0.1144340.0141030.825394-0.060654-0.4136880.9748361.3392101.0348380.0407750.7050010.0177961.867681-0.3901732.2852772.311464-0.085070-0.6481150.576300-0.790087-1.183798-1.334558-0.4541180.3193021.7064880.8304290.502476-0.0796310.4146350.3325110.042935-0.1609100.918553-0.292697-1.303834-0.1996040.871023-1.370681-0.205701-0.4929731.123083-0.081842-0.1185270.245838-0.315742-0.511806
20.011470-0.0361041.399603-0.418176-0.412229-1.234783-1.1215001.196478-0.5695220.422022-0.2204840.8043382.892667-0.511055-0.168722-1.477996-1.9699170.4713541.6985480.137105-0.7620520.199379-0.964346-0.2566921.2652750.848762-0.7841611.863776-0.3555690.8545520.768061-2.075718-2.5010691.1098680.957545-0.6832760.3077640.7330731.706250-1.1180910.374961-1.414503-0.524183-1.6626960.6879210.5217321.451396-0.833491-0.362796-1.174444-0.813893-0.8932200.7707431.156647-0.6474440.1259290.513600-0.5378741.992052-1.946584-0.1047590.484779-0.290936-0.4410750.542993-1.0500381.6304820.239771-1.1773100.464804-0.9669950.6460860.4868991.022196-2.267827-1.2296161.3138051.0732922.324940-0.542720-1.5042920.777643-0.6185530.0113421.3850621.363552-0.5498340.6888961.361288-0.3811370.797812-1.1281980.3692080.5401320.413853-0.200308-0.9691260.981293-0.009783-0.320020
3-0.5748161.4199770.434813-1.101217-1.5862751.9795730.3782980.7823262.1789870.6575640.683774-0.091000-0.059552-0.738908-0.907653-0.7019360.580039-0.6187570.4536841.665382-0.1523210.8800770.571073-0.6047360.5323590.515031-0.959844-0.8871840.4357810.862093-0.956321-0.6259090.1944720.4424900.526503-0.2152740.0907110.9325920.811999-2.4970260.6315450.321418-0.425549-1.0788320.7534440.199790-0.360526-0.013448-0.8194760.8148690.442118-0.972048-0.060603-2.3498251.265445-0.5732570.4291241.0497831.9547730.071883-0.0942090.2656160.9483180.3316451.343401-0.167934-1.105252-0.167077-0.096576-0.838161-0.2085640.3945340.7625331.235357-0.207282-0.202946-0.4680250.2569442.5875841.186697-1.0319031.4283160.658899-0.046582-0.0754221.329359-0.684267-1.5241822.0140613.7709330.647353-1.021377-0.3454930.5828110.7978121.3260201.422857-3.0770070.1840831.478935
4-0.6001421.929561-2.346771-0.669700-1.1652580.8147880.444449-0.5767580.3530910.4088930.091391-2.2943890.485506-0.081304-0.716272-1.6480101.005361-1.4896030.3630980.758602-1.373847-0.9720571.9885370.3198291.1690600.1465851.0303881.1659841.3695630.730984-1.383696-0.515189-0.808927-1.174651-1.631502-1.123414-0.478155-1.5830671.4190741.6687771.5675170.222103-0.336040-1.3520640.251032-0.4016950.268413-0.012299-0.9189532.921208-0.5815880.6728481.2511361.3822631.4298971.290990-1.272673-0.308611-0.422988-0.6756420.8744411.305736-0.262585-1.099395-0.667101-0.646737-0.556338-0.1965910.119306-0.266455-0.5242672.6509510.097318-0.9746970.1899641.141155-0.0644341.104971-1.508908-0.0318330.803919-0.6592210.9391450.214041-0.5318050.9560600.2493280.637903-0.5101581.850287-0.3484072.001376-0.389643-0.024786-0.4709730.8693390.1706670.5980621.2172621.274013
5-0.389981-0.752441-0.7348713.517318-1.173559-0.0049560.1454192.151368-3.086037-1.5691391.449784-0.868951-1.687716-0.9944011.1532661.803045-0.8190590.8479700.227102-0.5007620.8682101.8235401.161007-0.307606-0.7134160.363560-0.8221622.427681-0.129537-0.0787161.345644-1.2860940.237242-0.1360560.596664-1.4123811.2063410.2998600.7052380.142412-1.0593820.8334681.060015-0.527045-1.135732-1.140983-0.779540-0.640875-1.217196-1.6756630.241263-0.273322-1.697936-0.5949430.1011541.391735-0.4269531.008344-0.8185771.924570-0.578900-0.457395-1.0967050.418522-0.1556230.169706-2.5337060.0189041.4341600.7440950.647626-0.7703092.329141-0.141547-1.7615940.702091-1.531450-0.788427-0.184622-1.9423211.5301130.5034061.105845-0.935120-1.115483-2.2497621.3071350.788412-0.4410910.0735610.812101-0.9161461.573714-0.3095080.4999870.1875940.5589130.9032460.317901-0.809797
61.1282481.516826-0.186735-0.6681571.132259-0.246648-0.8551670.7322830.9318021.318684-1.198418-1.1493180.586321-1.171937-0.6077312.7537471.479287-1.136365-0.0204850.320444-1.9557550.660402-1.5453710.200519-0.0172631.6346860.5992460.4629890.0237210.2255460.170972-0.027496-0.061233-0.566411-0.6695670.6016180.503656-0.678253-2.907108-1.7171230.3976311.3001080.215821-0.593075-0.225944-0.9460571.0003080.3931601.342074-0.370687-0.166413-0.419814-0.2559311.7894780.2823780.742260-0.0504981.4153090.838166-1.400292-0.937976-1.4991480.8018590.2248240.2835720.643703-1.1984650.5272060.2152020.4370481.3128680.7412430.0779880.0061230.1903700.018007-1.026036-2.378430-1.0699490.8438221.289216-1.423369-0.4628870.197330-0.9350760.4412710.414643-0.377887-0.5305150.6215921.0095720.5697180.175291-0.656279-0.112273-0.392137-1.043558-0.467318-0.384329-2.009207
70.6585980.101830-0.6827810.229349-0.3056570.4048770.252244-0.837784-0.0396240.3294570.7516941.469070-0.1571991.032628-0.584639-0.9255440.342474-0.9693630.133480-0.385974-0.6002780.2819390.8685791.129803-0.0418980.9611930.131521-0.792889-1.2857370.073934-1.333315-1.0441251.2773381.4922570.4113791.771805-1.1111281.123233-1.0194491.738357-0.690764-0.120710-0.421359-0.727294-0.857759-0.069436-0.328334-0.5581801.063474-0.519133-0.4969021.089589-1.6158010.080174-0.229938-0.498420-0.6246150.059481-0.093158-1.784549-0.503789-0.1405280.002653-0.4849300.055914-0.680948-0.9942711.2770520.0376512.155421-0.4375890.6964040.417752-0.5447851.1906900.9782620.7521020.5044720.139853-0.505089-0.264975-1.6031940.7318470.010903-1.165346-0.125195-1.032685-0.4655201.5148080.3047620.7934140.314635-1.6382790.111737-0.7770370.2517831.126303-0.8087980.422064-0.349264
8-0.356362-0.0892270.6093730.542382-0.768681-0.0480742.015458-1.5523510.2515521.4596350.9497070.339465-0.0013721.7985891.5591630.2317830.423141-0.3105300.3537952.173336-0.196247-0.375636-0.8582210.2584100.6564300.9608191.1378931.5534050.038981-0.632038-0.132009-1.834997-0.242576-0.297879-0.441559-0.7696910.224077-0.1530090.519526-0.6801880.5358510.671496-0.1830640.3012341.288256-2.478240-0.3604030.424067-0.834659-0.128464-0.489013-0.014888-1.461230-1.435223-1.3198021.0836750.979140-0.3752911.110189-1.0113510.587886-0.822775-1.1838651.4551731.1343280.239403-0.837991-1.1309320.7831681.8455201.437072-1.1984431.3790982.1291130.260096-0.0119750.0433020.7229411.028152-0.2358061.145245-1.3595980.2321890.503712-0.614264-0.530606-2.435803-0.255238-0.0644230.7846430.2563460.1280231.414103-1.1186590.8773530.5005610.463651-2.034512-0.981683-0.691944
9-1.113376-1.1694020.680539-1.5342121.653817-1.295181-0.5668260.4770141.4133710.5171051.401153-0.8726850.8309570.181507-0.1456160.694592-0.7512080.3244440.681973-0.0549720.917776-1.024810-0.206446-0.6001130.8528051.455109-0.0797690.0760760.207699-1.850458-0.124124-0.610871-0.8833620.219049-0.685094-0.645330-0.242805-0.7756020.2330702.422642-1.423040-0.5824210.968304-0.701025-0.1678500.2772641.3012310.301205-3.081249-0.5628680.192944-0.6645920.5656860.190913-0.841858-1.856545-1.0227771.2959680.4519210.6599550.065818-0.3195860.253495-1.144646-0.4834040.5559020.8070690.7141960.6611960.0536670.346833-1.288977-0.386734-1.2621270.477495-0.494034-0.9114141.152963-0.342365-0.1601870.470054-0.853063-1.387949-0.257257-1.030690-0.1102100.328911-0.5559230.987713-0.5019572.069887-0.0675030.316029-1.5062322.2016210.492097-0.085193-0.9778221.039147-0.653932
10-0.405638-1.402027-1.1662421.3061840.856283-1.236170-0.646721-1.4740640.0829600.090310-0.1699770.4063450.915427-0.9745030.2716371.539184-0.098866-0.5251491.0639330.085827-0.1296220.947959-0.072496-0.2375920.0125491.0657610.996596-0.1724812.583139-0.028578-0.2548561.328794-1.5929512.434350-0.341500-0.307719-1.333273-1.1008450.2090971.7347770.6396320.424779-0.1293270.905029-0.4829091.731628-2.783425-0.333677-0.1108951.212636-0.2084120.4271171.3485630.0438591.772519-1.4161060.4011550.8071570.303427-1.2462880.178774-0.066126-1.8622881.2412950.377021-0.822320-0.7490141.4636521.602268-1.0438771.185290-0.565783-1.0768791.360241-0.1219910.9910431.0079520.450185-0.7443761.388876-0.316847-0.841655-1.056842-0.5002260.0969591.176896-2.9396521.7922130.3163400.3032181.024967-0.590871-0.453326-0.795981-0.393301-0.374372-1.2701991.6183721.197727-0.914863
11-0.6252100.2889110.288374-1.372667-0.591395-0.4789421.335664-0.459855-1.615975-1.1896760.374767-2.4887330.586656-1.4220080.4960301.911128-0.560660-0.499614-0.372171-1.8330690.237124-0.9444460.9121400.359790-1.3592350.166966-0.047107-0.279789-0.594454-0.739013-1.5276450.4016681.791252-2.7748480.5238732.2075850.488999-0.3392830.1317110.0184091.186551-0.4243181.554994-0.205917-0.9349750.654102-1.227761-0.461025-0.421201-0.058615-0.5845630.336913-0.477102-1.3814630.757745-0.2689680.0348701.2316860.2366001.234720-0.0402470.0295821.0349050.380204-0.012108-0.859511-0.990340-1.205172-1.0301780.4266760.497796-0.8768080.9579630.1730160.131612-1.003556-1.069908-1.7992071.429598-0.116015-1.4549800.2619170.4444120.2732900.8441150.218745-1.033350-1.1882950.0583730.800523-1.6270680.8616510.871018-0.003733-0.2433540.9472960.5094060.0445460.2668961.337165
120.699142-1.9280330.1053631.0423220.715206-0.7637830.098798-1.1578980.1341050.0420410.6748260.165649-1.622970-3.1312740.597649-1.8803310.663980-0.256033-1.5240580.4927990.2211630.429622-0.6595841.264506-0.032131-2.114907-0.2640430.457835-0.676837-0.6290030.489145-0.5516860.942622-0.512043-0.4558930.021244-0.178035-2.498073-0.1712920.323510-0.545163-0.668909-0.1500310.521620-0.4289800.6764630.369081-0.7248320.7935421.2374220.4012752.1415230.2490120.486755-0.1632740.592222-0.292600-0.5471680.619104-0.0136050.7767340.1314241.189480-0.666317-0.9390361.1055150.6214521.586605-0.7609701.6496460.2831991.275812-0.4520120.301361-0.976951-0.268106-0.079255-1.2583322.216658-1.175988-0.863497-1.653022-0.5615140.4507530.4172000.094676-2.2310541.316862-0.4774410.646654-0.2002521.074354-0.0581760.1209900.222522-0.1795070.421655-0.914341-0.2341780.741524
130.9327141.423761-1.2808350.347882-0.863171-0.8525801.0449332.0945360.8062060.416201-1.1095030.145302-0.9968710.325456-0.6050811.1753261.6450540.293432-2.7668221.0328490.079115-1.4141321.4633762.3354860.411951-0.0485430.159284-0.651554-1.0931281.568390-0.077807-2.390779-0.842346-0.229675-0.999072-1.367219-0.792042-1.8785751.4514521.266250-0.7343150.2661520.735523-0.4308600.2298640.850083-2.2412411.0638500.289409-0.3543600.113063-0.1730061.3869981.8862360.587119-0.9611330.3992951.4615600.3108230.280220-0.879103-1.3263480.003337-1.085908-0.4367232.1119260.1060680.6155972.152996-0.1961550.025747-0.0390610.656823-0.3471052.5139791.7580701.288473-0.739185-0.691592-0.098728-0.2763860.4899810.516278-0.8382580.596673-0.3310530.521174-0.1450230.836693-1.0921660.361733-1.1699810.0467310.655377-0.7568521.285805-0.0950190.3602531.3706210.083010
140.8888932.288725-1.0323320.212273-1.0918261.6924981.0253670.5508540.679430-1.335712-0.7983412.265351-1.0069382.0597610.420266-1.1896570.5066740.260847-0.5331450.7272671.4122761.482106-0.9962580.588641-0.412642-0.920733-0.8746910.8390020.501668-0.342493-0.533806-2.146352-0.5973390.1157260.850683-0.7522390.377263-0.5619820.262783-0.356676-0.3674620.753611-1.267414-1.330698-0.5364530.840938-0.763108-0.268100-0.6774241.6068310.151732-2.0857011.2192960.4008630.591165-1.4852131.5019791.196569-0.2141540.339554-0.0344461.1764520.546340-1.255630-1.309210-0.4454370.189437-0.7374630.843767-0.605632-0.0607770.4093101.285569-0.6226381.0181930.8806800.046805-1.818058-0.8098290.8752240.409569-0.116621-1.2389193.305724-0.024121-1.7565001.3289580.507593-0.866554-2.240848-0.661376-0.6718240.215720-0.2963260.4814020.829645-0.7210251.2639140.549047-1.234945
15-1.9788380.721823-0.559067-1.2352430.420716-0.5988450.359576-0.619366-1.757772-1.1562510.7052120.875071-1.0203760.394760-0.1479700.2302491.3552031.7944882.678058-0.153565-0.460959-0.098108-1.407930-2.4877021.8230140.099873-0.517603-0.509311-1.833175-0.9009060.459493-0.6554401.466122-1.531389-0.4221060.4214220.5786150.2597950.018941-0.1687261.611107-1.586550-1.3849410.8583771.0332421.7013431.748344-0.371182-0.8435752.089641-0.345430-1.7405560.141915-2.1971380.689569-0.1500250.2874560.654016-1.521919-0.918008-0.5875280.2306360.2626370.6156740.600044-0.494699-0.7430890.220026-0.2422070.528216-0.328174-1.536517-1.476640-1.162114-1.2602221.106252-1.467408-0.349341-1.8412170.031296-0.076475-0.3533830.8075450.779064-2.398417-0.2678281.5497340.8143970.284770-0.6593690.761040-0.7220670.8103321.5012951.440865-1.367459-0.700301-1.5406620.159837-0.625415
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 62, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "bigdf = pd.DataFrame(np.random.randn(16, 100))\n", - "bigdf.style.set_sticky(axis=\"index\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "It is also possible to stick MultiIndexes and even only specific levels." - ] - }, - { - "cell_type": "code", - "execution_count": 63, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:38.973641Z", - "iopub.status.busy": "2023-01-25T14:32:38.973532Z", - "iopub.status.idle": "2023-01-25T14:32:39.002186Z", - "shell.execute_reply": "2023-01-25T14:32:39.001920Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
   0123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
A00-0.773866-0.240521-0.2171651.1736090.6863900.0083580.6962320.1731660.6204980.5040670.428066-0.0518240.7199150.0571650.562808-0.3695360.4833990.620765-0.354342-1.469471-1.9372660.038031-1.518162-0.4175990.3867170.7161930.4899610.7339570.9144150.6798940.255448-0.5083380.332030-0.111107-0.251983-1.4566200.4096301.062320-0.5771150.718796-0.399260-1.3113890.6491220.0915660.6288720.297894-0.142290-0.542291-0.9142901.1445140.3135841.1826351.214235-0.416446-1.653940-2.5507870.4424730.052127-0.464469-0.5238520.989726-1.325539-0.199687-1.2267270.2900181.1645740.817841-0.3095090.4965990.943536-0.091850-2.8026582.126219-0.5211610.288098-0.454663-1.676143-0.357661-0.7889600.185911-0.0171062.4540201.832706-0.911743-0.655873-0.000514-2.2269970.677285-0.140249-0.408407-0.8386650.4822281.243458-0.477394-0.220343-2.4639660.237325-0.3073801.1724780.819492
10.405906-0.9789191.2675260.145250-1.066786-2.114192-1.128346-1.0825230.3722160.004127-0.2119840.937326-0.935890-1.7041180.611789-1.0300150.636123-1.5061931.7366091.3929581.0094240.3532660.697339-0.2974240.428702-0.145346-0.333553-0.9746990.6653140.9719440.121950-1.4396681.0188081.442399-0.199585-1.1659160.6456561.436466-0.9212151.293906-2.7064431.460928-0.8231970.292952-1.4489920.026692-0.9758830.3928230.4421660.7457411.187982-0.2185700.3052880.054932-1.476953-0.1144340.0141030.825394-0.060654-0.4136880.9748361.3392101.0348380.0407750.7050010.0177961.867681-0.3901732.2852772.311464-0.085070-0.6481150.576300-0.790087-1.183798-1.334558-0.4541180.3193021.7064880.8304290.502476-0.0796310.4146350.3325110.042935-0.1609100.918553-0.292697-1.303834-0.1996040.871023-1.370681-0.205701-0.4929731.123083-0.081842-0.1185270.245838-0.315742-0.511806
20.011470-0.0361041.399603-0.418176-0.412229-1.234783-1.1215001.196478-0.5695220.422022-0.2204840.8043382.892667-0.511055-0.168722-1.477996-1.9699170.4713541.6985480.137105-0.7620520.199379-0.964346-0.2566921.2652750.848762-0.7841611.863776-0.3555690.8545520.768061-2.075718-2.5010691.1098680.957545-0.6832760.3077640.7330731.706250-1.1180910.374961-1.414503-0.524183-1.6626960.6879210.5217321.451396-0.833491-0.362796-1.174444-0.813893-0.8932200.7707431.156647-0.6474440.1259290.513600-0.5378741.992052-1.946584-0.1047590.484779-0.290936-0.4410750.542993-1.0500381.6304820.239771-1.1773100.464804-0.9669950.6460860.4868991.022196-2.267827-1.2296161.3138051.0732922.324940-0.542720-1.5042920.777643-0.6185530.0113421.3850621.363552-0.5498340.6888961.361288-0.3811370.797812-1.1281980.3692080.5401320.413853-0.200308-0.9691260.981293-0.009783-0.320020
3-0.5748161.4199770.434813-1.101217-1.5862751.9795730.3782980.7823262.1789870.6575640.683774-0.091000-0.059552-0.738908-0.907653-0.7019360.580039-0.6187570.4536841.665382-0.1523210.8800770.571073-0.6047360.5323590.515031-0.959844-0.8871840.4357810.862093-0.956321-0.6259090.1944720.4424900.526503-0.2152740.0907110.9325920.811999-2.4970260.6315450.321418-0.425549-1.0788320.7534440.199790-0.360526-0.013448-0.8194760.8148690.442118-0.972048-0.060603-2.3498251.265445-0.5732570.4291241.0497831.9547730.071883-0.0942090.2656160.9483180.3316451.343401-0.167934-1.105252-0.167077-0.096576-0.838161-0.2085640.3945340.7625331.235357-0.207282-0.202946-0.4680250.2569442.5875841.186697-1.0319031.4283160.658899-0.046582-0.0754221.329359-0.684267-1.5241822.0140613.7709330.647353-1.021377-0.3454930.5828110.7978121.3260201.422857-3.0770070.1840831.478935
10-0.6001421.929561-2.346771-0.669700-1.1652580.8147880.444449-0.5767580.3530910.4088930.091391-2.2943890.485506-0.081304-0.716272-1.6480101.005361-1.4896030.3630980.758602-1.373847-0.9720571.9885370.3198291.1690600.1465851.0303881.1659841.3695630.730984-1.383696-0.515189-0.808927-1.174651-1.631502-1.123414-0.478155-1.5830671.4190741.6687771.5675170.222103-0.336040-1.3520640.251032-0.4016950.268413-0.012299-0.9189532.921208-0.5815880.6728481.2511361.3822631.4298971.290990-1.272673-0.308611-0.422988-0.6756420.8744411.305736-0.262585-1.099395-0.667101-0.646737-0.556338-0.1965910.119306-0.266455-0.5242672.6509510.097318-0.9746970.1899641.141155-0.0644341.104971-1.508908-0.0318330.803919-0.6592210.9391450.214041-0.5318050.9560600.2493280.637903-0.5101581.850287-0.3484072.001376-0.389643-0.024786-0.4709730.8693390.1706670.5980621.2172621.274013
1-0.389981-0.752441-0.7348713.517318-1.173559-0.0049560.1454192.151368-3.086037-1.5691391.449784-0.868951-1.687716-0.9944011.1532661.803045-0.8190590.8479700.227102-0.5007620.8682101.8235401.161007-0.307606-0.7134160.363560-0.8221622.427681-0.129537-0.0787161.345644-1.2860940.237242-0.1360560.596664-1.4123811.2063410.2998600.7052380.142412-1.0593820.8334681.060015-0.527045-1.135732-1.140983-0.779540-0.640875-1.217196-1.6756630.241263-0.273322-1.697936-0.5949430.1011541.391735-0.4269531.008344-0.8185771.924570-0.578900-0.457395-1.0967050.418522-0.1556230.169706-2.5337060.0189041.4341600.7440950.647626-0.7703092.329141-0.141547-1.7615940.702091-1.531450-0.788427-0.184622-1.9423211.5301130.5034061.105845-0.935120-1.115483-2.2497621.3071350.788412-0.4410910.0735610.812101-0.9161461.573714-0.3095080.4999870.1875940.5589130.9032460.317901-0.809797
21.1282481.516826-0.186735-0.6681571.132259-0.246648-0.8551670.7322830.9318021.318684-1.198418-1.1493180.586321-1.171937-0.6077312.7537471.479287-1.136365-0.0204850.320444-1.9557550.660402-1.5453710.200519-0.0172631.6346860.5992460.4629890.0237210.2255460.170972-0.027496-0.061233-0.566411-0.6695670.6016180.503656-0.678253-2.907108-1.7171230.3976311.3001080.215821-0.593075-0.225944-0.9460571.0003080.3931601.342074-0.370687-0.166413-0.419814-0.2559311.7894780.2823780.742260-0.0504981.4153090.838166-1.400292-0.937976-1.4991480.8018590.2248240.2835720.643703-1.1984650.5272060.2152020.4370481.3128680.7412430.0779880.0061230.1903700.018007-1.026036-2.378430-1.0699490.8438221.289216-1.423369-0.4628870.197330-0.9350760.4412710.414643-0.377887-0.5305150.6215921.0095720.5697180.175291-0.656279-0.112273-0.392137-1.043558-0.467318-0.384329-2.009207
30.6585980.101830-0.6827810.229349-0.3056570.4048770.252244-0.837784-0.0396240.3294570.7516941.469070-0.1571991.032628-0.584639-0.9255440.342474-0.9693630.133480-0.385974-0.6002780.2819390.8685791.129803-0.0418980.9611930.131521-0.792889-1.2857370.073934-1.333315-1.0441251.2773381.4922570.4113791.771805-1.1111281.123233-1.0194491.738357-0.690764-0.120710-0.421359-0.727294-0.857759-0.069436-0.328334-0.5581801.063474-0.519133-0.4969021.089589-1.6158010.080174-0.229938-0.498420-0.6246150.059481-0.093158-1.784549-0.503789-0.1405280.002653-0.4849300.055914-0.680948-0.9942711.2770520.0376512.155421-0.4375890.6964040.417752-0.5447851.1906900.9782620.7521020.5044720.139853-0.505089-0.264975-1.6031940.7318470.010903-1.165346-0.125195-1.032685-0.4655201.5148080.3047620.7934140.314635-1.6382790.111737-0.7770370.2517831.126303-0.8087980.422064-0.349264
B00-0.356362-0.0892270.6093730.542382-0.768681-0.0480742.015458-1.5523510.2515521.4596350.9497070.339465-0.0013721.7985891.5591630.2317830.423141-0.3105300.3537952.173336-0.196247-0.375636-0.8582210.2584100.6564300.9608191.1378931.5534050.038981-0.632038-0.132009-1.834997-0.242576-0.297879-0.441559-0.7696910.224077-0.1530090.519526-0.6801880.5358510.671496-0.1830640.3012341.288256-2.478240-0.3604030.424067-0.834659-0.128464-0.489013-0.014888-1.461230-1.435223-1.3198021.0836750.979140-0.3752911.110189-1.0113510.587886-0.822775-1.1838651.4551731.1343280.239403-0.837991-1.1309320.7831681.8455201.437072-1.1984431.3790982.1291130.260096-0.0119750.0433020.7229411.028152-0.2358061.145245-1.3595980.2321890.503712-0.614264-0.530606-2.435803-0.255238-0.0644230.7846430.2563460.1280231.414103-1.1186590.8773530.5005610.463651-2.034512-0.981683-0.691944
1-1.113376-1.1694020.680539-1.5342121.653817-1.295181-0.5668260.4770141.4133710.5171051.401153-0.8726850.8309570.181507-0.1456160.694592-0.7512080.3244440.681973-0.0549720.917776-1.024810-0.206446-0.6001130.8528051.455109-0.0797690.0760760.207699-1.850458-0.124124-0.610871-0.8833620.219049-0.685094-0.645330-0.242805-0.7756020.2330702.422642-1.423040-0.5824210.968304-0.701025-0.1678500.2772641.3012310.301205-3.081249-0.5628680.192944-0.6645920.5656860.190913-0.841858-1.856545-1.0227771.2959680.4519210.6599550.065818-0.3195860.253495-1.144646-0.4834040.5559020.8070690.7141960.6611960.0536670.346833-1.288977-0.386734-1.2621270.477495-0.494034-0.9114141.152963-0.342365-0.1601870.470054-0.853063-1.387949-0.257257-1.030690-0.1102100.328911-0.5559230.987713-0.5019572.069887-0.0675030.316029-1.5062322.2016210.492097-0.085193-0.9778221.039147-0.653932
2-0.405638-1.402027-1.1662421.3061840.856283-1.236170-0.646721-1.4740640.0829600.090310-0.1699770.4063450.915427-0.9745030.2716371.539184-0.098866-0.5251491.0639330.085827-0.1296220.947959-0.072496-0.2375920.0125491.0657610.996596-0.1724812.583139-0.028578-0.2548561.328794-1.5929512.434350-0.341500-0.307719-1.333273-1.1008450.2090971.7347770.6396320.424779-0.1293270.905029-0.4829091.731628-2.783425-0.333677-0.1108951.212636-0.2084120.4271171.3485630.0438591.772519-1.4161060.4011550.8071570.303427-1.2462880.178774-0.066126-1.8622881.2412950.377021-0.822320-0.7490141.4636521.602268-1.0438771.185290-0.565783-1.0768791.360241-0.1219910.9910431.0079520.450185-0.7443761.388876-0.316847-0.841655-1.056842-0.5002260.0969591.176896-2.9396521.7922130.3163400.3032181.024967-0.590871-0.453326-0.795981-0.393301-0.374372-1.2701991.6183721.197727-0.914863
3-0.6252100.2889110.288374-1.372667-0.591395-0.4789421.335664-0.459855-1.615975-1.1896760.374767-2.4887330.586656-1.4220080.4960301.911128-0.560660-0.499614-0.372171-1.8330690.237124-0.9444460.9121400.359790-1.3592350.166966-0.047107-0.279789-0.594454-0.739013-1.5276450.4016681.791252-2.7748480.5238732.2075850.488999-0.3392830.1317110.0184091.186551-0.4243181.554994-0.205917-0.9349750.654102-1.227761-0.461025-0.421201-0.058615-0.5845630.336913-0.477102-1.3814630.757745-0.2689680.0348701.2316860.2366001.234720-0.0402470.0295821.0349050.380204-0.012108-0.859511-0.990340-1.205172-1.0301780.4266760.497796-0.8768080.9579630.1730160.131612-1.003556-1.069908-1.7992071.429598-0.116015-1.4549800.2619170.4444120.2732900.8441150.218745-1.033350-1.1882950.0583730.800523-1.6270680.8616510.871018-0.003733-0.2433540.9472960.5094060.0445460.2668961.337165
100.699142-1.9280330.1053631.0423220.715206-0.7637830.098798-1.1578980.1341050.0420410.6748260.165649-1.622970-3.1312740.597649-1.8803310.663980-0.256033-1.5240580.4927990.2211630.429622-0.6595841.264506-0.032131-2.114907-0.2640430.457835-0.676837-0.6290030.489145-0.5516860.942622-0.512043-0.4558930.021244-0.178035-2.498073-0.1712920.323510-0.545163-0.668909-0.1500310.521620-0.4289800.6764630.369081-0.7248320.7935421.2374220.4012752.1415230.2490120.486755-0.1632740.592222-0.292600-0.5471680.619104-0.0136050.7767340.1314241.189480-0.666317-0.9390361.1055150.6214521.586605-0.7609701.6496460.2831991.275812-0.4520120.301361-0.976951-0.268106-0.079255-1.2583322.216658-1.175988-0.863497-1.653022-0.5615140.4507530.4172000.094676-2.2310541.316862-0.4774410.646654-0.2002521.074354-0.0581760.1209900.222522-0.1795070.421655-0.914341-0.2341780.741524
10.9327141.423761-1.2808350.347882-0.863171-0.8525801.0449332.0945360.8062060.416201-1.1095030.145302-0.9968710.325456-0.6050811.1753261.6450540.293432-2.7668221.0328490.079115-1.4141321.4633762.3354860.411951-0.0485430.159284-0.651554-1.0931281.568390-0.077807-2.390779-0.842346-0.229675-0.999072-1.367219-0.792042-1.8785751.4514521.266250-0.7343150.2661520.735523-0.4308600.2298640.850083-2.2412411.0638500.289409-0.3543600.113063-0.1730061.3869981.8862360.587119-0.9611330.3992951.4615600.3108230.280220-0.879103-1.3263480.003337-1.085908-0.4367232.1119260.1060680.6155972.152996-0.1961550.025747-0.0390610.656823-0.3471052.5139791.7580701.288473-0.739185-0.691592-0.098728-0.2763860.4899810.516278-0.8382580.596673-0.3310530.521174-0.1450230.836693-1.0921660.361733-1.1699810.0467310.655377-0.7568521.285805-0.0950190.3602531.3706210.083010
20.8888932.288725-1.0323320.212273-1.0918261.6924981.0253670.5508540.679430-1.335712-0.7983412.265351-1.0069382.0597610.420266-1.1896570.5066740.260847-0.5331450.7272671.4122761.482106-0.9962580.588641-0.412642-0.920733-0.8746910.8390020.501668-0.342493-0.533806-2.146352-0.5973390.1157260.850683-0.7522390.377263-0.5619820.262783-0.356676-0.3674620.753611-1.267414-1.330698-0.5364530.840938-0.763108-0.268100-0.6774241.6068310.151732-2.0857011.2192960.4008630.591165-1.4852131.5019791.196569-0.2141540.339554-0.0344461.1764520.546340-1.255630-1.309210-0.4454370.189437-0.7374630.843767-0.605632-0.0607770.4093101.285569-0.6226381.0181930.8806800.046805-1.818058-0.8098290.8752240.409569-0.116621-1.2389193.305724-0.024121-1.7565001.3289580.507593-0.866554-2.240848-0.661376-0.6718240.215720-0.2963260.4814020.829645-0.7210251.2639140.549047-1.234945
3-1.9788380.721823-0.559067-1.2352430.420716-0.5988450.359576-0.619366-1.757772-1.1562510.7052120.875071-1.0203760.394760-0.1479700.2302491.3552031.7944882.678058-0.153565-0.460959-0.098108-1.407930-2.4877021.8230140.099873-0.517603-0.509311-1.833175-0.9009060.459493-0.6554401.466122-1.531389-0.4221060.4214220.5786150.2597950.018941-0.1687261.611107-1.586550-1.3849410.8583771.0332421.7013431.748344-0.371182-0.8435752.089641-0.345430-1.7405560.141915-2.1971380.689569-0.1500250.2874560.654016-1.521919-0.918008-0.5875280.2306360.2626370.6156740.600044-0.494699-0.7430890.220026-0.2422070.528216-0.328174-1.536517-1.476640-1.162114-1.2602221.106252-1.467408-0.349341-1.8412170.031296-0.076475-0.3533830.8075450.779064-2.398417-0.2678281.5497340.8143970.284770-0.6593690.761040-0.7220670.8103321.5012951.440865-1.367459-0.700301-1.5406620.159837-0.625415
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 63, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "bigdf.index = pd.MultiIndex.from_product([[\"A\",\"B\"],[0,1],[0,1,2,3]])\n", - "bigdf.style.set_sticky(axis=\"index\", pixel_size=18, levels=[1,2])" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### HTML Escaping\n", - "\n", - "Suppose you have to display HTML within HTML, that can be a bit of pain when the renderer can't distinguish. You can use the `escape` formatting option to handle this, and even use it within a formatter that contains HTML itself." - ] - }, - { - "cell_type": "code", - "execution_count": 64, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:39.004072Z", - "iopub.status.busy": "2023-01-25T14:32:39.003971Z", - "iopub.status.idle": "2023-01-25T14:32:39.017834Z", - "shell.execute_reply": "2023-01-25T14:32:39.017579Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
 012
0
\"&other\"
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 64, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df4 = pd.DataFrame([['
', '\"&other\"', '']])\n", - "df4.style" - ] - }, - { - "cell_type": "code", - "execution_count": 65, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:39.019342Z", - "iopub.status.busy": "2023-01-25T14:32:39.019261Z", - "iopub.status.idle": "2023-01-25T14:32:39.032461Z", - "shell.execute_reply": "2023-01-25T14:32:39.032207Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
 012
0<div></div>"&other"<span></span>
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 65, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df4.style.format(escape=\"html\")" - ] - }, - { - "cell_type": "code", - "execution_count": 66, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:39.033933Z", - "iopub.status.busy": "2023-01-25T14:32:39.033845Z", - "iopub.status.idle": "2023-01-25T14:32:39.046802Z", - "shell.execute_reply": "2023-01-25T14:32:39.046562Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
 012
0<div></div>"&other"<span></span>
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 66, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df4.style.format('{}', escape=\"html\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Export to Excel\n", - "\n", - "Some support (*since version 0.20.0*) is available for exporting styled `DataFrames` to Excel worksheets using the `OpenPyXL` or `XlsxWriter` engines. CSS2.2 properties handled include:\n", - "\n", - "- `background-color`\n", - "- `border-style` properties\n", - "- `border-width` properties\n", - "- `border-color` properties\n", - "- `color`\n", - "- `font-family`\n", - "- `font-style`\n", - "- `font-weight`\n", - "- `text-align`\n", - "- `text-decoration`\n", - "- `vertical-align`\n", - "- `white-space: nowrap`\n", - "\n", - "\n", - "- Shorthand and side-specific border properties are supported (e.g. `border-style` and `border-left-style`) as well as the `border` shorthands for all sides (`border: 1px solid green`) or specified sides (`border-left: 1px solid green`). Using a `border` shorthand will override any border properties set before it (See [CSS Working Group](https://drafts.csswg.org/css-backgrounds/#border-shorthands) for more details)\n", - "\n", - "\n", - "- Only CSS2 named colors and hex colors of the form `#rgb` or `#rrggbb` are currently supported.\n", - "- The following pseudo CSS properties are also available to set Excel specific style properties:\n", - " - `number-format`\n", - " - `border-style` (for Excel-specific styles: \"hair\", \"mediumDashDot\", \"dashDotDot\", \"mediumDashDotDot\", \"dashDot\", \"slantDashDot\", or \"mediumDashed\")\n", - "\n", - "Table level styles, and data cell CSS-classes are not included in the export to Excel: individual cells must have their properties mapped by the `Styler.apply` and/or `Styler.applymap` methods." - ] - }, - { - "cell_type": "code", - "execution_count": 67, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:39.048287Z", - "iopub.status.busy": "2023-01-25T14:32:39.048204Z", - "iopub.status.idle": "2023-01-25T14:32:39.141871Z", - "shell.execute_reply": "2023-01-25T14:32:39.141606Z" - } - }, - "outputs": [], - "source": [ - "df2.style.\\\n", - " applymap(style_negative, props='color:red;').\\\n", - " highlight_max(axis=0).\\\n", - " to_excel('styled.xlsx', engine='openpyxl')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "A screenshot of the output:\n", - "\n", - "![Excel spreadsheet with styled DataFrame](../_static/style-excel.png)\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Export to LaTeX\n", - "\n", - "There is support (*since version 1.3.0*) to export `Styler` to LaTeX. The documentation for the [.to_latex][latex] method gives further detail and numerous examples.\n", - "\n", - "[latex]: ../reference/api/pandas.io.formats.style.Styler.to_latex.rst" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## More About CSS and HTML\n", - "\n", - "Cascading Style Sheet (CSS) language, which is designed to influence how a browser renders HTML elements, has its own peculiarities. It never reports errors: it just silently ignores them and doesn't render your objects how you intend so can sometimes be frustrating. Here is a very brief primer on how ``Styler`` creates HTML and interacts with CSS, with advice on common pitfalls to avoid." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### CSS Classes and Ids\n", - "\n", - "The precise structure of the CSS `class` attached to each cell is as follows.\n", - "\n", - "- Cells with Index and Column names include `index_name` and `level` where `k` is its level in a MultiIndex\n", - "- Index label cells include\n", - " + `row_heading`\n", - " + `level` where `k` is the level in a MultiIndex\n", - " + `row` where `m` is the numeric position of the row\n", - "- Column label cells include\n", - " + `col_heading`\n", - " + `level` where `k` is the level in a MultiIndex\n", - " + `col` where `n` is the numeric position of the column\n", - "- Data cells include\n", - " + `data`\n", - " + `row`, where `m` is the numeric position of the cell.\n", - " + `col`, where `n` is the numeric position of the cell.\n", - "- Blank cells include `blank`\n", - "- Trimmed cells include `col_trim` or `row_trim`\n", - "\n", - "The structure of the `id` is `T_uuid_level_row_col` where `level` is used only on headings, and headings will only have either `row` or `col` whichever is needed. By default we've also prepended each row/column identifier with a UUID unique to each DataFrame so that the style from one doesn't collide with the styling from another within the same notebook or page. You can read more about the use of UUIDs in [Optimization](#Optimization).\n", - "\n", - "We can see example of the HTML by calling the [.to_html()][tohtml] method.\n", - "\n", - "[tohtml]: ../reference/api/pandas.io.formats.style.Styler.to_html.rst" - ] - }, - { - "cell_type": "code", - "execution_count": 68, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:39.143742Z", - "iopub.status.busy": "2023-01-25T14:32:39.143631Z", - "iopub.status.idle": "2023-01-25T14:32:39.158365Z", - "shell.execute_reply": "2023-01-25T14:32:39.158123Z" - } - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
 c1c2
i112
i234
\n", - "\n" - ] - } - ], - "source": [ - "print(pd.DataFrame([[1,2],[3,4]], index=['i1', 'i2'], columns=['c1', 'c2']).style.to_html())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### CSS Hierarchies\n", - "\n", - "The examples have shown that when CSS styles overlap, the one that comes last in the HTML render, takes precedence. So the following yield different results:" - ] - }, - { - "cell_type": "code", - "execution_count": 69, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:39.159850Z", - "iopub.status.busy": "2023-01-25T14:32:39.159771Z", - "iopub.status.idle": "2023-01-25T14:32:39.174906Z", - "shell.execute_reply": "2023-01-25T14:32:39.174636Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
 0
0text
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 69, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df4 = pd.DataFrame([['text']])\n", - "df4.style.applymap(lambda x: 'color:green;')\\\n", - " .applymap(lambda x: 'color:red;')" - ] - }, - { - "cell_type": "code", - "execution_count": 70, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:39.176453Z", - "iopub.status.busy": "2023-01-25T14:32:39.176346Z", - "iopub.status.idle": "2023-01-25T14:32:39.191218Z", - "shell.execute_reply": "2023-01-25T14:32:39.190956Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
 0
0text
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 70, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df4.style.applymap(lambda x: 'color:red;')\\\n", - " .applymap(lambda x: 'color:green;')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "This is only true for CSS rules that are equivalent in hierarchy, or importance. You can read more about [CSS specificity here](https://www.w3schools.com/css/css_specificity.asp) but for our purposes it suffices to summarize the key points:\n", - "\n", - "A CSS importance score for each HTML element is derived by starting at zero and adding:\n", - "\n", - " - 1000 for an inline style attribute\n", - " - 100 for each ID\n", - " - 10 for each attribute, class or pseudo-class\n", - " - 1 for each element name or pseudo-element\n", - " \n", - "Let's use this to describe the action of the following configurations" - ] - }, - { - "cell_type": "code", - "execution_count": 71, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:39.192714Z", - "iopub.status.busy": "2023-01-25T14:32:39.192634Z", - "iopub.status.idle": "2023-01-25T14:32:39.207243Z", - "shell.execute_reply": "2023-01-25T14:32:39.206983Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
 0
0text
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 71, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df4.style.set_uuid('a_')\\\n", - " .set_table_styles([{'selector': 'td', 'props': 'color:red;'}])\\\n", - " .applymap(lambda x: 'color:green;')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "This text is red because the generated selector `#T_a_ td` is worth 101 (ID plus element), whereas `#T_a_row0_col0` is only worth 100 (ID), so is considered inferior even though in the HTML it comes after the previous." - ] - }, - { - "cell_type": "code", - "execution_count": 72, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:39.208837Z", - "iopub.status.busy": "2023-01-25T14:32:39.208728Z", - "iopub.status.idle": "2023-01-25T14:32:39.222863Z", - "shell.execute_reply": "2023-01-25T14:32:39.222605Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
 0
0text
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 72, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df4.style.set_uuid('b_')\\\n", - " .set_table_styles([{'selector': 'td', 'props': 'color:red;'},\n", - " {'selector': '.cls-1', 'props': 'color:blue;'}])\\\n", - " .applymap(lambda x: 'color:green;')\\\n", - " .set_td_classes(pd.DataFrame([['cls-1']]))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "In the above case the text is blue because the selector `#T_b_ .cls-1` is worth 110 (ID plus class), which takes precedence." - ] - }, - { - "cell_type": "code", - "execution_count": 73, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:39.224293Z", - "iopub.status.busy": "2023-01-25T14:32:39.224213Z", - "iopub.status.idle": "2023-01-25T14:32:39.238734Z", - "shell.execute_reply": "2023-01-25T14:32:39.238466Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
 0
0text
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 73, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df4.style.set_uuid('c_')\\\n", - " .set_table_styles([{'selector': 'td', 'props': 'color:red;'},\n", - " {'selector': '.cls-1', 'props': 'color:blue;'},\n", - " {'selector': 'td.data', 'props': 'color:yellow;'}])\\\n", - " .applymap(lambda x: 'color:green;')\\\n", - " .set_td_classes(pd.DataFrame([['cls-1']]))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Now we have created another table style this time the selector `T_c_ td.data` (ID plus element plus class) gets bumped up to 111. \n", - "\n", - "If your style fails to be applied, and its really frustrating, try the `!important` trump card." - ] - }, - { - "cell_type": "code", - "execution_count": 74, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:39.240317Z", - "iopub.status.busy": "2023-01-25T14:32:39.240209Z", - "iopub.status.idle": "2023-01-25T14:32:39.254735Z", - "shell.execute_reply": "2023-01-25T14:32:39.254486Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
 0
0text
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 74, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df4.style.set_uuid('d_')\\\n", - " .set_table_styles([{'selector': 'td', 'props': 'color:red;'},\n", - " {'selector': '.cls-1', 'props': 'color:blue;'},\n", - " {'selector': 'td.data', 'props': 'color:yellow;'}])\\\n", - " .applymap(lambda x: 'color:green !important;')\\\n", - " .set_td_classes(pd.DataFrame([['cls-1']]))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Finally got that green text after all!" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Extensibility\n", - "\n", - "The core of pandas is, and will remain, its \"high-performance, easy-to-use data structures\".\n", - "With that in mind, we hope that `DataFrame.style` accomplishes two goals\n", - "\n", - "- Provide an API that is pleasing to use interactively and is \"good enough\" for many tasks\n", - "- Provide the foundations for dedicated libraries to build on\n", - "\n", - "If you build a great library on top of this, let us know and we'll [link](https://pandas.pydata.org/pandas-docs/stable/ecosystem.html) to it.\n", - "\n", - "### Subclassing\n", - "\n", - "If the default template doesn't quite suit your needs, you can subclass Styler and extend or override the template.\n", - "We'll show an example of extending the default template to insert a custom header before each table." - ] - }, - { - "cell_type": "code", - "execution_count": 75, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:39.256259Z", - "iopub.status.busy": "2023-01-25T14:32:39.256174Z", - "iopub.status.idle": "2023-01-25T14:32:39.268879Z", - "shell.execute_reply": "2023-01-25T14:32:39.268627Z" - } - }, - "outputs": [], - "source": [ - "from jinja2 import Environment, ChoiceLoader, FileSystemLoader\n", - "from IPython.display import HTML\n", - "from pandas.io.formats.style import Styler" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We'll use the following template:" - ] - }, - { - "cell_type": "code", - "execution_count": 76, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:39.270397Z", - "iopub.status.busy": "2023-01-25T14:32:39.270323Z", - "iopub.status.idle": "2023-01-25T14:32:39.283516Z", - "shell.execute_reply": "2023-01-25T14:32:39.283277Z" - } - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{% extends \"html_table.tpl\" %}\n", - "{% block table %}\n", - "

{{ table_title|default(\"My Table\") }}

\n", - "{{ super() }}\n", - "{% endblock table %}\n", - "\n" - ] - } - ], - "source": [ - "with open(\"templates/myhtml.tpl\") as f:\n", - " print(f.read())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Now that we've created a template, we need to set up a subclass of ``Styler`` that\n", - "knows about it." - ] - }, - { - "cell_type": "code", - "execution_count": 77, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:39.285003Z", - "iopub.status.busy": "2023-01-25T14:32:39.284923Z", - "iopub.status.idle": "2023-01-25T14:32:39.298378Z", - "shell.execute_reply": "2023-01-25T14:32:39.298123Z" - } - }, - "outputs": [], - "source": [ - "class MyStyler(Styler):\n", - " env = Environment(\n", - " loader=ChoiceLoader([\n", - " FileSystemLoader(\"templates\"), # contains ours\n", - " Styler.loader, # the default\n", - " ])\n", - " )\n", - " template_html_table = env.get_template(\"myhtml.tpl\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Notice that we include the original loader in our environment's loader.\n", - "That's because we extend the original template, so the Jinja environment needs\n", - "to be able to find it.\n", - "\n", - "Now we can use that custom styler. It's `__init__` takes a DataFrame." - ] - }, - { - "cell_type": "code", - "execution_count": 78, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:39.299907Z", - "iopub.status.busy": "2023-01-25T14:32:39.299823Z", - "iopub.status.idle": "2023-01-25T14:32:39.319847Z", - "shell.execute_reply": "2023-01-25T14:32:39.319602Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - "\n", - "

My Table

\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - " \n", - "\n", - "\n", - "\n", - " \n", - "\n", - "\n", - "\n", - " \n", - "\n", - "\n", - "\n", - " \n", - "\n", - "\n", - "\n", - " \n", - "\n", - "\n", - "\n", - " \n", - "\n", - "\n", - "\n", - " \n", - "\n", - "\n", - "\n", - " \n", - "\n", - "\n", - "\n", - " \n", - "\n", - "\n", - "\n", - " \n", - "\n", - "\n", - " \n", - "\n", - "\n", - "\n", - " \n", - "\n", - "\n", - " \n", - "\n", - " \n", - "\n", - " \n", - "\n", - " \n", - "\n", - " \n", - "\n", - " \n", - "\n", - "\n", - " \n", - "\n", - "\n", - "\n", - " \n", - "\n", - "\n", - " \n", - "\n", - " \n", - "\n", - " \n", - "\n", - " \n", - "\n", - " \n", - "\n", - "\n", - " \n", - "\n", - "\n", - "\n", - " \n", - "\n", - "\n", - " \n", - "\n", - " \n", - "\n", - " \n", - "\n", - " \n", - "\n", - " \n", - "\n", - " \n", - "\n", - "\n", - " \n", - "\n", - "\n", - "\n", - " \n", - "\n", - "\n", - " \n", - "\n", - " \n", - "\n", - " \n", - "\n", - " \n", - "\n", - " \n", - "\n", - "\n", - " \n", - "\n", - "\n", - "\n", - " \n", - "\n", - "
  c1c2c3c4
Ar1-1.048553-1.420018-1.7062701.950775
r2-0.509652-0.438074-1.2527950.777490
Br1-1.613898-0.212740-0.8954670.386902
r2-0.510805-1.180632-0.0281820.428332
\n", - "\n", - "\n" - ], - "text/plain": [ - "<__main__.MyStyler at 0x15986b100>" - ] - }, - "execution_count": 78, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "MyStyler(df3)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Our custom template accepts a `table_title` keyword. We can provide the value in the `.to_html` method." - ] - }, - { - "cell_type": "code", - "execution_count": 79, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:39.321297Z", - "iopub.status.busy": "2023-01-25T14:32:39.321218Z", - "iopub.status.idle": "2023-01-25T14:32:39.335660Z", - "shell.execute_reply": "2023-01-25T14:32:39.335413Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - "\n", - "

Extending Example

\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - " \n", - "\n", - "\n", - "\n", - " \n", - "\n", - "\n", - "\n", - " \n", - "\n", - "\n", - "\n", - " \n", - "\n", - "\n", - "\n", - " \n", - "\n", - "\n", - "\n", - " \n", - "\n", - "\n", - "\n", - " \n", - "\n", - "\n", - "\n", - " \n", - "\n", - "\n", - "\n", - " \n", - "\n", - "\n", - "\n", - " \n", - "\n", - "\n", - " \n", - "\n", - "\n", - "\n", - " \n", - "\n", - "\n", - " \n", - "\n", - " \n", - "\n", - " \n", - "\n", - " \n", - "\n", - " \n", - "\n", - " \n", - "\n", - "\n", - " \n", - "\n", - "\n", - "\n", - " \n", - "\n", - "\n", - " \n", - "\n", - " \n", - "\n", - " \n", - "\n", - " \n", - "\n", - " \n", - "\n", - "\n", - " \n", - "\n", - "\n", - "\n", - " \n", - "\n", - "\n", - " \n", - "\n", - " \n", - "\n", - " \n", - "\n", - " \n", - "\n", - " \n", - "\n", - " \n", - "\n", - "\n", - " \n", - "\n", - "\n", - "\n", - " \n", - "\n", - "\n", - " \n", - "\n", - " \n", - "\n", - " \n", - "\n", - " \n", - "\n", - " \n", - "\n", - "\n", - " \n", - "\n", - "\n", - "\n", - " \n", - "\n", - "
  c1c2c3c4
Ar1-1.048553-1.420018-1.7062701.950775
r2-0.509652-0.438074-1.2527950.777490
Br1-1.613898-0.212740-0.8954670.386902
r2-0.510805-1.180632-0.0281820.428332
\n", - "\n", - "\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 79, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "HTML(MyStyler(df3).to_html(table_title=\"Extending Example\"))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "For convenience, we provide the `Styler.from_custom_template` method that does the same as the custom subclass." - ] - }, - { - "cell_type": "code", - "execution_count": 80, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:39.337154Z", - "iopub.status.busy": "2023-01-25T14:32:39.337069Z", - "iopub.status.idle": "2023-01-25T14:32:39.359505Z", - "shell.execute_reply": "2023-01-25T14:32:39.359234Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - "\n", - "

Another Title

\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - " \n", - "\n", - "\n", - "\n", - " \n", - "\n", - "\n", - "\n", - " \n", - "\n", - "\n", - "\n", - " \n", - "\n", - "\n", - "\n", - " \n", - "\n", - "\n", - "\n", - " \n", - "\n", - "\n", - "\n", - " \n", - "\n", - "\n", - "\n", - " \n", - "\n", - "\n", - "\n", - " \n", - "\n", - "\n", - "\n", - " \n", - "\n", - "\n", - " \n", - "\n", - "\n", - "\n", - " \n", - "\n", - "\n", - " \n", - "\n", - " \n", - "\n", - " \n", - "\n", - " \n", - "\n", - " \n", - "\n", - " \n", - "\n", - "\n", - " \n", - "\n", - "\n", - "\n", - " \n", - "\n", - "\n", - " \n", - "\n", - " \n", - "\n", - " \n", - "\n", - " \n", - "\n", - " \n", - "\n", - "\n", - " \n", - "\n", - "\n", - "\n", - " \n", - "\n", - "\n", - " \n", - "\n", - " \n", - "\n", - " \n", - "\n", - " \n", - "\n", - " \n", - "\n", - " \n", - "\n", - "\n", - " \n", - "\n", - "\n", - "\n", - " \n", - "\n", - "\n", - " \n", - "\n", - " \n", - "\n", - " \n", - "\n", - " \n", - "\n", - " \n", - "\n", - "\n", - " \n", - "\n", - "\n", - "\n", - " \n", - "\n", - "
  c1c2c3c4
Ar1-1.048553-1.420018-1.7062701.950775
r2-0.509652-0.438074-1.2527950.777490
Br1-1.613898-0.212740-0.8954670.386902
r2-0.510805-1.180632-0.0281820.428332
\n", - "\n", - "\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 80, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "EasyStyler = Styler.from_custom_template(\"templates\", \"myhtml.tpl\")\n", - "HTML(EasyStyler(df3).to_html(table_title=\"Another Title\"))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### Template Structure\n", - "\n", - "Here's the template structure for the both the style generation template and the table generation template:" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Style template:" - ] - }, - { - "cell_type": "code", - "execution_count": 81, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:39.361130Z", - "iopub.status.busy": "2023-01-25T14:32:39.361016Z", - "iopub.status.idle": "2023-01-25T14:32:39.375038Z", - "shell.execute_reply": "2023-01-25T14:32:39.374778Z" - }, - "nbsphinx": "hidden" - }, - "outputs": [], - "source": [ - "with open(\"templates/html_style_structure.html\") as f:\n", - " style_structure = f.read()" - ] - }, - { - "cell_type": "code", - "execution_count": 82, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:39.376468Z", - "iopub.status.busy": "2023-01-25T14:32:39.376388Z", - "iopub.status.idle": "2023-01-25T14:32:39.388926Z", - "shell.execute_reply": "2023-01-25T14:32:39.388689Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - "\n", - "
before_style
\n", - "
style\n", - "
<style type="text/css">
\n", - "
table_styles
\n", - "
before_cellstyle
\n", - "
cellstyle
\n", - "
</style>
\n", - "
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 82, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "HTML(style_structure)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Table template:" - ] - }, - { - "cell_type": "code", - "execution_count": 83, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:39.390367Z", - "iopub.status.busy": "2023-01-25T14:32:39.390279Z", - "iopub.status.idle": "2023-01-25T14:32:39.402874Z", - "shell.execute_reply": "2023-01-25T14:32:39.402618Z" - }, - "nbsphinx": "hidden" - }, - "outputs": [], - "source": [ - "with open(\"templates/html_table_structure.html\") as f:\n", - " table_structure = f.read()" - ] - }, - { - "cell_type": "code", - "execution_count": 84, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:39.404290Z", - "iopub.status.busy": "2023-01-25T14:32:39.404190Z", - "iopub.status.idle": "2023-01-25T14:32:39.416613Z", - "shell.execute_reply": "2023-01-25T14:32:39.416388Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - "\n", - "
before_table
\n", - "\n", - "
table\n", - "
<table ...>
\n", - "
caption
\n", - "\n", - "
thead\n", - "
before_head_rows
\n", - "
head_tr (loop over headers)
\n", - "
after_head_rows
\n", - "
\n", - "\n", - "
tbody\n", - "
before_rows
\n", - "
tr (loop over data rows)
\n", - "
after_rows
\n", - "
\n", - "
</table>
\n", - "
\n", - "\n", - "
after_table
\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 84, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "HTML(table_structure)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "See the template in the [GitHub repo](https://github.com/pandas-dev/pandas) for more details." - ] - }, - { - "cell_type": "code", - "execution_count": 85, - "metadata": { - "execution": { - "iopub.execute_input": "2023-01-25T14:32:39.418110Z", - "iopub.status.busy": "2023-01-25T14:32:39.418031Z", - "iopub.status.idle": "2023-01-25T14:32:39.429900Z", - "shell.execute_reply": "2023-01-25T14:32:39.429653Z" - }, - "nbsphinx": "hidden" - }, - "outputs": [], - "source": [ - "# # Hack to get the same style in the notebook as the\n", - "# # main site. This is hidden in the docs.\n", - "# from IPython.display import HTML\n", - "# with open(\"themes/nature_with_gtoc/static/nature.css_t\") as f:\n", - "# css = f.read()\n", - " \n", - "# HTML(''.format(css))" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.9.7" - }, - "widgets": { - "application/vnd.jupyter.widget-state+json": { - "state": { - "03cc60499bd6413f83ca0aeef1ee3127": { - "model_module": "@jupyter-widgets/controls", - "model_module_version": "1.5.0", - "model_name": "FloatSliderModel", - "state": { - "_dom_classes": [], - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "FloatSliderModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/controls", - "_view_module_version": "1.5.0", - "_view_name": "FloatSliderView", - "continuous_update": true, - "description": "", - "description_tooltip": null, - "disabled": false, - "layout": "IPY_MODEL_a653b4b8ecee44789c2168105b6b4ac1", - "max": 99.9, - "min": 0.0, - "orientation": "horizontal", - "readout": true, - "readout_format": ".2f", - "step": 0.1, - "style": "IPY_MODEL_d38ed46cf67f4270a86a4b8d2a333242", - "value": 49.95 - } - }, - "19c78c6691d34efc8302c28a1cf3ef4f": { - "model_module": "@jupyter-widgets/base", - "model_module_version": "1.2.0", - "model_name": "LayoutModel", - "state": { - "_model_module": "@jupyter-widgets/base", - "_model_module_version": "1.2.0", - "_model_name": "LayoutModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "LayoutView", - "align_content": null, - "align_items": null, - "align_self": null, - "border": null, - "bottom": null, - "display": null, - "flex": null, - "flex_flow": null, - "grid_area": null, - "grid_auto_columns": null, - "grid_auto_flow": null, - "grid_auto_rows": null, - "grid_column": null, - "grid_gap": null, - "grid_row": null, - "grid_template_areas": null, - "grid_template_columns": null, - "grid_template_rows": null, - "height": null, - "justify_content": null, - "justify_items": null, - "left": null, - "margin": null, - "max_height": null, - "max_width": null, - "min_height": null, - "min_width": null, - "object_fit": null, - "object_position": null, - "order": null, - "overflow": null, - "overflow_x": null, - "overflow_y": null, - "padding": null, - "right": null, - "top": null, - "visibility": null, - "width": null - } - }, - "1e7f2a13a3d44cb4908d1952f601d90f": { - "model_module": "@jupyter-widgets/controls", - "model_module_version": "1.5.0", - "model_name": "IntSliderModel", - "state": { - "_dom_classes": [], - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "IntSliderModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/controls", - "_view_module_version": "1.5.0", - "_view_name": "IntSliderView", - "continuous_update": true, - "description": "h_neg", - "description_tooltip": null, - "disabled": false, - "layout": "IPY_MODEL_4db00ffd8bbc444fac8dede2469d743a", - "max": 359, - "min": 0, - "orientation": "horizontal", - "readout": true, - "readout_format": "d", - "step": 1, - "style": "IPY_MODEL_9e5af469fab14fcf81523ee1a7bac2ab", - "value": 179 - } - }, - "2b4d3eeb52584f6f8a44f1077061e19c": { - "model_module": "@jupyter-widgets/controls", - "model_module_version": "1.5.0", - "model_name": "SliderStyleModel", - "state": { - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "SliderStyleModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "StyleView", - "description_width": "", - "handle_color": null - } - }, - "3e46ecb64d66422cb30385f8a2a11edb": { - "model_module": "@jupyter-widgets/output", - "model_module_version": "1.0.0", - "model_name": "OutputModel", - "state": { - "_dom_classes": [], - "_model_module": "@jupyter-widgets/output", - "_model_module_version": "1.0.0", - "_model_name": "OutputModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/output", - "_view_module_version": "1.0.0", - "_view_name": "OutputView", - "layout": "IPY_MODEL_618834f84d1440258917df7846021262", - "msg_id": "", - "outputs": [] - } - }, - "4db00ffd8bbc444fac8dede2469d743a": { - "model_module": "@jupyter-widgets/base", - "model_module_version": "1.2.0", - "model_name": "LayoutModel", - "state": { - "_model_module": "@jupyter-widgets/base", - "_model_module_version": "1.2.0", - "_model_name": "LayoutModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "LayoutView", - "align_content": null, - "align_items": null, - "align_self": null, - "border": null, - "bottom": null, - "display": null, - "flex": null, - "flex_flow": null, - "grid_area": null, - "grid_auto_columns": null, - "grid_auto_flow": null, - "grid_auto_rows": null, - "grid_column": null, - "grid_gap": null, - "grid_row": null, - "grid_template_areas": null, - "grid_template_columns": null, - "grid_template_rows": null, - "height": null, - "justify_content": null, - "justify_items": null, - "left": null, - "margin": null, - "max_height": null, - "max_width": null, - "min_height": null, - "min_width": null, - "object_fit": null, - "object_position": null, - "order": null, - "overflow": null, - "overflow_x": null, - "overflow_y": null, - "padding": null, - "right": null, - "top": null, - "visibility": null, - "width": null - } - }, - "4f5f5d8749bb4ff6aa9b420219dd1c23": { - "model_module": "@jupyter-widgets/controls", - "model_module_version": "1.5.0", - "model_name": "FloatSliderModel", - "state": { - "_dom_classes": [], - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "FloatSliderModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/controls", - "_view_module_version": "1.5.0", - "_view_name": "FloatSliderView", - "continuous_update": true, - "description": "", - "description_tooltip": null, - "disabled": false, - "layout": "IPY_MODEL_d8f1a40b21c34c1e832dd3496bfd7ef6", - "max": 99.9, - "min": 0.0, - "orientation": "horizontal", - "readout": true, - "readout_format": ".2f", - "step": 0.1, - "style": "IPY_MODEL_2b4d3eeb52584f6f8a44f1077061e19c", - "value": 49.95 - } - }, - "5470024c5cdd4d058229278a678a1bc8": { - "model_module": "@jupyter-widgets/controls", - "model_module_version": "1.5.0", - "model_name": "FloatSliderModel", - "state": { - "_dom_classes": [], - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "FloatSliderModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/controls", - "_view_module_version": "1.5.0", - "_view_name": "FloatSliderView", - "continuous_update": true, - "description": "l", - "description_tooltip": null, - "disabled": false, - "layout": "IPY_MODEL_d8f1a40b21c34c1e832dd3496bfd7ef6", - "max": 99.9, - "min": 0.0, - "orientation": "horizontal", - "readout": true, - "readout_format": ".2f", - "step": 0.1, - "style": "IPY_MODEL_2b4d3eeb52584f6f8a44f1077061e19c", - "value": 49.95 - } - }, - "5721ff8684484320a09017bfc24c68c4": { - "model_module": "@jupyter-widgets/base", - "model_module_version": "1.2.0", - "model_name": "LayoutModel", - "state": { - "_model_module": "@jupyter-widgets/base", - "_model_module_version": "1.2.0", - "_model_name": "LayoutModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "LayoutView", - "align_content": null, - "align_items": null, - "align_self": null, - "border": null, - "bottom": null, - "display": null, - "flex": null, - "flex_flow": null, - "grid_area": null, - "grid_auto_columns": null, - "grid_auto_flow": null, - "grid_auto_rows": null, - "grid_column": null, - "grid_gap": null, - "grid_row": null, - "grid_template_areas": null, - "grid_template_columns": null, - "grid_template_rows": null, - "height": null, - "justify_content": null, - "justify_items": null, - "left": null, - "margin": null, - "max_height": null, - "max_width": null, - "min_height": null, - "min_width": null, - "object_fit": null, - "object_position": null, - "order": null, - "overflow": null, - "overflow_x": null, - "overflow_y": null, - "padding": null, - "right": null, - "top": null, - "visibility": null, - "width": null - } - }, - "5ae1c99066914006b2ae4d4991c09d84": { - "model_module": "@jupyter-widgets/output", - "model_module_version": "1.0.0", - "model_name": "OutputModel", - "state": { - "_dom_classes": [], - "_model_module": "@jupyter-widgets/output", - "_model_module_version": "1.0.0", - "_model_name": "OutputModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/output", - "_view_module_version": "1.0.0", - "_view_name": "OutputView", - "layout": "IPY_MODEL_618834f84d1440258917df7846021262", - "msg_id": "", - "outputs": [ - { - "data": { - "text/html": "\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
 ABCD
01.7640520.400157nan2.240893
11.867558-0.9772780.950088-0.151357
2-0.1032190.4105990.1440441.454274
30.7610380.1216750.4438630.333674
41.494079-0.2051580.313068nan
5-2.5529900.6536190.864436-0.742165
62.269755-1.4543660.045759-0.187184
71.5327791.4693590.1549470.378163
8-0.887786-1.980796-0.3479120.156349
91.2302911.202380-0.387327-0.302303
\n", - "text/plain": "" - }, - "metadata": {}, - "output_type": "display_data" - } - ] - } - }, - "5e43fbb84b9540f1a6c6ad76efe2c7c0": { - "model_module": "@jupyter-widgets/controls", - "model_module_version": "1.5.0", - "model_name": "SliderStyleModel", - "state": { - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "SliderStyleModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "StyleView", - "description_width": "", - "handle_color": null - } - }, - "618834f84d1440258917df7846021262": { - "model_module": "@jupyter-widgets/base", - "model_module_version": "1.2.0", - "model_name": "LayoutModel", - "state": { - "_model_module": "@jupyter-widgets/base", - "_model_module_version": "1.2.0", - "_model_name": "LayoutModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "LayoutView", - "align_content": null, - "align_items": null, - "align_self": null, - "border": null, - "bottom": null, - "display": null, - "flex": null, - "flex_flow": null, - "grid_area": null, - "grid_auto_columns": null, - "grid_auto_flow": null, - "grid_auto_rows": null, - "grid_column": null, - "grid_gap": null, - "grid_row": null, - "grid_template_areas": null, - "grid_template_columns": null, - "grid_template_rows": null, - "height": null, - "justify_content": null, - "justify_items": null, - "left": null, - "margin": null, - "max_height": null, - "max_width": null, - "min_height": null, - "min_width": null, - "object_fit": null, - "object_position": null, - "order": null, - "overflow": null, - "overflow_x": null, - "overflow_y": null, - "padding": null, - "right": null, - "top": null, - "visibility": null, - "width": null - } - }, - "64a8388cf50e4ebead4a6f109539f10e": { - "model_module": "@jupyter-widgets/controls", - "model_module_version": "1.5.0", - "model_name": "VBoxModel", - "state": { - "_dom_classes": [ - "widget-interact" - ], - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "VBoxModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/controls", - "_view_module_version": "1.5.0", - "_view_name": "VBoxView", - "box_style": "", - "children": [], - "layout": "IPY_MODEL_19c78c6691d34efc8302c28a1cf3ef4f" - } - }, - "6535634e0b2448f5b641cee4336c1a84": { - "model_module": "@jupyter-widgets/controls", - "model_module_version": "1.5.0", - "model_name": "IntSliderModel", - "state": { - "_dom_classes": [], - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "IntSliderModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/controls", - "_view_module_version": "1.5.0", - "_view_name": "IntSliderView", - "continuous_update": true, - "description": "", - "description_tooltip": null, - "disabled": false, - "layout": "IPY_MODEL_a1bad22bdfb64c0f85a4156e914b5a36", - "max": 359, - "min": 0, - "orientation": "horizontal", - "readout": true, - "readout_format": "d", - "step": 1, - "style": "IPY_MODEL_e49df24ec5e544f19cecf232034f2319", - "value": 179 - } - }, - "77dfb0ad9bd446778dbffc0d8201373b": { - "model_module": "@jupyter-widgets/controls", - "model_module_version": "1.5.0", - "model_name": "SliderStyleModel", - "state": { - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "SliderStyleModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "StyleView", - "description_width": "", - "handle_color": null - } - }, - "7cb492a6543f45b9b0f767ca197b0dc5": { - "model_module": "@jupyter-widgets/base", - "model_module_version": "1.2.0", - "model_name": "LayoutModel", - "state": { - "_model_module": "@jupyter-widgets/base", - "_model_module_version": "1.2.0", - "_model_name": "LayoutModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "LayoutView", - "align_content": null, - "align_items": null, - "align_self": null, - "border": null, - "bottom": null, - "display": null, - "flex": null, - "flex_flow": null, - "grid_area": null, - "grid_auto_columns": null, - "grid_auto_flow": null, - "grid_auto_rows": null, - "grid_column": null, - "grid_gap": null, - "grid_row": null, - "grid_template_areas": null, - "grid_template_columns": null, - "grid_template_rows": null, - "height": null, - "justify_content": null, - "justify_items": null, - "left": null, - "margin": null, - "max_height": null, - "max_width": null, - "min_height": null, - "min_width": null, - "object_fit": null, - "object_position": null, - "order": null, - "overflow": null, - "overflow_x": null, - "overflow_y": null, - "padding": null, - "right": null, - "top": null, - "visibility": null, - "width": null - } - }, - "9ca04a7e7da044a99aa6dc1e31c0127a": { - "model_module": "@jupyter-widgets/controls", - "model_module_version": "1.5.0", - "model_name": "VBoxModel", - "state": { - "_dom_classes": [ - "widget-interact" - ], - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "VBoxModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/controls", - "_view_module_version": "1.5.0", - "_view_name": "VBoxView", - "box_style": "", - "children": [ - "IPY_MODEL_1e7f2a13a3d44cb4908d1952f601d90f", - "IPY_MODEL_a72d733698d94389824fed752fb35e9c", - "IPY_MODEL_c1d450968de641ee86032e20cc08acd1", - "IPY_MODEL_5470024c5cdd4d058229278a678a1bc8", - "IPY_MODEL_5ae1c99066914006b2ae4d4991c09d84" - ], - "layout": "IPY_MODEL_19c78c6691d34efc8302c28a1cf3ef4f" - } - }, - "9e5af469fab14fcf81523ee1a7bac2ab": { - "model_module": "@jupyter-widgets/controls", - "model_module_version": "1.5.0", - "model_name": "SliderStyleModel", - "state": { - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "SliderStyleModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "StyleView", - "description_width": "", - "handle_color": null - } - }, - "a1bad22bdfb64c0f85a4156e914b5a36": { - "model_module": "@jupyter-widgets/base", - "model_module_version": "1.2.0", - "model_name": "LayoutModel", - "state": { - "_model_module": "@jupyter-widgets/base", - "_model_module_version": "1.2.0", - "_model_name": "LayoutModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "LayoutView", - "align_content": null, - "align_items": null, - "align_self": null, - "border": null, - "bottom": null, - "display": null, - "flex": null, - "flex_flow": null, - "grid_area": null, - "grid_auto_columns": null, - "grid_auto_flow": null, - "grid_auto_rows": null, - "grid_column": null, - "grid_gap": null, - "grid_row": null, - "grid_template_areas": null, - "grid_template_columns": null, - "grid_template_rows": null, - "height": null, - "justify_content": null, - "justify_items": null, - "left": null, - "margin": null, - "max_height": null, - "max_width": null, - "min_height": null, - "min_width": null, - "object_fit": null, - "object_position": null, - "order": null, - "overflow": null, - "overflow_x": null, - "overflow_y": null, - "padding": null, - "right": null, - "top": null, - "visibility": null, - "width": null - } - }, - "a653b4b8ecee44789c2168105b6b4ac1": { - "model_module": "@jupyter-widgets/base", - "model_module_version": "1.2.0", - "model_name": "LayoutModel", - "state": { - "_model_module": "@jupyter-widgets/base", - "_model_module_version": "1.2.0", - "_model_name": "LayoutModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "LayoutView", - "align_content": null, - "align_items": null, - "align_self": null, - "border": null, - "bottom": null, - "display": null, - "flex": null, - "flex_flow": null, - "grid_area": null, - "grid_auto_columns": null, - "grid_auto_flow": null, - "grid_auto_rows": null, - "grid_column": null, - "grid_gap": null, - "grid_row": null, - "grid_template_areas": null, - "grid_template_columns": null, - "grid_template_rows": null, - "height": null, - "justify_content": null, - "justify_items": null, - "left": null, - "margin": null, - "max_height": null, - "max_width": null, - "min_height": null, - "min_width": null, - "object_fit": null, - "object_position": null, - "order": null, - "overflow": null, - "overflow_x": null, - "overflow_y": null, - "padding": null, - "right": null, - "top": null, - "visibility": null, - "width": null - } - }, - "a72d733698d94389824fed752fb35e9c": { - "model_module": "@jupyter-widgets/controls", - "model_module_version": "1.5.0", - "model_name": "IntSliderModel", - "state": { - "_dom_classes": [], - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "IntSliderModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/controls", - "_view_module_version": "1.5.0", - "_view_name": "IntSliderView", - "continuous_update": true, - "description": "h_pos", - "description_tooltip": null, - "disabled": false, - "layout": "IPY_MODEL_a1bad22bdfb64c0f85a4156e914b5a36", - "max": 359, - "min": 0, - "orientation": "horizontal", - "readout": true, - "readout_format": "d", - "step": 1, - "style": "IPY_MODEL_e49df24ec5e544f19cecf232034f2319", - "value": 179 - } - }, - "b539ddb2c2f9406fbe35ab10f4a7564a": { - "model_module": "@jupyter-widgets/base", - "model_module_version": "1.2.0", - "model_name": "LayoutModel", - "state": { - "_model_module": "@jupyter-widgets/base", - "_model_module_version": "1.2.0", - "_model_name": "LayoutModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "LayoutView", - "align_content": null, - "align_items": null, - "align_self": null, - "border": null, - "bottom": null, - "display": null, - "flex": null, - "flex_flow": null, - "grid_area": null, - "grid_auto_columns": null, - "grid_auto_flow": null, - "grid_auto_rows": null, - "grid_column": null, - "grid_gap": null, - "grid_row": null, - "grid_template_areas": null, - "grid_template_columns": null, - "grid_template_rows": null, - "height": null, - "justify_content": null, - "justify_items": null, - "left": null, - "margin": null, - "max_height": null, - "max_width": null, - "min_height": null, - "min_width": null, - "object_fit": null, - "object_position": null, - "order": null, - "overflow": null, - "overflow_x": null, - "overflow_y": null, - "padding": null, - "right": null, - "top": null, - "visibility": null, - "width": null - } - }, - "bff79996e7d14fe8a4991062eb0a2724": { - "model_module": "@jupyter-widgets/base", - "model_module_version": "1.2.0", - "model_name": "LayoutModel", - "state": { - "_model_module": "@jupyter-widgets/base", - "_model_module_version": "1.2.0", - "_model_name": "LayoutModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "LayoutView", - "align_content": null, - "align_items": null, - "align_self": null, - "border": null, - "bottom": null, - "display": null, - "flex": null, - "flex_flow": null, - "grid_area": null, - "grid_auto_columns": null, - "grid_auto_flow": null, - "grid_auto_rows": null, - "grid_column": null, - "grid_gap": null, - "grid_row": null, - "grid_template_areas": null, - "grid_template_columns": null, - "grid_template_rows": null, - "height": null, - "justify_content": null, - "justify_items": null, - "left": null, - "margin": null, - "max_height": null, - "max_width": null, - "min_height": null, - "min_width": null, - "object_fit": null, - "object_position": null, - "order": null, - "overflow": null, - "overflow_x": null, - "overflow_y": null, - "padding": null, - "right": null, - "top": null, - "visibility": null, - "width": null - } - }, - "c1d450968de641ee86032e20cc08acd1": { - "model_module": "@jupyter-widgets/controls", - "model_module_version": "1.5.0", - "model_name": "FloatSliderModel", - "state": { - "_dom_classes": [], - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "FloatSliderModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/controls", - "_view_module_version": "1.5.0", - "_view_name": "FloatSliderView", - "continuous_update": true, - "description": "s", - "description_tooltip": null, - "disabled": false, - "layout": "IPY_MODEL_a653b4b8ecee44789c2168105b6b4ac1", - "max": 99.9, - "min": 0.0, - "orientation": "horizontal", - "readout": true, - "readout_format": ".2f", - "step": 0.1, - "style": "IPY_MODEL_d38ed46cf67f4270a86a4b8d2a333242", - "value": 49.95 - } - }, - "c40aef508c204d968c4026e35961d3f2": { - "model_module": "@jupyter-widgets/base", - "model_module_version": "1.2.0", - "model_name": "LayoutModel", - "state": { - "_model_module": "@jupyter-widgets/base", - "_model_module_version": "1.2.0", - "_model_name": "LayoutModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "LayoutView", - "align_content": null, - "align_items": null, - "align_self": null, - "border": null, - "bottom": null, - "display": null, - "flex": null, - "flex_flow": null, - "grid_area": null, - "grid_auto_columns": null, - "grid_auto_flow": null, - "grid_auto_rows": null, - "grid_column": null, - "grid_gap": null, - "grid_row": null, - "grid_template_areas": null, - "grid_template_columns": null, - "grid_template_rows": null, - "height": null, - "justify_content": null, - "justify_items": null, - "left": null, - "margin": null, - "max_height": null, - "max_width": null, - "min_height": null, - "min_width": null, - "object_fit": null, - "object_position": null, - "order": null, - "overflow": null, - "overflow_x": null, - "overflow_y": null, - "padding": null, - "right": null, - "top": null, - "visibility": null, - "width": null - } - }, - "c62d9dc168a44e3b909bdda066173284": { - "model_module": "@jupyter-widgets/base", - "model_module_version": "1.2.0", - "model_name": "LayoutModel", - "state": { - "_model_module": "@jupyter-widgets/base", - "_model_module_version": "1.2.0", - "_model_name": "LayoutModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "LayoutView", - "align_content": null, - "align_items": null, - "align_self": null, - "border": null, - "bottom": null, - "display": null, - "flex": null, - "flex_flow": null, - "grid_area": null, - "grid_auto_columns": null, - "grid_auto_flow": null, - "grid_auto_rows": null, - "grid_column": null, - "grid_gap": null, - "grid_row": null, - "grid_template_areas": null, - "grid_template_columns": null, - "grid_template_rows": null, - "height": null, - "justify_content": null, - "justify_items": null, - "left": null, - "margin": null, - "max_height": null, - "max_width": null, - "min_height": null, - "min_width": null, - "object_fit": null, - "object_position": null, - "order": null, - "overflow": null, - "overflow_x": null, - "overflow_y": null, - "padding": null, - "right": null, - "top": null, - "visibility": null, - "width": null - } - }, - "d38ed46cf67f4270a86a4b8d2a333242": { - "model_module": "@jupyter-widgets/controls", - "model_module_version": "1.5.0", - "model_name": "SliderStyleModel", - "state": { - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "SliderStyleModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "StyleView", - "description_width": "", - "handle_color": null - } - }, - "d8f1a40b21c34c1e832dd3496bfd7ef6": { - "model_module": "@jupyter-widgets/base", - "model_module_version": "1.2.0", - "model_name": "LayoutModel", - "state": { - "_model_module": "@jupyter-widgets/base", - "_model_module_version": "1.2.0", - "_model_name": "LayoutModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "LayoutView", - "align_content": null, - "align_items": null, - "align_self": null, - "border": null, - "bottom": null, - "display": null, - "flex": null, - "flex_flow": null, - "grid_area": null, - "grid_auto_columns": null, - "grid_auto_flow": null, - "grid_auto_rows": null, - "grid_column": null, - "grid_gap": null, - "grid_row": null, - "grid_template_areas": null, - "grid_template_columns": null, - "grid_template_rows": null, - "height": null, - "justify_content": null, - "justify_items": null, - "left": null, - "margin": null, - "max_height": null, - "max_width": null, - "min_height": null, - "min_width": null, - "object_fit": null, - "object_position": null, - "order": null, - "overflow": null, - "overflow_x": null, - "overflow_y": null, - "padding": null, - "right": null, - "top": null, - "visibility": null, - "width": null - } - }, - "da5e66c57d70414dbe0734a4d36529cc": { - "model_module": "@jupyter-widgets/controls", - "model_module_version": "1.5.0", - "model_name": "SliderStyleModel", - "state": { - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "SliderStyleModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "StyleView", - "description_width": "", - "handle_color": null - } - }, - "e49df24ec5e544f19cecf232034f2319": { - "model_module": "@jupyter-widgets/controls", - "model_module_version": "1.5.0", - "model_name": "SliderStyleModel", - "state": { - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "SliderStyleModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "StyleView", - "description_width": "", - "handle_color": null - } - }, - "f255f802b3184e0b8374ea33f3be4502": { - "model_module": "@jupyter-widgets/controls", - "model_module_version": "1.5.0", - "model_name": "IntSliderModel", - "state": { - "_dom_classes": [], - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "IntSliderModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/controls", - "_view_module_version": "1.5.0", - "_view_name": "IntSliderView", - "continuous_update": true, - "description": "", - "description_tooltip": null, - "disabled": false, - "layout": "IPY_MODEL_4db00ffd8bbc444fac8dede2469d743a", - "max": 359, - "min": 0, - "orientation": "horizontal", - "readout": true, - "readout_format": "d", - "step": 1, - "style": "IPY_MODEL_9e5af469fab14fcf81523ee1a7bac2ab", - "value": 179 - } - }, - "f8e6893e62a24b489d804297d0047c57": { - "model_module": "@jupyter-widgets/controls", - "model_module_version": "1.5.0", - "model_name": "SliderStyleModel", - "state": { - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "SliderStyleModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "StyleView", - "description_width": "", - "handle_color": null - } - } - }, - "version_major": 2, - "version_minor": 0 - } - } - }, - "nbformat": 4, - "nbformat_minor": 1 -}