From 64d2270522b705d7470cf0b26debe2552d853517 Mon Sep 17 00:00:00 2001 From: Rahul Hoque Date: Sun, 20 Apr 2025 17:16:46 -0400 Subject: [PATCH 1/4] Make select by substring --- books.xml | 120 +++++++++++++++++++++++++++++++++++++ pandas/core/frame.py | 82 +++++++++++++++++++++++++ pandas/tests/frame/test_ | 0 placeholder.txt | 125 +++++++++++++++++++++++++++++++++++++++ test.py | 15 +++++ 5 files changed, 342 insertions(+) create mode 100644 books.xml create mode 100644 pandas/tests/frame/test_ create mode 100644 placeholder.txt create mode 100644 test.py diff --git a/books.xml b/books.xml new file mode 100644 index 0000000000000..e3d1fe8760515 --- /dev/null +++ b/books.xml @@ -0,0 +1,120 @@ + + + + Gambardella, Matthew + XML Developer's Guide + Computer + 44.95 + 2000-10-01 + An in-depth look at creating applications + with XML. + + + Ralls, Kim + Midnight Rain + Fantasy + 5.95 + 2000-12-16 + A former architect battles corporate zombies, + an evil sorceress, and her own childhood to become queen + of the world. + + + Corets, Eva + Maeve Ascendant + Fantasy + 5.95 + 2000-11-17 + After the collapse of a nanotechnology + society in England, the young survivors lay the + foundation for a new society. + + + Corets, Eva + Oberon's Legacy + Fantasy + 5.95 + 2001-03-10 + In post-apocalypse England, the mysterious + agent known only as Oberon helps to create a new life + for the inhabitants of London. Sequel to Maeve + Ascendant. + + + Corets, Eva + The Sundered Grail + Fantasy + 5.95 + 2001-09-10 + The two daughters of Maeve, half-sisters, + battle one another for control of England. Sequel to + Oberon's Legacy. + + + Randall, Cynthia + Lover Birds + Romance + 4.95 + 2000-09-02 + When Carla meets Paul at an ornithology + conference, tempers fly as feathers get ruffled. + + + Thurman, Paula + Splish Splash + Romance + 4.95 + 2000-11-02 + A deep sea diver finds true love twenty + thousand leagues beneath the sea. + + + Knorr, Stefan + Creepy Crawlies + Horror + 4.95 + 2000-12-06 + An anthology of horror stories about roaches, + centipedes, scorpions and other insects. + + + Kress, Peter + Paradox Lost + Science Fiction + 6.95 + 2000-11-02 + After an inadvertant trip through a Heisenberg + Uncertainty Device, James Salway discovers the problems + of being quantum. + + + O'Brien, Tim + Microsoft .NET: The Programming Bible + Computer + 36.95 + 2000-12-09 + Microsoft's .NET initiative is explored in + detail in this deep programmer's reference. + + + O'Brien, Tim + MSXML3: A Comprehensive Guide + Computer + 36.95 + 2000-12-01 + The Microsoft MSXML3 parser is covered in + detail, with attention to XML DOM interfaces, XSLT processing, + SAX and more. + + + Galos, Mike + Visual Studio 7: A Comprehensive Guide + Computer + 49.95 + 2001-04-16 + Microsoft Visual Studio 7 is explored in depth, + looking at how Visual Basic, Visual C++, C#, and ASP+ are + integrated into a comprehensive development + environment. + + \ No newline at end of file diff --git a/pandas/core/frame.py b/pandas/core/frame.py index dea246bcd1cf8..658793842194b 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -31,8 +31,10 @@ TYPE_CHECKING, Any, Literal, + List, cast, overload, + Union ) import warnings @@ -7716,6 +7718,86 @@ def nsmallest( Nauru 337000 182 NR """ return selectn.SelectNFrame(self, n=n, keep=keep, columns=columns).nsmallest() + + def select_by_substr( + self, + substr: Union[str, List[str]], + ignore_case: bool = True, + ) -> DataFrame | None: + """ + Return columns whose names contain the specified substring(s). + + Select and return all columns from the DataFrame whose names contain + the given substring or any of a list of substrings. By default, the + search is case-insensitive. + + Parameters + ---------- + substr : str or list of str + Substring or list of substrings to search for in column names. + ignore_case : bool, default True + Whether to ignore case when searching for substrings. + + Returns + ------- + DataFrame or None + DataFrame containing only the columns whose names match the + specified substring(s). Returns None if no columns match. + + See Also + -------- + DataFrame.filter : Subset the columns or rows of a DataFrame according to labels or a boolean array. + DataFrame.loc : Access a group of rows and columns by label(s) or a boolean array. + + Notes + ----- + All columns containing at least one of the provided substrings will be + returned. If no columns match, None is returned. + + Examples + -------- + >>> df = pd.DataFrame({ + ... "first_name": ["Alice", "Bob"], + ... "last_name": ["Smith", "Jones"], + ... "age": [25, 30], + ... "city": ["NY", "LA"] + ... }) + >>> df.select_by_substr("name") + first_name last_name + 0 Alice Smith + 1 Bob Jones + + >>> df.select_by_substr(["name", "city"]) + first_name last_name city + 0 Alice Smith NY + 1 Bob Jones LA + + >>> df.select_by_substr("AGE", ignore_case=False) # No match due to case + None + + >>> df.select_by_substr("AGE", ignore_case=True) + age + 0 25 + 1 30 + """ + substr = [substr] if isinstance(substr, str) else substr + selected_cols = self.columns + + if ignore_case: + selected_cols = [ + col for col in self.columns + if any(sub.casefold() in col.casefold() + for sub in substr) + ] + else: + selected_cols = [ + col for col in self.columns + if any(sub in col + for sub in substr) + ] + + selected_cols = list(set(selected_cols)) + return self[selected_cols] def swaplevel(self, i: Axis = -2, j: Axis = -1, axis: Axis = 0) -> DataFrame: """ diff --git a/pandas/tests/frame/test_ b/pandas/tests/frame/test_ new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/placeholder.txt b/placeholder.txt new file mode 100644 index 0000000000000..ec10be0abd110 --- /dev/null +++ b/placeholder.txt @@ -0,0 +1,125 @@ +Return the first `n` rows ordered by `columns` in ascending order. + + Return the first `n` rows with the smallest values in `columns`, in + ascending order. The columns that are not specified are returned as + well, but not used for ordering. + + This method is equivalent to + ``df.sort_values(columns, ascending=True).head(n)``, but more + performant. + + Parameters + ---------- + n : int + Number of items to retrieve. + columns : list or str + Column name or names to order by. + keep : {'first', 'last', 'all'}, default 'first' + Where there are duplicate values: + + - ``first`` : take the first occurrence. + - ``last`` : take the last occurrence. + - ``all`` : keep all the ties of the largest item even if it means + selecting more than ``n`` items. + + Returns + ------- + DataFrame + DataFrame with the first `n` rows ordered by `columns` in ascending order. + + See Also + -------- + DataFrame.nlargest : Return the first `n` rows ordered by `columns` in + descending order. + DataFrame.sort_values : Sort DataFrame by the values. + DataFrame.head : Return the first `n` rows without re-ordering. + + Examples + -------- + >>> df = pd.DataFrame( + ... { + ... "population": [ + ... 59000000, + ... 65000000, + ... 434000, + ... 434000, + ... 434000, + ... 337000, + ... 337000, + ... 11300, + ... 11300, + ... ], + ... "GDP": [1937894, 2583560, 12011, 4520, 12128, 17036, 182, 38, 311], + ... "alpha-2": ["IT", "FR", "MT", "MV", "BN", "IS", "NR", "TV", "AI"], + ... }, + ... index=[ + ... "Italy", + ... "France", + ... "Malta", + ... "Maldives", + ... "Brunei", + ... "Iceland", + ... "Nauru", + ... "Tuvalu", + ... "Anguilla", + ... ], + ... ) + >>> df + population GDP alpha-2 + Italy 59000000 1937894 IT + France 65000000 2583560 FR + Malta 434000 12011 MT + Maldives 434000 4520 MV + Brunei 434000 12128 BN + Iceland 337000 17036 IS + Nauru 337000 182 NR + Tuvalu 11300 38 TV + Anguilla 11300 311 AI + + In the following example, we will use ``nsmallest`` to select the + three rows having the smallest values in column "population". + + >>> df.nsmallest(3, "population") + population GDP alpha-2 + Tuvalu 11300 38 TV + Anguilla 11300 311 AI + Iceland 337000 17036 IS + + When using ``keep='last'``, ties are resolved in reverse order: + + >>> df.nsmallest(3, "population", keep="last") + population GDP alpha-2 + Anguilla 11300 311 AI + Tuvalu 11300 38 TV + Nauru 337000 182 NR + + When using ``keep='all'``, the number of element kept can go beyond ``n`` + if there are duplicate values for the largest element, all the + ties are kept. + + >>> df.nsmallest(3, "population", keep="all") + population GDP alpha-2 + Tuvalu 11300 38 TV + Anguilla 11300 311 AI + Iceland 337000 17036 IS + Nauru 337000 182 NR + + However, ``nsmallest`` does not keep ``n`` distinct + smallest elements: + + >>> df.nsmallest(4, "population", keep="all") + population GDP alpha-2 + Tuvalu 11300 38 TV + Anguilla 11300 311 AI + Iceland 337000 17036 IS + Nauru 337000 182 NR + + To order by the smallest values in column "population" and then "GDP", we can + specify multiple columns like in the next example. + + >>> df.nsmallest(3, ["population", "GDP"]) + population GDP alpha-2 + Tuvalu 11300 38 TV + Anguilla 11300 311 AI + Nauru 337000 182 NR + """ \ No newline at end of file diff --git a/test.py b/test.py new file mode 100644 index 0000000000000..34fd68207ab8b --- /dev/null +++ b/test.py @@ -0,0 +1,15 @@ +# contributing guide: https://pandas.pydata.org/docs/dev/development/contributing.html#pushing-your-changes +import pandas as pd + +df = pd.DataFrame({ + "yes": [5000, 2, 3], + "Byesyes": [4, 5, 6], + "no": [7, 8, 9], + "Byesno": [10, 11, 12], + "YES": [13, 14, 15], + "NO": [16, 17, 18], + "YESYES": [19, 20, 21], +}) + +# Test the DataFrame creation +print(df.select_by_substr("skibidi")) \ No newline at end of file From 822b5cca16dffa56c5f0a018cc5d7d15dc02e6d1 Mon Sep 17 00:00:00 2001 From: Rahul Hoque Date: Sun, 20 Apr 2025 17:58:08 -0400 Subject: [PATCH 2/4] Refine functionality and make tests. --- books.xml | 120 - doc/source/user_guide/style.nbconvert.ipynb | 15803 ++++++++++++++++++ pandas/core/frame.py | 35 +- pandas/tests/frame/test_ | 0 pandas/tests/frame/test_select_by_substr.py | 82 + placeholder.txt | 125 - test.py | 15 - 7 files changed, 15902 insertions(+), 278 deletions(-) delete mode 100644 books.xml create mode 100644 doc/source/user_guide/style.nbconvert.ipynb delete mode 100644 pandas/tests/frame/test_ create mode 100644 pandas/tests/frame/test_select_by_substr.py delete mode 100644 placeholder.txt delete mode 100644 test.py diff --git a/books.xml b/books.xml deleted file mode 100644 index e3d1fe8760515..0000000000000 --- a/books.xml +++ /dev/null @@ -1,120 +0,0 @@ - - - - Gambardella, Matthew - XML Developer's Guide - Computer - 44.95 - 2000-10-01 - An in-depth look at creating applications - with XML. - - - Ralls, Kim - Midnight Rain - Fantasy - 5.95 - 2000-12-16 - A former architect battles corporate zombies, - an evil sorceress, and her own childhood to become queen - of the world. - - - Corets, Eva - Maeve Ascendant - Fantasy - 5.95 - 2000-11-17 - After the collapse of a nanotechnology - society in England, the young survivors lay the - foundation for a new society. - - - Corets, Eva - Oberon's Legacy - Fantasy - 5.95 - 2001-03-10 - In post-apocalypse England, the mysterious - agent known only as Oberon helps to create a new life - for the inhabitants of London. Sequel to Maeve - Ascendant. - - - Corets, Eva - The Sundered Grail - Fantasy - 5.95 - 2001-09-10 - The two daughters of Maeve, half-sisters, - battle one another for control of England. Sequel to - Oberon's Legacy. - - - Randall, Cynthia - Lover Birds - Romance - 4.95 - 2000-09-02 - When Carla meets Paul at an ornithology - conference, tempers fly as feathers get ruffled. - - - Thurman, Paula - Splish Splash - Romance - 4.95 - 2000-11-02 - A deep sea diver finds true love twenty - thousand leagues beneath the sea. - - - Knorr, Stefan - Creepy Crawlies - Horror - 4.95 - 2000-12-06 - An anthology of horror stories about roaches, - centipedes, scorpions and other insects. - - - Kress, Peter - Paradox Lost - Science Fiction - 6.95 - 2000-11-02 - After an inadvertant trip through a Heisenberg - Uncertainty Device, James Salway discovers the problems - of being quantum. - - - O'Brien, Tim - Microsoft .NET: The Programming Bible - Computer - 36.95 - 2000-12-09 - Microsoft's .NET initiative is explored in - detail in this deep programmer's reference. - - - O'Brien, Tim - MSXML3: A Comprehensive Guide - Computer - 36.95 - 2000-12-01 - The Microsoft MSXML3 parser is covered in - detail, with attention to XML DOM interfaces, XSLT processing, - SAX and more. - - - Galos, Mike - Visual Studio 7: A Comprehensive Guide - Computer - 49.95 - 2001-04-16 - Microsoft Visual Studio 7 is explored in depth, - looking at how Visual Basic, Visual C++, C#, and ASP+ are - integrated into a comprehensive development - environment. - - \ 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..7b7206e5cd926 --- /dev/null +++ b/doc/source/user_guide/style.nbconvert.ipynb @@ -0,0 +1,15803 @@ +{ + "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 Object and Customising the Display\n", + "Styling and output display customisation should be performed **after** the data in a DataFrame has been processed. The Styler is **not** dynamically updated if further changes to the DataFrame are made. The `DataFrame.style` attribute is a property that returns a [Styler][styler] object. It has a `_repr_html_` method defined on it so it is rendered automatically in Jupyter Notebook.\n", + "\n", + "The Styler, which can be used for large data but is primarily designed for small data, currently has the ability to output to these formats:\n", + "\n", + " - HTML\n", + " - LaTeX\n", + " - String (and CSV by extension)\n", + " - Excel\n", + " - (JSON is not currently available)\n", + "\n", + "The first three of these have display customisation methods designed to format and customise the output. These include:\n", + "\n", + " - Formatting values, the index and columns headers, using [.format()][formatfunc] and [.format_index()][formatfuncindex],\n", + " - Renaming the index or column header labels, using [.relabel_index()][relabelfunc]\n", + " - Hiding certain columns, the index and/or column headers, or index names, using [.hide()][hidefunc]\n", + " - Concatenating similar DataFrames, using [.concat()][concatfunc]\n", + " \n", + "[styler]: ../reference/api/pandas.io.formats.style.Styler.rst\n", + "[viz]: visualization.rst\n", + "[download]: https://nbviewer.org/github/pandas-dev/pandas/blob/main/doc/source/user_guide/style.ipynb\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\n", + "[relabelfunc]: ../reference/api/pandas.io.formats.style.Styler.relabel_index.rst\n", + "[hidefunc]: ../reference/api/pandas.io.formats.style.Styler.hide.rst\n", + "[concatfunc]: ../reference/api/pandas.io.formats.style.Styler.concat.rst" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Formatting the Display\n", + "\n", + "### Formatting Values\n", + "\n", + "The [Styler][styler] distinguishes the *display* value from the *actual* value, in both data values and index or columns headers. To control the display value, the text is printed in each cell as a 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. We can also overwrite index names.\n", + "\n", + "Additionally, the format function has a **precision** argument to specifically help format floats, as well as **decimal** and **thousands** separators to support other locales, an **na_rep** argument to display missing data, and an **escape** and **hyperlinks** arguments to help displaying safe-HTML or safe-LaTeX. The default formatter is configured to adopt pandas' global options such as `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\n", + "[relabelfunc]: ../reference/api/pandas.io.formats.style.Styler.relabel_index.rst" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:46.042039Z", + "iopub.status.busy": "2025-04-20T21:37:46.041167Z", + "iopub.status.idle": "2025-04-20T21:37:47.633616Z", + "shell.execute_reply": "2025-04-20T21:37:47.632671Z" + } + }, + "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", + "
 STRINGSINTSFLOATS
row 1Adam11,123
row 2Mike31.000,230
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import pandas as pd\n", + "import numpy as np\n", + "\n", + "df = pd.DataFrame(\n", + " {\"strings\": [\"Adam\", \"Mike\"], \"ints\": [1, 3], \"floats\": [1.123, 1000.23]}\n", + ")\n", + "df.style.format(precision=3, thousands=\".\", decimal=\",\").format_index(\n", + " str.upper, axis=1\n", + ").relabel_index([\"row 1\", \"row 2\"], axis=0)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Using Styler to manipulate the display is a useful feature because maintaining the indexing and data values for other purposes gives greater control. You do not have to overwrite your DataFrame to display it how you like. Here is a more comprehensive example of using the formatting functions whilst still relying on the underlying data for indexing and calculations." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:47.671864Z", + "iopub.status.busy": "2025-04-20T21:37:47.670590Z", + "iopub.status.idle": "2025-04-20T21:37:47.694246Z", + "shell.execute_reply": "2025-04-20T21:37:47.693216Z" + } + }, + "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-012.8527423.712998
2021-01-020.8375772.062004
2021-01-034.2647011.427223
2021-01-042.4410203.751653
2021-01-052.8999544.274491
2021-01-060.1860490.268773
2021-01-071.4978500.614012
2021-01-081.4862914.696579
2021-01-090.5676860.383801
2021-01-102.8403471.571832
\n", + "
" + ], + "text/plain": [ + " Tokyo Beijing\n", + "2021-01-01 2.852742 3.712998\n", + "2021-01-02 0.837577 2.062004\n", + "2021-01-03 4.264701 1.427223\n", + "2021-01-04 2.441020 3.751653\n", + "2021-01-05 2.899954 4.274491\n", + "2021-01-06 0.186049 0.268773\n", + "2021-01-07 1.497850 0.614012\n", + "2021-01-08 1.486291 4.696579\n", + "2021-01-09 0.567686 0.383801\n", + "2021-01-10 2.840347 1.571832" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "weather_df = pd.DataFrame(\n", + " np.random.default_rng().random((10, 2)) * 5,\n", + " index=pd.date_range(start=\"2021-01-01\", periods=10),\n", + " columns=[\"Tokyo\", \"Beijing\"],\n", + ")\n", + "\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", + "\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", + "\n", + "weather_df" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:47.698791Z", + "iopub.status.busy": "2025-04-20T21:37:47.697210Z", + "iopub.status.idle": "2025-04-20T21:37:47.836925Z", + "shell.execute_reply": "2025-04-20T21:37:47.835553Z" + } + }, + "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
MondayRainHeavy Rain
TuesdayHeavy RainHeavy Rain
WednesdayDryDry
ThursdayDryDry
FridayDryHeavy Rain
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 3, + "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", + "[hideidx]: ../reference/api/pandas.io.formats.style.Styler.hide.rst" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:47.841056Z", + "iopub.status.busy": "2025-04-20T21:37:47.840128Z", + "iopub.status.idle": "2025-04-20T21:37:47.855033Z", + "shell.execute_reply": "2025-04-20T21:37:47.853312Z" + } + }, + "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", + "
 13
10.1385450.204426
3-0.048063-1.212957
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df = pd.DataFrame(np.random.default_rng().standard_normal((5, 5)))\n", + "df.style.hide(subset=[0, 2, 4], axis=0).hide(subset=[0, 2, 4], axis=1)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "To invert the function to a **show** functionality it is best practice to compose a list of hidden items." + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:47.859221Z", + "iopub.status.busy": "2025-04-20T21:37:47.858231Z", + "iopub.status.idle": "2025-04-20T21:37:47.870768Z", + "shell.execute_reply": "2025-04-20T21:37:47.869677Z" + } + }, + "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", + "
 024
0-0.517507-0.434444-0.033583
21.2178770.4677610.386644
41.7256791.512723-1.283392
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "show = [0, 2, 4]\n", + "df.style.hide([row for row in df.index if row not in show], axis=0).hide(\n", + " [col for col in df.columns if col not in show], axis=1\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Concatenating DataFrame Outputs\n", + "\n", + "Two or more Stylers can be concatenated together provided they share the same columns. This is very useful for showing summary statistics for a DataFrame, and is often used in combination with DataFrame.agg.\n", + "\n", + "Since the objects concatenated are Stylers they can independently be styled as will be shown below and their concatenation preserves those styles." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:47.874986Z", + "iopub.status.busy": "2025-04-20T21:37:47.873882Z", + "iopub.status.idle": "2025-04-20T21:37:47.890291Z", + "shell.execute_reply": "2025-04-20T21:37:47.888841Z" + } + }, + "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", + "
 01234
0-0.5-0.9-0.4-0.1-0.0
10.20.1-1.60.20.2
21.20.70.50.30.4
30.8-0.01.1-1.2-0.7
41.70.21.50.3-1.3
Sum3.5250.1151.062-0.550-1.444
Average0.7050.0230.212-0.110-0.289
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "summary_styler = (\n", + " df.agg([\"sum\", \"mean\"]).style.format(precision=3).relabel_index([\"Sum\", \"Average\"])\n", + ")\n", + "df.style.format(precision=1).concat(summary_styler)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Styler Object and HTML \n", + "\n", + "The [Styler][styler] was originally constructed to support the wide array of HTML formatting options. Its HTML output 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 existing user interface designs.\n", + "\n", + "Below we demonstrate the default output, which 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). This section will also provide a walkthrough for how to convert this default output to represent a DataFrame output that is more communicative. For example how we can build `s`:\n", + "\n", + "[tohtml]: ../reference/api/pandas.io.formats.style.Styler.to_html.rst\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": 7, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:47.894156Z", + "iopub.status.busy": "2025-04-20T21:37:47.893703Z", + "iopub.status.idle": "2025-04-20T21:37:47.910519Z", + "shell.execute_reply": "2025-04-20T21:37:47.909063Z" + } + }, + "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": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "idx = pd.Index([\"Tumour (Positive)\", \"Non-Tumour (Negative)\"], name=\"Actual Label:\")\n", + "cols = pd.MultiIndex.from_product(\n", + " [[\"Decision Tree\", \"Regression\", \"Random\"], [\"Tumour\", \"Non-Tumour\"]],\n", + " names=[\"Model:\", \"Predicted:\"],\n", + ")\n", + "df = pd.DataFrame(\n", + " [[38.0, 2.0, 18.0, 22.0, 21, np.nan], [19, 439, 6, 452, 226, 232]],\n", + " index=idx,\n", + " columns=cols,\n", + ")\n", + "df.style" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:47.915467Z", + "iopub.status.busy": "2025-04-20T21:37:47.914444Z", + "iopub.status.idle": "2025-04-20T21:37:47.928854Z", + "shell.execute_reply": "2025-04-20T21:37:47.927867Z" + }, + "nbsphinx": "hidden" + }, + "outputs": [], + "source": [ + "# Hidden cell to just create the below example: code is covered throughout the guide.\n", + "s = (\n", + " df.style.hide([(\"Random\", \"Tumour\"), (\"Random\", \"Non-Tumour\")], axis=\"columns\")\n", + " .format(\"{:.0f}\")\n", + " .set_table_styles(\n", + " [\n", + " {\"selector\": \"\", \"props\": \"border-collapse: separate;\"},\n", + " {\"selector\": \"caption\", \"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", + " {\n", + " \"selector\": \"th:not(.index_name)\",\n", + " \"props\": \"background-color: #000066; color: white;\",\n", + " },\n", + " {\"selector\": \"th.col_heading\", \"props\": \"text-align: center;\"},\n", + " {\"selector\": \"th.col_heading.level0\", \"props\": \"font-size: 1.5em;\"},\n", + " {\"selector\": \"th.col2\", \"props\": \"border-left: 1px solid white;\"},\n", + " {\"selector\": \".col2\", \"props\": \"border-left: 1px solid #000066;\"},\n", + " {\"selector\": \"td\", \"props\": \"text-align: center; font-weight:bold;\"},\n", + " {\"selector\": \".true\", \"props\": \"background-color: #e6ffe6;\"},\n", + " {\"selector\": \".false\", \"props\": \"background-color: #ffe6e6;\"},\n", + " {\"selector\": \".border-red\", \"props\": \"border: 2px dashed red;\"},\n", + " {\"selector\": \".border-green\", \"props\": \"border: 2px dashed green;\"},\n", + " {\"selector\": \"td:hover\", \"props\": \"background-color: #ffffb3;\"},\n", + " ]\n", + " )\n", + " .set_td_classes(\n", + " pd.DataFrame(\n", + " [\n", + " [\"true border-green\", \"false\", \"true\", \"false border-red\", \"\", \"\"],\n", + " [\"false\", \"true\", \"false\", \"true\", \"\", \"\"],\n", + " ],\n", + " index=df.index,\n", + " columns=df.columns,\n", + " )\n", + " )\n", + " .set_caption(\"Confusion matrix for multiple cancer prediction models.\")\n", + " .set_tooltips(\n", + " pd.DataFrame(\n", + " [\n", + " [\n", + " \"This model has a very strong true positive rate\",\n", + " \"\",\n", + " \"\",\n", + " \"This model's total number of false negatives is too high\",\n", + " \"\",\n", + " \"\",\n", + " ],\n", + " [\"\", \"\", \"\", \"\", \"\", \"\"],\n", + " ],\n", + " index=df.index,\n", + " columns=df.columns,\n", + " ),\n", + " css_class=\"pd-tt\",\n", + " props=\"visibility: hidden; \"\n", + " \"position: absolute; z-index: 1; \"\n", + " \"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", + " )\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:47.933585Z", + "iopub.status.busy": "2025-04-20T21:37:47.932121Z", + "iopub.status.idle": "2025-04-20T21:37:47.945107Z", + "shell.execute_reply": "2025-04-20T21:37:47.943776Z" + } + }, + "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": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "s" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The first step we have taken is the create the Styler object from the DataFrame and then select the range of interest by hiding unwanted columns with [.hide()][hideidx].\n", + "\n", + "[hideidx]: ../reference/api/pandas.io.formats.style.Styler.hide.rst" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:47.950090Z", + "iopub.status.busy": "2025-04-20T21:37:47.948921Z", + "iopub.status.idle": "2025-04-20T21:37:47.962609Z", + "shell.execute_reply": "2025-04-20T21:37:47.961724Z" + } + }, + "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": [ + "s = df.style.format(\"{:.0f}\").hide(\n", + " [(\"Random\", \"Tumour\"), (\"Random\", \"Non-Tumour\")], axis=\"columns\"\n", + ")\n", + "s" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:47.966756Z", + "iopub.status.busy": "2025-04-20T21:37:47.965617Z", + "iopub.status.idle": "2025-04-20T21:37:47.976220Z", + "shell.execute_reply": "2025-04-20T21:37:47.974736Z" + }, + "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_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 [.map()][map] 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 [.map_index()][mapindex]. 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.map()][dfmap].\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", + "[map]: ../reference/api/pandas.io.formats.style.Styler.map.rst\n", + "[applyindex]: ../reference/api/pandas.io.formats.style.Styler.apply_index.rst\n", + "[mapindex]: ../reference/api/pandas.io.formats.style.Styler.map_index.rst\n", + "[dfapply]: ../reference/api/pandas.DataFrame.apply.rst\n", + "[dfmap]: ../reference/api/pandas.DataFrame.map.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": 12, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:47.980626Z", + "iopub.status.busy": "2025-04-20T21:37:47.979594Z", + "iopub.status.idle": "2025-04-20T21:37:47.989822Z", + "shell.execute_reply": "2025-04-20T21:37:47.988459Z" + } + }, + "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": [ + "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": 13, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:47.994262Z", + "iopub.status.busy": "2025-04-20T21:37:47.993038Z", + "iopub.status.idle": "2025-04-20T21:37:48.004811Z", + "shell.execute_reply": "2025-04-20T21:37:48.003802Z" + }, + "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_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": 14, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:48.008684Z", + "iopub.status.busy": "2025-04-20T21:37:48.008000Z", + "iopub.status.idle": "2025-04-20T21:37:48.020238Z", + "shell.execute_reply": "2025-04-20T21:37:48.018277Z" + } + }, + "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", + " [\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", + " ],\n", + " overwrite=False,\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:48.024402Z", + "iopub.status.busy": "2025-04-20T21:37:48.024089Z", + "iopub.status.idle": "2025-04-20T21:37:48.034816Z", + "shell.execute_reply": "2025-04-20T21:37:48.033312Z" + }, + "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(\"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": 16, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:48.040477Z", + "iopub.status.busy": "2025-04-20T21:37:48.039195Z", + "iopub.status.idle": "2025-04-20T21:37:48.054348Z", + "shell.execute_reply": "2025-04-20T21:37:48.052625Z" + } + }, + "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": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "s.set_table_styles(\n", + " {\n", + " (\"Regression\", \"Tumour\"): [\n", + " {\"selector\": \"th\", \"props\": \"border-left: 1px solid white\"},\n", + " {\"selector\": \"td\", \"props\": \"border-left: 1px solid #000066\"},\n", + " ]\n", + " },\n", + " overwrite=False,\n", + " axis=0,\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:48.058219Z", + "iopub.status.busy": "2025-04-20T21:37:48.057542Z", + "iopub.status.idle": "2025-04-20T21:37:48.066712Z", + "shell.execute_reply": "2025-04-20T21:37:48.065756Z" + }, + "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": 17, + "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": 18, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:48.072017Z", + "iopub.status.busy": "2025-04-20T21:37:48.070958Z", + "iopub.status.idle": "2025-04-20T21:37:48.081091Z", + "shell.execute_reply": "2025-04-20T21:37:48.079644Z" + } + }, + "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-and-Captions).\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": 19, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:48.084702Z", + "iopub.status.busy": "2025-04-20T21:37:48.084067Z", + "iopub.status.idle": "2025-04-20T21:37:48.099242Z", + "shell.execute_reply": "2025-04-20T21:37:48.097998Z" + } + }, + "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": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "s.set_table_styles(\n", + " [ # create internal CSS classes\n", + " {\"selector\": \".true\", \"props\": \"background-color: #e6ffe6;\"},\n", + " {\"selector\": \".false\", \"props\": \"background-color: #ffe6e6;\"},\n", + " ],\n", + " overwrite=False,\n", + ")\n", + "cell_color = pd.DataFrame(\n", + " [[\"true \", \"false \", \"true \", \"false \"], [\"false \", \"true \", \"false \", \"true \"]],\n", + " index=df.index,\n", + " columns=df.columns[:4],\n", + ")\n", + "s.set_td_classes(cell_color)" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:48.103949Z", + "iopub.status.busy": "2025-04-20T21:37:48.102707Z", + "iopub.status.idle": "2025-04-20T21:37:48.114681Z", + "shell.execute_reply": "2025-04-20T21:37:48.112963Z" + }, + "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": 20, + "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", + "- [.map()][map] (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", + "[map]: ../reference/api/pandas.io.formats.style.Styler.map.rst" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:48.119576Z", + "iopub.status.busy": "2025-04-20T21:37:48.118757Z", + "iopub.status.idle": "2025-04-20T21:37:48.131833Z", + "shell.execute_reply": "2025-04-20T21:37:48.130266Z" + } + }, + "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
00.125730-0.1321050.6404230.104900
1-0.5356690.3615951.3040000.947081
2-0.703735-1.265421-0.6232740.041326
3-2.325031-0.218792-1.245911-0.732267
4-0.544259-0.3163000.4116311.042513
5-0.1285351.366463-0.6651950.351510
60.9034700.094012-0.743499-0.921725
7-0.4577260.220195-1.009618-0.209176
8-0.1592250.5408460.2146590.355373
9-0.653829-0.1296140.7839751.493431
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df2 = pd.DataFrame(\n", + " np.random.default_rng(0).standard_normal((10, 4)), columns=[\"A\", \"B\", \"C\", \"D\"]\n", + ")\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 ``map``." + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:48.136187Z", + "iopub.status.busy": "2025-04-20T21:37:48.135780Z", + "iopub.status.idle": "2025-04-20T21:37:48.151532Z", + "shell.execute_reply": "2025-04-20T21:37:48.149405Z" + } + }, + "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
00.125730-0.1321050.6404230.104900
1-0.5356690.3615951.3040000.947081
2-0.703735-1.265421-0.6232740.041326
3-2.325031-0.218792-1.245911-0.732267
4-0.544259-0.3163000.4116311.042513
5-0.1285351.366463-0.6651950.351510
60.9034700.094012-0.743499-0.921725
7-0.4577260.220195-1.009618-0.209176
8-0.1592250.5408460.2146590.355373
9-0.653829-0.1296140.7839751.493431
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def style_negative(v, props=\"\"):\n", + " return props if v < 0 else None\n", + "\n", + "\n", + "s2 = df2.style.map(style_negative, props=\"color:red;\").map(\n", + " lambda v: \"opacity: 20%;\" if (v < 0.3) and (v > -0.3) else None\n", + ")\n", + "s2" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:48.156097Z", + "iopub.status.busy": "2025-04-20T21:37:48.155759Z", + "iopub.status.idle": "2025-04-20T21:37:48.169810Z", + "shell.execute_reply": "2025-04-20T21:37:48.167772Z" + }, + "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
00.125730-0.1321050.6404230.104900
1-0.5356690.3615951.3040000.947081
2-0.703735-1.265421-0.6232740.041326
3-2.325031-0.218792-1.245911-0.732267
4-0.544259-0.3163000.4116311.042513
5-0.1285351.366463-0.6651950.351510
60.9034700.094012-0.743499-0.921725
7-0.4577260.220195-1.009618-0.209176
8-0.1592250.5408460.2146590.355373
9-0.653829-0.1296140.7839751.493431
\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_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": 24, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:48.174709Z", + "iopub.status.busy": "2025-04-20T21:37:48.174318Z", + "iopub.status.idle": "2025-04-20T21:37:48.191142Z", + "shell.execute_reply": "2025-04-20T21:37:48.188986Z" + } + }, + "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
00.125730-0.1321050.6404230.104900
1-0.5356690.3615951.3040000.947081
2-0.703735-1.265421-0.6232740.041326
3-2.325031-0.218792-1.245911-0.732267
4-0.544259-0.3163000.4116311.042513
5-0.1285351.366463-0.6651950.351510
60.9034700.094012-0.743499-0.921725
7-0.4577260.220195-1.009618-0.209176
8-0.1592250.5408460.2146590.355373
9-0.653829-0.1296140.7839751.493431
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def highlight_max(s, props=\"\"):\n", + " return np.where(s == np.nanmax(s.values), props, \"\")\n", + "\n", + "\n", + "s2.apply(highlight_max, props=\"color:white;background-color:darkblue\", axis=0)" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:48.196043Z", + "iopub.status.busy": "2025-04-20T21:37:48.195314Z", + "iopub.status.idle": "2025-04-20T21:37:48.209905Z", + "shell.execute_reply": "2025-04-20T21:37:48.208110Z" + }, + "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
00.125730-0.1321050.6404230.104900
1-0.5356690.3615951.3040000.947081
2-0.703735-1.265421-0.6232740.041326
3-2.325031-0.218792-1.245911-0.732267
4-0.544259-0.3163000.4116311.042513
5-0.1285351.366463-0.6651950.351510
60.9034700.094012-0.743499-0.921725
7-0.4577260.220195-1.009618-0.209176
8-0.1592250.5408460.2146590.355373
9-0.653829-0.1296140.7839751.493431
\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\")" + ] + }, + { + "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": 26, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:48.214140Z", + "iopub.status.busy": "2025-04-20T21:37:48.213441Z", + "iopub.status.idle": "2025-04-20T21:37:48.232603Z", + "shell.execute_reply": "2025-04-20T21:37:48.231196Z" + } + }, + "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
00.125730-0.1321050.6404230.104900
1-0.5356690.3615951.3040000.947081
2-0.703735-1.265421-0.6232740.041326
3-2.325031-0.218792-1.245911-0.732267
4-0.544259-0.3163000.4116311.042513
5-0.1285351.366463-0.6651950.351510
60.9034700.094012-0.743499-0.921725
7-0.4577260.220195-1.009618-0.209176
8-0.1592250.5408460.2146590.355373
9-0.653829-0.1296140.7839751.493431
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 26, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "s2.apply(highlight_max, props=\"color:white;background-color:pink;\", axis=1).apply(\n", + " highlight_max, props=\"color:white;background-color:purple\", axis=None\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:48.236000Z", + "iopub.status.busy": "2025-04-20T21:37:48.235655Z", + "iopub.status.idle": "2025-04-20T21:37:48.255182Z", + "shell.execute_reply": "2025-04-20T21:37:48.253931Z" + }, + "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
00.125730-0.1321050.6404230.104900
1-0.5356690.3615951.3040000.947081
2-0.703735-1.265421-0.6232740.041326
3-2.325031-0.218792-1.245911-0.732267
4-0.544259-0.3163000.4116311.042513
5-0.1285351.366463-0.6651950.351510
60.9034700.094012-0.743499-0.921725
7-0.4577260.220195-1.009618-0.209176
8-0.1592250.5408460.2146590.355373
9-0.653829-0.1296140.7839751.493431
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 27, + "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", + "- [.map_index()][mapindex] (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", + "[mapindex]: ../reference/api/pandas.io.formats.style.Styler.map_index.rst" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:48.260700Z", + "iopub.status.busy": "2025-04-20T21:37:48.259395Z", + "iopub.status.idle": "2025-04-20T21:37:48.282124Z", + "shell.execute_reply": "2025-04-20T21:37:48.280251Z" + } + }, + "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
00.125730-0.1321050.6404230.104900
1-0.5356690.3615951.3040000.947081
2-0.703735-1.265421-0.6232740.041326
3-2.325031-0.218792-1.245911-0.732267
4-0.544259-0.3163000.4116311.042513
5-0.1285351.366463-0.6651950.351510
60.9034700.094012-0.743499-0.921725
7-0.4577260.220195-1.009618-0.209176
8-0.1592250.5408460.2146590.355373
9-0.653829-0.1296140.7839751.493431
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "s2.map_index(lambda v: \"color:pink;\" if v > 4 else \"color:darkblue;\", axis=0)\n", + "s2.apply_index(\n", + " lambda s: np.where(s.isin([\"A\", \"B\"]), \"color:pink;\", \"color:darkblue;\"), axis=1\n", + ")" + ] + }, + { + "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": 29, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:48.286850Z", + "iopub.status.busy": "2025-04-20T21:37:48.285827Z", + "iopub.status.idle": "2025-04-20T21:37:48.298003Z", + "shell.execute_reply": "2025-04-20T21:37:48.296140Z" + } + }, + "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": [ + "s.set_caption(\n", + " \"Confusion matrix for multiple cancer prediction models.\"\n", + ").set_table_styles(\n", + " [{\"selector\": \"caption\", \"props\": \"caption-side: bottom; font-size:1.25em;\"}],\n", + " overwrite=False,\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:48.303458Z", + "iopub.status.busy": "2025-04-20T21:37:48.301921Z", + "iopub.status.idle": "2025-04-20T21:37:48.312417Z", + "shell.execute_reply": "2025-04-20T21:37:48.311147Z" + }, + "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_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": 31, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:48.316219Z", + "iopub.status.busy": "2025-04-20T21:37:48.315895Z", + "iopub.status.idle": "2025-04-20T21:37:48.330222Z", + "shell.execute_reply": "2025-04-20T21:37:48.328889Z" + } + }, + "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": [ + "tt = pd.DataFrame(\n", + " [\n", + " [\n", + " \"This model has a very strong true positive rate\",\n", + " \"This model's total number of false negatives is too high\",\n", + " ]\n", + " ],\n", + " index=[\"Tumour (Positive)\"],\n", + " columns=df.columns[[0, 3]],\n", + ")\n", + "s.set_tooltips(\n", + " tt,\n", + " props=\"visibility: hidden; position: absolute; z-index: 1; \"\n", + " \"border: 1px solid #000066;\"\n", + " \"background-color: white; color: #000066; font-size: 0.8em;\"\n", + " \"transform: translate(0px, -24px); padding: 0.6em; \"\n", + " \"border-radius: 0.5em;\",\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:48.334462Z", + "iopub.status.busy": "2025-04-20T21:37:48.334187Z", + "iopub.status.idle": "2025-04-20T21:37:48.349180Z", + "shell.execute_reply": "2025-04-20T21:37:48.347879Z" + }, + "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_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": 33, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:48.354604Z", + "iopub.status.busy": "2025-04-20T21:37:48.353176Z", + "iopub.status.idle": "2025-04-20T21:37:48.371701Z", + "shell.execute_reply": "2025-04-20T21:37:48.370819Z" + } + }, + "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": 33, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "s.set_table_styles(\n", + " [ # create internal CSS classes\n", + " {\"selector\": \".border-red\", \"props\": \"border: 2px dashed red;\"},\n", + " {\"selector\": \".border-green\", \"props\": \"border: 2px dashed green;\"},\n", + " ],\n", + " overwrite=False,\n", + ")\n", + "cell_border = pd.DataFrame(\n", + " [[\"border-green \", \" \", \" \", \"border-red \"], [\" \", \" \", \" \", \" \"]],\n", + " index=df.index,\n", + " columns=df.columns[:4],\n", + ")\n", + "s.set_td_classes(cell_color + cell_border)" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:48.374593Z", + "iopub.status.busy": "2025-04-20T21:37:48.374346Z", + "iopub.status.idle": "2025-04-20T21:37:48.387748Z", + "shell.execute_reply": "2025-04-20T21:37:48.386775Z" + }, + "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": 34, + "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.map` 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": 35, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:48.393436Z", + "iopub.status.busy": "2025-04-20T21:37:48.392317Z", + "iopub.status.idle": "2025-04-20T21:37:48.410407Z", + "shell.execute_reply": "2025-04-20T21:37:48.408815Z" + } + }, + "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
Ar11.0164880.2639000.466660-0.671318
r20.9207880.702660-0.8344680.993752
Br1-0.810651-0.097565-0.5410681.465816
r2-0.2642301.6739610.246209-0.434415
\n", + "
" + ], + "text/plain": [ + " c1 c2 c3 c4\n", + "A r1 1.016488 0.263900 0.466660 -0.671318\n", + " r2 0.920788 0.702660 -0.834468 0.993752\n", + "B r1 -0.810651 -0.097565 -0.541068 1.465816\n", + " r2 -0.264230 1.673961 0.246209 -0.434415" + ] + }, + "execution_count": 35, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df3 = pd.DataFrame(\n", + " np.random.default_rng().standard_normal((4, 4)),\n", + " pd.MultiIndex.from_product([[\"A\", \"B\"], [\"r1\", \"r2\"]]),\n", + " columns=[\"c1\", \"c2\", \"c3\", \"c4\"],\n", + ")\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": 36, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:48.415949Z", + "iopub.status.busy": "2025-04-20T21:37:48.414228Z", + "iopub.status.idle": "2025-04-20T21:37:48.429975Z", + "shell.execute_reply": "2025-04-20T21:37:48.429058Z" + } + }, + "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
Ar11.0164880.2639000.466660-0.671318
r20.9207880.702660-0.8344680.993752
Br1-0.810651-0.097565-0.5410681.465816
r2-0.2642301.6739610.246209-0.434415
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 36, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "slice_ = [\"c3\", \"c4\"]\n", + "df3.style.apply(\n", + " 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": 37, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:48.433910Z", + "iopub.status.busy": "2025-04-20T21:37:48.432555Z", + "iopub.status.idle": "2025-04-20T21:37:48.448001Z", + "shell.execute_reply": "2025-04-20T21:37:48.446570Z" + } + }, + "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
Ar11.0164880.2639000.466660-0.671318
r20.9207880.702660-0.8344680.993752
Br1-0.810651-0.097565-0.5410681.465816
r2-0.2642301.6739610.246209-0.434415
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 37, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "idx = pd.IndexSlice\n", + "slice_ = idx[idx[:, \"r1\"], idx[\"c2\":\"c4\"]]\n", + "df3.style.apply(\n", + " 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": 38, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:48.451310Z", + "iopub.status.busy": "2025-04-20T21:37:48.450877Z", + "iopub.status.idle": "2025-04-20T21:37:48.464498Z", + "shell.execute_reply": "2025-04-20T21:37:48.463084Z" + } + }, + "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
Ar11.0164880.2639000.466660-0.671318
r20.9207880.702660-0.8344680.993752
Br1-0.810651-0.097565-0.5410681.465816
r2-0.2642301.6739610.246209-0.434415
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 38, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "slice_ = idx[idx[:, \"r2\"], :]\n", + "df3.style.apply(\n", + " 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": 39, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:48.467185Z", + "iopub.status.busy": "2025-04-20T21:37:48.466930Z", + "iopub.status.idle": "2025-04-20T21:37:48.480322Z", + "shell.execute_reply": "2025-04-20T21:37:48.479337Z" + } + }, + "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
Ar11.0164880.2639000.466660-0.671318
r20.9207880.702660-0.8344680.993752
Br1-0.810651-0.097565-0.5410681.465816
r2-0.2642301.6739610.246209-0.434415
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 39, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "slice_ = idx[idx[(df3[\"c1\"] + df3[\"c3\"]) < -2.0], [\"c2\", \"c4\"]]\n", + "df3.style.apply(\n", + " 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": 40, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:48.484641Z", + "iopub.status.busy": "2025-04-20T21:37:48.484325Z", + "iopub.status.idle": "2025-04-20T21:37:48.490936Z", + "shell.execute_reply": "2025-04-20T21:37:48.489403Z" + } + }, + "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": 41, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:48.496410Z", + "iopub.status.busy": "2025-04-20T21:37:48.495357Z", + "iopub.status.idle": "2025-04-20T21:37:48.501801Z", + "shell.execute_reply": "2025-04-20T21:37:48.499722Z" + } + }, + "outputs": [], + "source": [ + "from pandas.io.formats.style import Styler\n", + "\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": 42, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:48.507304Z", + "iopub.status.busy": "2025-04-20T21:37:48.505768Z", + "iopub.status.idle": "2025-04-20T21:37:48.518470Z", + "shell.execute_reply": "2025-04-20T21:37:48.516337Z" + } + }, + "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": 42, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "props = 'font-family: \"Times New Roman\", Times, serif; color: #e83e8c; font-size:1.3em;'\n", + "df4.style.map(lambda x: props, subset=[1])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "
\n", + "\n", + "This is better:\n", + "\n", + "
" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:48.522946Z", + "iopub.status.busy": "2025-04-20T21:37:48.522403Z", + "iopub.status.idle": "2025-04-20T21:37:48.531786Z", + "shell.execute_reply": "2025-04-20T21:37:48.530318Z" + } + }, + "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": 43, + "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": 44, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:48.535881Z", + "iopub.status.busy": "2025-04-20T21:37:48.534962Z", + "iopub.status.idle": "2025-04-20T21:37:48.551263Z", + "shell.execute_reply": "2025-04-20T21:37:48.549545Z" + } + }, + "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
00.125730-0.1321050.6404230.104900
1-0.5356690.3615951.3040000.947081
2-0.703735-1.265421-0.6232740.041326
3-2.325031-0.218792-1.245911-0.732267
4-0.544259-0.3163000.4116311.042513
5-0.1285351.366463-0.6651950.351510
60.9034700.094012-0.743499-0.921725
7-0.4577260.220195-1.009618-0.209176
8-0.1592250.5408460.2146590.355373
9-0.653829-0.1296140.7839751.493431
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 44, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df2.style.apply(\n", + " highlight_max, props=\"color:white;background-color:darkblue;\", axis=0\n", + ").apply(highlight_max, props=\"color:white;background-color:pink;\", axis=1).apply(\n", + " highlight_max, props=\"color:white;background-color:purple\", axis=None\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "
\n", + "\n", + "This is better:\n", + "\n", + "
" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:48.555876Z", + "iopub.status.busy": "2025-04-20T21:37:48.555466Z", + "iopub.status.idle": "2025-04-20T21:37:48.572014Z", + "shell.execute_reply": "2025-04-20T21:37:48.570268Z" + } + }, + "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
00.125730-0.1321050.6404230.104900
1-0.5356690.3615951.3040000.947081
2-0.703735-1.265421-0.6232740.041326
3-2.325031-0.218792-1.245911-0.732267
4-0.544259-0.3163000.4116311.042513
5-0.1285351.366463-0.6651950.351510
60.9034700.094012-0.743499-0.921725
7-0.4577260.220195-1.009618-0.209176
8-0.1592250.5408460.2146590.355373
9-0.653829-0.1296140.7839751.493431
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 45, + "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(\n", + " df2.apply(highlight_max, props=\"cls-2 \", axis=1, result_type=\"expand\").values\n", + ")\n", + "cls3 = build(highlight_max(df2, props=\"cls-3 \"))\n", + "df2.style.set_table_styles(\n", + " [\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", + " ]\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": 46, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:48.575948Z", + "iopub.status.busy": "2025-04-20T21:37:48.575666Z", + "iopub.status.idle": "2025-04-20T21:37:48.584758Z", + "shell.execute_reply": "2025-04-20T21:37:48.583118Z" + } + }, + "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(\n", + " [\n", + " {\"selector\": \"td\", \"props\": props},\n", + " {\"selector\": \".c1\", \"props\": \"color:green;\"},\n", + " {\"selector\": \".l0\", \"props\": \"color:blue;\"},\n", + " ],\n", + " css_class_names=my_css,\n", + ")\n", + "print(html.to_html())" + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:48.587443Z", + "iopub.status.busy": "2025-04-20T21:37:48.587198Z", + "iopub.status.idle": "2025-04-20T21:37:48.596659Z", + "shell.execute_reply": "2025-04-20T21:37:48.595083Z" + } + }, + "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": 47, + "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 extremities 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": 48, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:48.601333Z", + "iopub.status.busy": "2025-04-20T21:37:48.601076Z", + "iopub.status.idle": "2025-04-20T21:37:48.612330Z", + "shell.execute_reply": "2025-04-20T21:37:48.610623Z" + } + }, + "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
00.125730-0.132105nan0.104900
1-0.5356690.3615951.3040000.947081
2-0.703735-1.265421-0.6232740.041326
3-2.325031-0.218792-1.245911-0.732267
4-0.544259-0.3163000.411631nan
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 48, + "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": 49, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:48.616743Z", + "iopub.status.busy": "2025-04-20T21:37:48.616412Z", + "iopub.status.idle": "2025-04-20T21:37:48.632014Z", + "shell.execute_reply": "2025-04-20T21:37:48.630820Z" + } + }, + "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
00.125730-0.132105nan0.104900
1-0.5356690.3615951.3040000.947081
2-0.703735-1.265421-0.6232740.041326
3-2.325031-0.218792-1.245911-0.732267
4-0.544259-0.3163000.411631nan
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 49, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df2.loc[:4].style.highlight_max(\n", + " axis=1, props=(\"color:white; font-weight:bold; background-color:darkblue;\")\n", + ")" + ] + }, + { + "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": 50, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:48.637745Z", + "iopub.status.busy": "2025-04-20T21:37:48.636454Z", + "iopub.status.idle": "2025-04-20T21:37:48.654408Z", + "shell.execute_reply": "2025-04-20T21:37:48.652815Z" + } + }, + "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
00.125730-0.132105nan0.104900
1-0.5356690.3615951.3040000.947081
2-0.703735-1.265421-0.6232740.041326
3-2.325031-0.218792-1.245911-0.732267
4-0.544259-0.3163000.411631nan
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 50, + "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(\n", + " left=left, right=1.5, axis=1, props=\"color:white; background-color:purple;\"\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Highlight Quantile\n", + "Useful for detecting the highest or lowest percentile values" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:48.658672Z", + "iopub.status.busy": "2025-04-20T21:37:48.658406Z", + "iopub.status.idle": "2025-04-20T21:37:48.673324Z", + "shell.execute_reply": "2025-04-20T21:37:48.671997Z" + } + }, + "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
00.125730-0.132105nan0.104900
1-0.5356690.3615951.3040000.947081
2-0.703735-1.265421-0.6232740.041326
3-2.325031-0.218792-1.245911-0.732267
4-0.544259-0.3163000.411631nan
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 51, + "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](https://seaborn.pydata.org/) to get a nice colormap." + ] + }, + { + "cell_type": "code", + "execution_count": 52, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:48.677975Z", + "iopub.status.busy": "2025-04-20T21:37:48.677717Z", + "iopub.status.idle": "2025-04-20T21:37:49.926657Z", + "shell.execute_reply": "2025-04-20T21:37:49.924787Z" + } + }, + "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
00.125730-0.132105nan0.104900
1-0.5356690.3615951.3040000.947081
2-0.703735-1.265421-0.6232740.041326
3-2.325031-0.218792-1.245911-0.732267
4-0.544259-0.3163000.411631nan
5-0.1285351.366463-0.6651950.351510
60.9034700.094012-0.743499-0.921725
7-0.4577260.220195-1.009618-0.209176
8-0.1592250.5408460.2146590.355373
9-0.653829-0.1296140.7839751.493431
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 52, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import seaborn as sns\n", + "\n", + "cm = sns.light_palette(\"green\", as_cmap=True)\n", + "\n", + "df2.style.background_gradient(cmap=cm)" + ] + }, + { + "cell_type": "code", + "execution_count": 53, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:49.930481Z", + "iopub.status.busy": "2025-04-20T21:37:49.929912Z", + "iopub.status.idle": "2025-04-20T21:37:49.948112Z", + "shell.execute_reply": "2025-04-20T21:37:49.946542Z" + } + }, + "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
00.125730-0.132105nan0.104900
1-0.5356690.3615951.3040000.947081
2-0.703735-1.265421-0.6232740.041326
3-2.325031-0.218792-1.245911-0.732267
4-0.544259-0.3163000.411631nan
5-0.1285351.366463-0.6651950.351510
60.9034700.094012-0.743499-0.921725
7-0.4577260.220195-1.009618-0.209176
8-0.1592250.5408460.2146590.355373
9-0.653829-0.1296140.7839751.493431
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 53, + "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 `.map` where the function returns the same properties for all cells." + ] + }, + { + "cell_type": "code", + "execution_count": 54, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:49.951697Z", + "iopub.status.busy": "2025-04-20T21:37:49.951391Z", + "iopub.status.idle": "2025-04-20T21:37:49.962094Z", + "shell.execute_reply": "2025-04-20T21:37:49.960631Z" + } + }, + "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
00.125730-0.132105nan0.104900
1-0.5356690.3615951.3040000.947081
2-0.703735-1.265421-0.6232740.041326
3-2.325031-0.218792-1.245911-0.732267
4-0.544259-0.3163000.411631nan
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 54, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df2.loc[:4].style.set_properties(\n", + " **{\"background-color\": \"black\", \"color\": \"lawngreen\", \"border-color\": \"white\"}\n", + ")" + ] + }, + { + "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": 55, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:49.966681Z", + "iopub.status.busy": "2025-04-20T21:37:49.965771Z", + "iopub.status.idle": "2025-04-20T21:37:49.978345Z", + "shell.execute_reply": "2025-04-20T21:37:49.977128Z" + } + }, + "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
00.125730-0.132105nan0.104900
1-0.5356690.3615951.3040000.947081
2-0.703735-1.265421-0.6232740.041326
3-2.325031-0.218792-1.245911-0.732267
4-0.544259-0.3163000.411631nan
5-0.1285351.366463-0.6651950.351510
60.9034700.094012-0.743499-0.921725
7-0.4577260.220195-1.009618-0.209176
8-0.1592250.5408460.2146590.355373
9-0.653829-0.1296140.7839751.493431
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 55, + "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": 56, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:49.981305Z", + "iopub.status.busy": "2025-04-20T21:37:49.981035Z", + "iopub.status.idle": "2025-04-20T21:37:50.004191Z", + "shell.execute_reply": "2025-04-20T21:37:50.003155Z" + } + }, + "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
00.126-0.1320.105
1-0.5360.3621.3040.947
2-0.704-1.265-0.6230.041
3-2.325-0.219-1.246-0.732
4-0.544-0.3160.412
5-0.1291.366-0.6650.352
60.9030.094-0.743-0.922
7-0.4580.220-1.010-0.209
8-0.1590.5410.2150.355
9-0.654-0.1300.7841.493
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 56, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df2.style.format(\"{:.3f}\", na_rep=\"\").bar(\n", + " align=0,\n", + " vmin=-2.5,\n", + " vmax=2.5,\n", + " cmap=\"bwr\",\n", + " height=50,\n", + " width=60,\n", + " 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": 57, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:50.009313Z", + "iopub.status.busy": "2025-04-20T21:37:50.007615Z", + "iopub.status.idle": "2025-04-20T21:37:50.076290Z", + "shell.execute_reply": "2025-04-20T21:37:50.075279Z" + }, + "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(\n", + " s.to_frame()\n", + " .style.hide(axis=\"index\")\n", + " .bar(align=align, color=[\"#d65f5f\", \"#5fba7d\"], width=100)\n", + " .to_html()\n", + " ) # testn['width']\n", + " row += \"\"\n", + " head += row\n", + "\n", + "head += \"\"\"\n", + "\n", + "
AlignAll NegativeBoth Neg and PosAll PositiveLarge Positive
{}{}
\"\"\"" + ] + }, + { + "cell_type": "code", + "execution_count": 58, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:50.081324Z", + "iopub.status.busy": "2025-04-20T21:37:50.080876Z", + "iopub.status.idle": "2025-04-20T21:37:50.090195Z", + "shell.execute_reply": "2025-04-20T21:37:50.087850Z" + } + }, + "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": 58, + "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": 59, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:50.094108Z", + "iopub.status.busy": "2025-04-20T21:37:50.093229Z", + "iopub.status.idle": "2025-04-20T21:37:50.105461Z", + "shell.execute_reply": "2025-04-20T21:37:50.104103Z" + } + }, + "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
0.125730-0.132105nan0.104900
-0.5356690.3615951.3040000.947081
-0.703735-1.265421-0.6232740.041326
-2.325031-0.218792-1.245911-0.732267
-0.544259-0.3163000.411631nan
-0.1285351.366463-0.6651950.351510
0.9034700.094012-0.743499-0.921725
-0.4577260.220195-1.009618-0.209176
-0.1592250.5408460.2146590.355373
-0.653829-0.1296140.7839751.493431
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 59, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "style1 = (\n", + " df2.style.map(style_negative, props=\"color:red;\")\n", + " .map(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", + ")\n", + "style1" + ] + }, + { + "cell_type": "code", + "execution_count": 60, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:50.108975Z", + "iopub.status.busy": "2025-04-20T21:37:50.108702Z", + "iopub.status.idle": "2025-04-20T21:37:50.120716Z", + "shell.execute_reply": "2025-04-20T21:37:50.118654Z" + } + }, + "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.0164880.2639000.466660-0.671318
0.9207880.702660-0.8344680.993752
-0.810651-0.097565-0.5410681.465816
-0.2642301.6739610.246209-0.434415
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 60, + "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": 61, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:50.124797Z", + "iopub.status.busy": "2025-04-20T21:37:50.124305Z", + "iopub.status.idle": "2025-04-20T21:37:50.177895Z", + "shell.execute_reply": "2025-04-20T21:37:50.176129Z" + } + }, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "1d84a21b3fe94876acee2d2d12fa5c6e", + "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", + "\n", + "\n", + "@widgets.interact\n", + "def f(h_neg=(0, 359, 1), h_pos=(0, 359), s=(0.0, 99.9), l_post=(0.0, 99.9)):\n", + " return df2.style.background_gradient(\n", + " cmap=sns.palettes.diverging_palette(\n", + " h_neg=h_neg, h_pos=h_pos, s=s, l=l_post, as_cmap=True\n", + " )\n", + " )" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Magnify" + ] + }, + { + "cell_type": "code", + "execution_count": 62, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:50.183669Z", + "iopub.status.busy": "2025-04-20T21:37:50.183280Z", + "iopub.status.idle": "2025-04-20T21:37:50.189148Z", + "shell.execute_reply": "2025-04-20T21:37:50.187659Z" + } + }, + "outputs": [], + "source": [ + "def magnify():\n", + " return [\n", + " {\"selector\": \"th\", \"props\": [(\"font-size\", \"4pt\")]},\n", + " {\"selector\": \"td\", \"props\": [(\"padding\", \"0em 0em\")]},\n", + " {\"selector\": \"th:hover\", \"props\": [(\"font-size\", \"12pt\")]},\n", + " {\n", + " \"selector\": \"tr:hover td:hover\",\n", + " \"props\": [(\"max-width\", \"200px\"), (\"font-size\", \"12pt\")],\n", + " },\n", + " ]" + ] + }, + { + "cell_type": "code", + "execution_count": 63, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:50.193034Z", + "iopub.status.busy": "2025-04-20T21:37:50.191992Z", + "iopub.status.idle": "2025-04-20T21:37:50.263219Z", + "shell.execute_reply": "2025-04-20T21:37:50.261636Z" + } + }, + "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.35-0.00-0.53-2.280.020.931.04-0.542.231.94-0.23-0.160.96-0.250.221.221.19-0.53-0.46-0.55-0.010.07-0.390.770.05
10.37-1.97-1.92-2.970.380.062.60-0.392.492.060.260.770.411.31-0.551.740.98-0.700.21-0.351.59-0.430.131.362.16
21.98-1.27-0.24-2.12-0.400.393.83-0.914.012.42-0.361.23-1.160.62-1.602.24-0.04-2.260.52-0.830.87-1.031.171.531.41
34.78-0.781.67-1.070.96-0.483.26-0.273.932.500.72-1.07-1.492.16-2.072.280.34-1.940.83-1.761.20-1.632.750.901.67
44.580.351.79-0.360.40-0.862.31-0.443.651.36-0.53-0.91-1.671.45-2.991.170.44-2.480.20-2.320.73-1.942.84-0.861.41
53.38-0.023.04-2.28-0.89-1.380.011.953.012.98-0.620.27-0.861.15-2.490.51-0.04-0.99-0.67-3.243.28-2.333.140.780.92
62.811.803.02-2.01-1.23-0.85-1.572.124.013.94-1.130.911.281.27-1.810.15-1.77-0.25-1.63-3.943.34-2.353.011.901.05
72.850.723.92-3.29-3.49-1.67-0.872.465.284.34-0.761.240.640.81-2.270.34-2.71-0.67-1.35-4.013.06-2.551.780.540.25
83.801.514.19-2.67-2.71-4.04-1.423.307.044.520.962.400.78-0.24-3.280.28-2.51-0.74-0.74-3.443.11-2.122.07-1.35-1.03
94.112.274.29-2.97-2.50-3.58-1.251.327.365.251.084.60-0.64-2.050.09-0.72-4.96-1.310.09-4.162.68-1.374.02-0.59-0.72
103.673.027.08-4.10-3.57-3.95-0.531.947.144.782.445.060.69-2.281.23-1.56-2.90-1.71-0.27-3.722.50-1.974.47-1.231.21
112.983.856.33-5.84-5.90-3.91-1.942.086.334.702.416.840.50-3.68-1.10-0.67-2.80-0.28-1.88-3.911.67-1.484.150.170.79
122.763.216.80-4.75-5.36-4.53-3.001.176.524.202.257.970.98-3.45-1.59-0.86-3.09-0.24-2.08-3.731.03-0.184.540.481.69
131.692.025.31-5.51-4.79-4.34-1.42-0.246.962.920.976.702.18-3.38-0.33-0.77-2.390.42-1.53-3.591.980.014.610.521.11
140.171.267.10-5.35-5.81-4.61-0.451.615.101.31-1.186.091.25-2.230.32-1.33-0.08-0.19-1.21-2.830.970.134.890.361.83
150.010.617.94-5.85-5.35-5.100.141.763.891.72-1.617.860.71-1.38-1.95-1.84-1.88-0.14-2.02-1.451.681.623.97-1.881.80
161.420.919.86-6.10-6.02-4.561.241.383.251.050.385.771.92-1.51-0.36-1.01-3.010.10-2.50-1.990.292.912.07-1.643.87
171.942.5510.78-4.77-6.87-4.381.741.632.340.060.416.212.20-3.13-0.88-1.57-2.59-0.76-2.38-3.21-0.113.622.91-2.873.98
181.274.4511.25-4.68-4.93-7.300.922.302.340.52-0.156.012.52-1.891.37-2.65-1.98-2.85-2.78-2.81-0.863.932.83-1.044.17
190.722.8910.94-3.85-2.50-7.040.772.272.831.630.946.263.07-1.992.65-4.04-0.91-2.69-2.70-2.49-0.863.162.88-0.854.54
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 63, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "cmap = sns.diverging_palette(5, 250, as_cmap=True)\n", + "bigdf = pd.DataFrame(np.random.default_rng(25).standard_normal((20, 25))).cumsum()\n", + "\n", + "bigdf.style.background_gradient(cmap, axis=1).set_properties(\n", + " **{\"max-width\": \"80px\", \"font-size\": \"1pt\"}\n", + ").set_caption(\"Hover to magnify\").format(precision=2).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": 64, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:50.267551Z", + "iopub.status.busy": "2025-04-20T21:37:50.267073Z", + "iopub.status.idle": "2025-04-20T21:37:50.312298Z", + "shell.execute_reply": "2025-04-20T21:37:50.310602Z" + } + }, + "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
00.933414-0.282291-0.8395070.270199-2.0903670.769897-0.968883-0.2316360.537111-1.909494-0.360519-0.944411-0.186881-0.837276-0.0152591.2858440.9489361.253993-0.5345290.326423-2.8967770.3610330.4374991.1227330.7995021.469951-0.734740-0.802525-0.298598-0.225470-1.233320-0.1680201.3607820.632776-0.1999590.244304-0.663837-0.329920-1.942307-1.1464060.1158630.6258280.2346750.5409480.0358232.2245500.938836-0.0366721.525023-0.2235581.2338850.327426-0.5424820.1090570.6234831.5677360.8939160.0672430.6666640.2404601.143601-0.486092-0.3049900.3167552.013697-0.2222500.0204372.2822710.8637860.2160010.273002-1.635374-1.0783501.171063-0.008887-1.3041700.838055-0.5778690.718712-0.636248-0.2279521.1273541.0819731.203035-0.193011-0.6931560.4250470.6844470.662289-0.0724071.393306-1.545424-0.241681-1.2718940.163070-0.4388141.395784-1.591593-0.0147270.660796
10.725603-0.446175-0.554295-0.6757491.0173790.442235-0.405970-0.3483771.082457-0.074922-0.7986242.0354850.842403-1.719364-3.228103-0.105915-1.155721-1.0362332.4630851.3626770.5926891.4053861.518929-1.2314050.2943000.3972630.311849-0.5074200.397933-0.512744-1.4270841.167862-1.694242-1.595561-1.273092-1.544445-0.8409942.121894-0.259109-0.964158-0.336816-1.3744320.697506-1.2633540.8649791.0970952.5609640.0233891.7900510.2526380.3087290.300689-0.453625-1.5735901.475823-0.695704-0.3287860.5487781.393397-0.6976270.810112-0.637287-0.1400020.9846740.2094162.040928-0.309756-0.394227-0.737114-0.6356450.1964740.5929840.3554890.232134-0.407957-0.3709300.5302480.310814-1.875170-0.416942-0.0146780.6353611.2202830.158401-0.659447-0.114807-0.1843050.1515592.7780650.042801-1.036085-0.7506030.5380790.730573-1.3452041.1093680.0576372.1960160.159633-1.821399
21.036970-0.185527-1.8880370.502003-2.0288920.8057410.028003-1.014240-0.1561960.8665210.4188270.694043-0.089798-1.7106370.006290-0.138095-0.595603-0.4857211.055826-1.569693-0.7355370.597198-0.545928-1.3061160.5726531.1234190.425408-1.5525930.074939-1.813531-0.0900161.5386491.561177-0.717046-0.277858-0.333381-1.107328-1.177717-0.066787-0.6676690.1286511.0141111.8607100.826238-0.4490190.086260-0.231334-0.977593-0.527110-0.6842691.760198-1.473427-0.0289001.7068320.5998830.4800270.3439761.1121810.825574-0.0374610.278632-0.317559-1.522851-0.943377-2.228256-0.8450690.3747510.728348-0.167729-3.458502-0.2648031.3793691.5764912.038645-0.777806-1.5001430.1562080.8242411.1061860.9909102.326012-0.5227050.7064460.336499-0.394194-1.249295-1.2654890.0775860.425020-0.459487-2.327618-1.142491-0.611347-0.4849280.0909100.909422-0.702867-0.2799661.655663-0.840141
3-1.1927041.0765340.782057-1.8245210.4575641.777604-0.1526960.6679891.231463-1.2304100.3704150.6807201.0789561.4428880.1072080.8292581.940165-0.805230-0.2622361.322826-0.3478611.332225-1.369306-0.288674-1.6606470.124767-0.0380051.344372-0.2488770.517759-0.879883-0.0834290.891960-1.163759-0.6700331.561321-1.6031540.011796-0.9106550.5458850.948128-0.726401-0.360781-1.594485-0.542206-0.5704970.5399240.1686400.7850690.133760-0.665044-0.5117670.212659-1.354734-0.0003821.174357-0.462563-0.1517611.404122-0.282339-0.1847840.3586932.1083291.610171-0.243159-0.5171221.610688-1.4580660.2223240.6293840.9256460.1107440.098459-1.0608540.0679240.424166-0.731665-0.062379-0.0947820.6258590.5914320.992339-3.2085400.2617721.8605310.145771-1.3176820.7940200.933137-0.6332401.621662-1.137702-0.3954810.7784530.0609751.212765-0.4865902.6239380.3651450.009640
4-0.260061-1.9295250.8918980.685865-1.126859-1.5398250.2251331.214316-0.403976-2.119291-1.650816-1.7347030.7749621.068808-1.2694180.1463801.7347260.5803921.4339680.959014-0.347133-0.3199582.190182-0.9572801.434307-1.111834-0.092777-1.9420300.1241800.372127-0.988146-1.9137670.573853-0.665523-0.136022-0.0831680.8961680.0513261.916849-0.2757440.3047900.445574-1.3366850.4032620.0781350.882961-0.143077-0.730743-1.6676510.050738-1.1983790.4485241.327462-0.192599-0.645929-0.789250-1.105719-0.529784-1.2492922.521758-0.6092651.1064981.3783731.2755940.553620-1.581488-0.553281-0.8132360.510452-0.729289-2.307447-0.9259831.8356300.925026-0.550370-1.9522350.9720191.019584-0.6663940.093999-0.551895-1.3168680.0912421.870644-1.344467-0.054343-1.6536560.6085220.067638-0.683270-2.546297-1.6878001.184572-0.5627040.106028-0.884971-0.916787-0.7027001.4761841.165514
5-0.546442-0.128428-1.0344770.190410-0.2186780.2530412.3677510.3131250.1226600.543045-0.910016-0.1477901.1277180.2607950.9001960.040428-1.5332412.000742-0.507158-0.1480670.212087-1.129610-0.0812130.125724-1.4670530.4361380.392699-1.0269190.111909-1.2655111.2752850.2406621.906304-0.583343-0.9799690.746531-0.414892-0.2601560.786566-1.101191-0.372682-1.138768-0.115706-0.157206-0.606156-0.247606-1.2021640.389861-1.2013450.465893-1.2194240.8294411.724383-0.353054-1.879566-0.3849291.603198-1.1823470.9203650.9360080.404842-0.0776150.1227350.6229580.2679430.3538040.116941-0.7948963.3094261.2287660.7386160.050454-0.335194-1.430195-0.0895892.3626821.1793741.541345-1.1109060.8002981.4901350.416982-1.338222-0.499652-1.127112-1.1380500.175785-1.4538930.6580860.4827040.8996750.3738810.5449771.5708990.4624050.1476360.529579-1.8050340.475518-0.964511
6-0.1724090.0758650.916818-1.201595-0.2412410.0461280.732977-1.3375470.8705040.529322-0.150113-0.9544870.586305-2.380417-0.373588-0.6077700.842108-0.0137121.7670141.549010-0.4489401.5173710.232585-0.1938662.097667-0.153832-0.259158-0.6613431.990756-2.185896-1.202563-0.1039300.8105651.095063-0.0787600.4027240.356190-0.881801-0.261995-1.6856280.7342900.630032-1.146135-0.1100001.4034780.2903511.3597760.7580070.3701480.2116541.6078460.1591580.0273170.931713-0.0611720.4477320.796430-0.218947-0.484742-0.4219731.9671690.0788350.025049-1.4004070.162776-1.0391130.1943870.124384-1.8267450.001667-0.032340-1.264184-0.731628-0.5444040.556928-0.3680300.1982810.882674-0.724053-0.666849-0.338479-1.3852081.2464771.994723-1.297864-0.3799010.605890-0.6837550.1908010.892700-1.396065-0.322627-0.717620-0.081059-1.1542990.6519250.744991-1.0947551.0270390.894390
7-1.2403090.060812-0.1395620.656549-1.783771-1.2571932.269816-1.9548250.3308050.018175-1.340538-0.6337660.8907831.160452-0.928827-1.368565-0.397184-1.038666-0.017660-1.3501260.8284610.810705-1.1929030.610882-0.279862-1.2961270.806237-0.502530-0.8522870.6277831.167983-1.1876550.436337-1.1583200.3231251.949082-0.0161621.862688-1.224182-0.416144-1.079143-0.753917-0.643961-0.1585560.7817561.0809660.6731600.808622-0.5027690.921215-1.532835-0.7004640.5806180.8482361.074712-1.1900950.581898-0.443056-0.9904720.080252-2.4610280.4095740.808384-0.755166-0.643230-2.0729491.0217250.3269190.0086861.3560380.6391020.3511461.0388610.8624550.130464-0.7172170.041810-0.9665931.5477800.208165-0.160508-0.0190692.2152080.7910511.0666720.099015-0.089582-0.6041910.079915-2.2459510.561909-0.2457780.6729201.5038021.218391-0.339971-0.844750-0.865614-1.5493160.804709
8-0.0733890.496869-1.2056781.104402-1.4537921.302789-0.027793-0.7405760.2762390.775585-1.794388-0.538330-1.7959560.2079193.128862-2.046417-0.493514-1.0299451.3953410.0737851.0310910.5158560.141825-0.3327731.4920431.5387850.2579730.889872-1.008730-1.264616-0.301762-0.412288-0.4446980.5502830.911171-1.4642740.477770-1.353169-1.828182-1.0530000.372315-0.6035290.061180-0.362659-0.215266-0.261971-0.677973-0.241783-1.1598491.0190830.0462310.540512-0.8129851.3040640.3623930.429606-0.7427050.7046710.9249300.463996-0.626399-3.136856-0.237800-2.1490230.0810580.106313-0.3779371.0719121.487895-2.151123-0.1493280.880549-0.029543-0.651938-1.158118-1.4984871.772929-0.987185-0.628752-0.064703-0.7614881.1131330.157554-1.422721-0.1577720.700739-0.309669-0.801673-1.0629431.2274130.556289-0.085793-0.3693510.1345060.638609-0.845113-0.4025071.1479840.9294150.929385
90.1168500.392986-0.274386-0.3727981.614244-0.6868490.0434581.3898180.3118350.3155810.272705-0.1896920.082806-1.066536-1.1460410.3717700.081602-0.3547780.606268-0.535915-0.659617-0.4555002.0402892.1864110.748949-0.614797-0.2855820.778568-1.759577-0.165615-2.0279310.637038-1.425192-0.447790-0.2761570.113751-0.2863390.452538-1.018898-0.596627-1.336861-1.8015902.171287-1.309297-0.4236170.5445400.232838-0.1355691.186326-0.834421-0.1086450.358322-0.2102250.3297821.481924-1.5407190.857420-0.1276942.002759-0.970960-1.158725-0.4086991.4462070.941116-0.4016101.0258680.0394050.865923-0.1922670.9733280.164545-1.2244091.0012370.2453020.5011980.659569-1.2731170.1322011.4137110.115983-1.377610-0.7296221.649712-0.1577740.254437-0.189893-1.441565-0.4653650.1291862.162967-0.5556001.677289-0.448096-0.1542020.4187070.305047-1.439459-1.3577830.317164-0.699140
10-1.158658-1.7439730.2237840.0926691.491315-2.457458-0.3457781.719195-1.540327-0.457224-1.131505-0.380211-0.879773-0.199030-0.5817400.202811-0.4198890.449501-0.676163-0.877908-0.1161421.416912-1.2264100.7613480.3047540.2026930.1579521.081357-1.8021361.1342270.9268072.1247721.484530-1.9102180.9108551.744038-1.3019980.145737-1.1983440.867143-0.475698-1.8848511.056515-0.6027821.3532880.165294-0.033711-0.684095-0.9282480.5341200.829598-1.0658841.879628-0.414594-0.3703391.441847-0.232169-0.714818-0.611433-0.444770-0.651806-0.7161550.0326790.013494-1.4295940.5405640.7436720.639673-1.0002911.245191-1.5737920.2347721.6660260.9332210.130559-1.6349450.0157050.194268-0.152490-0.2104151.129041-1.4081510.4471751.9563540.871419-0.983039-0.9819461.036656-0.031900-0.403880-0.1917411.0287331.1554000.969091-1.2648360.569771-1.045285-0.8906190.0710190.268648
110.4106960.694213-0.277147-0.400811-1.480740-0.279116-1.1848440.8763080.4902451.2382551.4334151.0364361.3701900.3348620.275582-0.8620840.658719-0.2854991.065048-0.849593-0.6566020.7554641.784963-0.050952-0.394195-0.597142-0.695437-0.1251910.0730560.6448290.2665021.4206762.4420090.224656-0.739702-0.8454261.195171-0.376921-0.354454-0.1020611.0195561.3012680.2963951.100656-0.4830371.495922-0.9697381.686496-0.212080-0.5385450.858359-0.791318-0.272028-0.462741-1.084659-1.2404610.446452-0.9239620.461852-0.5932630.245383-1.378398-0.0880530.0323100.524120-1.109143-1.382273-1.2084481.387560-1.177533-1.136085-0.8292490.1526200.184766-1.6634421.011176-0.681026-0.0798460.3606361.1859542.105044-0.169393-1.006526-0.225240-0.9090630.0272050.9062891.592105-0.5581680.3837680.489696-0.0463680.476991-0.159182-0.188142-0.328093-0.2305800.515206-1.2848050.080010
12-1.482771-0.7657521.6179520.334043-0.7423620.090160-0.7420341.6044230.8483130.3577100.7044840.8181111.0785000.4482960.891218-1.1231761.113797-1.172891-1.1483010.8872730.550748-0.240004-0.9201831.008433-0.1641020.0897200.0668841.227851-0.4762440.1539000.621532-1.3653840.822645-0.581228-1.383076-0.016461-0.6599581.9697380.065818-1.0790570.3264171.7864930.192987-1.3566110.5816060.132767-0.9579360.2639751.447144-0.280768-1.4023620.198101-2.0050300.271044-0.8090090.9542702.374102-0.599499-0.904689-0.656597-0.262807-0.408991-1.1101751.001403-1.117362-0.4453330.996178-1.869323-0.851450-1.326239-0.9915220.757530-0.905287-0.243481-0.348934-2.033455-0.6150950.276761-1.529502-0.667121-0.4683100.0731691.6549230.027525-1.288521-2.674414-1.1104820.695802-0.0941930.1229730.223337-0.2525150.2794990.4250600.047079-0.420032-0.368921-1.249773-0.0975500.686549
13-0.894244-0.3324730.046204-0.405297-0.8199900.292986-0.486040-0.386708-0.877119-0.1776360.024626-1.058712-1.0996890.5332161.266650-1.2466600.7123060.306512-2.735957-0.071014-0.9951070.0495781.549767-1.2963011.3906780.436896-0.584787-0.8065791.166370-0.6811300.209078-0.279131-0.3521251.615434-0.7609370.1545100.5792150.294421-0.9415490.860177-2.255255-0.9506860.815197-0.7920210.3431000.615827-1.0814351.6041640.243987-0.935304-0.7962250.1709122.0042040.6700770.100818-0.8824380.300877-0.253892-0.4858371.173660-0.9308212.7699931.2209260.2823570.7332030.6578601.4765990.849873-0.5784140.1110010.597409-0.8188930.2094430.918042-0.0254800.3278210.8662430.3674801.3690170.809067-0.3866000.7381721.1099070.149974-1.4734310.794230-0.9370180.453209-0.9666540.4086821.115644-0.372408-2.275561-0.102069-0.667017-0.3146580.5080290.670779-0.1719030.635510
140.6238520.880763-1.547759-2.158798-0.1592572.666677-0.4260620.485207-0.460878-0.840187-1.242152-0.2297950.8223690.887160-2.7213441.097931-0.5044890.7986110.468300-1.4973040.140385-0.623004-0.532707-1.3263930.358515-1.359614-0.823432-0.282064-1.0709840.775804-1.325108-0.2862920.0919112.382751-1.216101-1.220655-0.6066930.2515450.2000660.9236200.084320-0.511591-0.6363270.891451-0.4293411.842804-0.193507-0.074958-0.225739-0.457991-0.760285-0.750717-2.0804191.0586380.336812-0.2434861.7944440.7932631.2641260.0040240.380951-0.976445-1.9642410.5117350.100613-1.1153550.638604-1.4566621.0622851.622414-0.079938-0.9140730.759539-0.4317410.633745-1.025637-0.242221-0.275623-0.0908280.1496940.034730-0.7979571.7711830.0616180.5202971.034154-1.477142-0.8341420.071788-1.948337-0.882583-1.652706-0.338930-2.198115-0.2265740.075781-2.214336-1.060942-0.1524610.284741
15-0.8851330.8728080.492826-0.134433-0.6774231.706353-1.187095-0.7608221.6809210.297227-0.3021450.8224100.1683970.333490-0.7321180.291324-0.6172960.535366-1.286263-0.404460-0.6089820.7890740.7211071.0767852.2693920.362099-0.074423-1.194329-0.014150-0.016602-1.3575220.8648030.0777420.935987-0.186647-0.2376100.798131-1.014528-0.448424-0.453515-0.175128-0.538875-0.0366640.1640111.714213-0.7937762.0772981.3026671.1691490.691683-1.0814120.1156410.0777590.4250850.298821-0.1284210.4820780.8635291.820006-2.053175-0.686764-0.5312950.1409021.118639-0.7629320.583160-2.1628410.0909590.698218-1.405964-1.0701160.385016-0.646642-0.4807681.4042370.6525790.3950901.174948-0.4499131.3602280.556748-0.2243651.8328021.7982150.791683-0.147293-1.538604-0.1325341.542305-1.5242541.5950590.458568-1.0605320.6613910.408761-0.184403-0.5822301.2519890.719041-1.508928
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 64, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "bigdf = pd.DataFrame(np.random.default_rng().standard_normal((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": 65, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:50.317048Z", + "iopub.status.busy": "2025-04-20T21:37:50.315957Z", + "iopub.status.idle": "2025-04-20T21:37:50.361040Z", + "shell.execute_reply": "2025-04-20T21:37:50.359316Z" + } + }, + "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
A000.933414-0.282291-0.8395070.270199-2.0903670.769897-0.968883-0.2316360.537111-1.909494-0.360519-0.944411-0.186881-0.837276-0.0152591.2858440.9489361.253993-0.5345290.326423-2.8967770.3610330.4374991.1227330.7995021.469951-0.734740-0.802525-0.298598-0.225470-1.233320-0.1680201.3607820.632776-0.1999590.244304-0.663837-0.329920-1.942307-1.1464060.1158630.6258280.2346750.5409480.0358232.2245500.938836-0.0366721.525023-0.2235581.2338850.327426-0.5424820.1090570.6234831.5677360.8939160.0672430.6666640.2404601.143601-0.486092-0.3049900.3167552.013697-0.2222500.0204372.2822710.8637860.2160010.273002-1.635374-1.0783501.171063-0.008887-1.3041700.838055-0.5778690.718712-0.636248-0.2279521.1273541.0819731.203035-0.193011-0.6931560.4250470.6844470.662289-0.0724071.393306-1.545424-0.241681-1.2718940.163070-0.4388141.395784-1.591593-0.0147270.660796
10.725603-0.446175-0.554295-0.6757491.0173790.442235-0.405970-0.3483771.082457-0.074922-0.7986242.0354850.842403-1.719364-3.228103-0.105915-1.155721-1.0362332.4630851.3626770.5926891.4053861.518929-1.2314050.2943000.3972630.311849-0.5074200.397933-0.512744-1.4270841.167862-1.694242-1.595561-1.273092-1.544445-0.8409942.121894-0.259109-0.964158-0.336816-1.3744320.697506-1.2633540.8649791.0970952.5609640.0233891.7900510.2526380.3087290.300689-0.453625-1.5735901.475823-0.695704-0.3287860.5487781.393397-0.6976270.810112-0.637287-0.1400020.9846740.2094162.040928-0.309756-0.394227-0.737114-0.6356450.1964740.5929840.3554890.232134-0.407957-0.3709300.5302480.310814-1.875170-0.416942-0.0146780.6353611.2202830.158401-0.659447-0.114807-0.1843050.1515592.7780650.042801-1.036085-0.7506030.5380790.730573-1.3452041.1093680.0576372.1960160.159633-1.821399
21.036970-0.185527-1.8880370.502003-2.0288920.8057410.028003-1.014240-0.1561960.8665210.4188270.694043-0.089798-1.7106370.006290-0.138095-0.595603-0.4857211.055826-1.569693-0.7355370.597198-0.545928-1.3061160.5726531.1234190.425408-1.5525930.074939-1.813531-0.0900161.5386491.561177-0.717046-0.277858-0.333381-1.107328-1.177717-0.066787-0.6676690.1286511.0141111.8607100.826238-0.4490190.086260-0.231334-0.977593-0.527110-0.6842691.760198-1.473427-0.0289001.7068320.5998830.4800270.3439761.1121810.825574-0.0374610.278632-0.317559-1.522851-0.943377-2.228256-0.8450690.3747510.728348-0.167729-3.458502-0.2648031.3793691.5764912.038645-0.777806-1.5001430.1562080.8242411.1061860.9909102.326012-0.5227050.7064460.336499-0.394194-1.249295-1.2654890.0775860.425020-0.459487-2.327618-1.142491-0.611347-0.4849280.0909100.909422-0.702867-0.2799661.655663-0.840141
3-1.1927041.0765340.782057-1.8245210.4575641.777604-0.1526960.6679891.231463-1.2304100.3704150.6807201.0789561.4428880.1072080.8292581.940165-0.805230-0.2622361.322826-0.3478611.332225-1.369306-0.288674-1.6606470.124767-0.0380051.344372-0.2488770.517759-0.879883-0.0834290.891960-1.163759-0.6700331.561321-1.6031540.011796-0.9106550.5458850.948128-0.726401-0.360781-1.594485-0.542206-0.5704970.5399240.1686400.7850690.133760-0.665044-0.5117670.212659-1.354734-0.0003821.174357-0.462563-0.1517611.404122-0.282339-0.1847840.3586932.1083291.610171-0.243159-0.5171221.610688-1.4580660.2223240.6293840.9256460.1107440.098459-1.0608540.0679240.424166-0.731665-0.062379-0.0947820.6258590.5914320.992339-3.2085400.2617721.8605310.145771-1.3176820.7940200.933137-0.6332401.621662-1.137702-0.3954810.7784530.0609751.212765-0.4865902.6239380.3651450.009640
10-0.260061-1.9295250.8918980.685865-1.126859-1.5398250.2251331.214316-0.403976-2.119291-1.650816-1.7347030.7749621.068808-1.2694180.1463801.7347260.5803921.4339680.959014-0.347133-0.3199582.190182-0.9572801.434307-1.111834-0.092777-1.9420300.1241800.372127-0.988146-1.9137670.573853-0.665523-0.136022-0.0831680.8961680.0513261.916849-0.2757440.3047900.445574-1.3366850.4032620.0781350.882961-0.143077-0.730743-1.6676510.050738-1.1983790.4485241.327462-0.192599-0.645929-0.789250-1.105719-0.529784-1.2492922.521758-0.6092651.1064981.3783731.2755940.553620-1.581488-0.553281-0.8132360.510452-0.729289-2.307447-0.9259831.8356300.925026-0.550370-1.9522350.9720191.019584-0.6663940.093999-0.551895-1.3168680.0912421.870644-1.344467-0.054343-1.6536560.6085220.067638-0.683270-2.546297-1.6878001.184572-0.5627040.106028-0.884971-0.916787-0.7027001.4761841.165514
1-0.546442-0.128428-1.0344770.190410-0.2186780.2530412.3677510.3131250.1226600.543045-0.910016-0.1477901.1277180.2607950.9001960.040428-1.5332412.000742-0.507158-0.1480670.212087-1.129610-0.0812130.125724-1.4670530.4361380.392699-1.0269190.111909-1.2655111.2752850.2406621.906304-0.583343-0.9799690.746531-0.414892-0.2601560.786566-1.101191-0.372682-1.138768-0.115706-0.157206-0.606156-0.247606-1.2021640.389861-1.2013450.465893-1.2194240.8294411.724383-0.353054-1.879566-0.3849291.603198-1.1823470.9203650.9360080.404842-0.0776150.1227350.6229580.2679430.3538040.116941-0.7948963.3094261.2287660.7386160.050454-0.335194-1.430195-0.0895892.3626821.1793741.541345-1.1109060.8002981.4901350.416982-1.338222-0.499652-1.127112-1.1380500.175785-1.4538930.6580860.4827040.8996750.3738810.5449771.5708990.4624050.1476360.529579-1.8050340.475518-0.964511
2-0.1724090.0758650.916818-1.201595-0.2412410.0461280.732977-1.3375470.8705040.529322-0.150113-0.9544870.586305-2.380417-0.373588-0.6077700.842108-0.0137121.7670141.549010-0.4489401.5173710.232585-0.1938662.097667-0.153832-0.259158-0.6613431.990756-2.185896-1.202563-0.1039300.8105651.095063-0.0787600.4027240.356190-0.881801-0.261995-1.6856280.7342900.630032-1.146135-0.1100001.4034780.2903511.3597760.7580070.3701480.2116541.6078460.1591580.0273170.931713-0.0611720.4477320.796430-0.218947-0.484742-0.4219731.9671690.0788350.025049-1.4004070.162776-1.0391130.1943870.124384-1.8267450.001667-0.032340-1.264184-0.731628-0.5444040.556928-0.3680300.1982810.882674-0.724053-0.666849-0.338479-1.3852081.2464771.994723-1.297864-0.3799010.605890-0.6837550.1908010.892700-1.396065-0.322627-0.717620-0.081059-1.1542990.6519250.744991-1.0947551.0270390.894390
3-1.2403090.060812-0.1395620.656549-1.783771-1.2571932.269816-1.9548250.3308050.018175-1.340538-0.6337660.8907831.160452-0.928827-1.368565-0.397184-1.038666-0.017660-1.3501260.8284610.810705-1.1929030.610882-0.279862-1.2961270.806237-0.502530-0.8522870.6277831.167983-1.1876550.436337-1.1583200.3231251.949082-0.0161621.862688-1.224182-0.416144-1.079143-0.753917-0.643961-0.1585560.7817561.0809660.6731600.808622-0.5027690.921215-1.532835-0.7004640.5806180.8482361.074712-1.1900950.581898-0.443056-0.9904720.080252-2.4610280.4095740.808384-0.755166-0.643230-2.0729491.0217250.3269190.0086861.3560380.6391020.3511461.0388610.8624550.130464-0.7172170.041810-0.9665931.5477800.208165-0.160508-0.0190692.2152080.7910511.0666720.099015-0.089582-0.6041910.079915-2.2459510.561909-0.2457780.6729201.5038021.218391-0.339971-0.844750-0.865614-1.5493160.804709
B00-0.0733890.496869-1.2056781.104402-1.4537921.302789-0.027793-0.7405760.2762390.775585-1.794388-0.538330-1.7959560.2079193.128862-2.046417-0.493514-1.0299451.3953410.0737851.0310910.5158560.141825-0.3327731.4920431.5387850.2579730.889872-1.008730-1.264616-0.301762-0.412288-0.4446980.5502830.911171-1.4642740.477770-1.353169-1.828182-1.0530000.372315-0.6035290.061180-0.362659-0.215266-0.261971-0.677973-0.241783-1.1598491.0190830.0462310.540512-0.8129851.3040640.3623930.429606-0.7427050.7046710.9249300.463996-0.626399-3.136856-0.237800-2.1490230.0810580.106313-0.3779371.0719121.487895-2.151123-0.1493280.880549-0.029543-0.651938-1.158118-1.4984871.772929-0.987185-0.628752-0.064703-0.7614881.1131330.157554-1.422721-0.1577720.700739-0.309669-0.801673-1.0629431.2274130.556289-0.085793-0.3693510.1345060.638609-0.845113-0.4025071.1479840.9294150.929385
10.1168500.392986-0.274386-0.3727981.614244-0.6868490.0434581.3898180.3118350.3155810.272705-0.1896920.082806-1.066536-1.1460410.3717700.081602-0.3547780.606268-0.535915-0.659617-0.4555002.0402892.1864110.748949-0.614797-0.2855820.778568-1.759577-0.165615-2.0279310.637038-1.425192-0.447790-0.2761570.113751-0.2863390.452538-1.018898-0.596627-1.336861-1.8015902.171287-1.309297-0.4236170.5445400.232838-0.1355691.186326-0.834421-0.1086450.358322-0.2102250.3297821.481924-1.5407190.857420-0.1276942.002759-0.970960-1.158725-0.4086991.4462070.941116-0.4016101.0258680.0394050.865923-0.1922670.9733280.164545-1.2244091.0012370.2453020.5011980.659569-1.2731170.1322011.4137110.115983-1.377610-0.7296221.649712-0.1577740.254437-0.189893-1.441565-0.4653650.1291862.162967-0.5556001.677289-0.448096-0.1542020.4187070.305047-1.439459-1.3577830.317164-0.699140
2-1.158658-1.7439730.2237840.0926691.491315-2.457458-0.3457781.719195-1.540327-0.457224-1.131505-0.380211-0.879773-0.199030-0.5817400.202811-0.4198890.449501-0.676163-0.877908-0.1161421.416912-1.2264100.7613480.3047540.2026930.1579521.081357-1.8021361.1342270.9268072.1247721.484530-1.9102180.9108551.744038-1.3019980.145737-1.1983440.867143-0.475698-1.8848511.056515-0.6027821.3532880.165294-0.033711-0.684095-0.9282480.5341200.829598-1.0658841.879628-0.414594-0.3703391.441847-0.232169-0.714818-0.611433-0.444770-0.651806-0.7161550.0326790.013494-1.4295940.5405640.7436720.639673-1.0002911.245191-1.5737920.2347721.6660260.9332210.130559-1.6349450.0157050.194268-0.152490-0.2104151.129041-1.4081510.4471751.9563540.871419-0.983039-0.9819461.036656-0.031900-0.403880-0.1917411.0287331.1554000.969091-1.2648360.569771-1.045285-0.8906190.0710190.268648
30.4106960.694213-0.277147-0.400811-1.480740-0.279116-1.1848440.8763080.4902451.2382551.4334151.0364361.3701900.3348620.275582-0.8620840.658719-0.2854991.065048-0.849593-0.6566020.7554641.784963-0.050952-0.394195-0.597142-0.695437-0.1251910.0730560.6448290.2665021.4206762.4420090.224656-0.739702-0.8454261.195171-0.376921-0.354454-0.1020611.0195561.3012680.2963951.100656-0.4830371.495922-0.9697381.686496-0.212080-0.5385450.858359-0.791318-0.272028-0.462741-1.084659-1.2404610.446452-0.9239620.461852-0.5932630.245383-1.378398-0.0880530.0323100.524120-1.109143-1.382273-1.2084481.387560-1.177533-1.136085-0.8292490.1526200.184766-1.6634421.011176-0.681026-0.0798460.3606361.1859542.105044-0.169393-1.006526-0.225240-0.9090630.0272050.9062891.592105-0.5581680.3837680.489696-0.0463680.476991-0.159182-0.188142-0.328093-0.2305800.515206-1.2848050.080010
10-1.482771-0.7657521.6179520.334043-0.7423620.090160-0.7420341.6044230.8483130.3577100.7044840.8181111.0785000.4482960.891218-1.1231761.113797-1.172891-1.1483010.8872730.550748-0.240004-0.9201831.008433-0.1641020.0897200.0668841.227851-0.4762440.1539000.621532-1.3653840.822645-0.581228-1.383076-0.016461-0.6599581.9697380.065818-1.0790570.3264171.7864930.192987-1.3566110.5816060.132767-0.9579360.2639751.447144-0.280768-1.4023620.198101-2.0050300.271044-0.8090090.9542702.374102-0.599499-0.904689-0.656597-0.262807-0.408991-1.1101751.001403-1.117362-0.4453330.996178-1.869323-0.851450-1.326239-0.9915220.757530-0.905287-0.243481-0.348934-2.033455-0.6150950.276761-1.529502-0.667121-0.4683100.0731691.6549230.027525-1.288521-2.674414-1.1104820.695802-0.0941930.1229730.223337-0.2525150.2794990.4250600.047079-0.420032-0.368921-1.249773-0.0975500.686549
1-0.894244-0.3324730.046204-0.405297-0.8199900.292986-0.486040-0.386708-0.877119-0.1776360.024626-1.058712-1.0996890.5332161.266650-1.2466600.7123060.306512-2.735957-0.071014-0.9951070.0495781.549767-1.2963011.3906780.436896-0.584787-0.8065791.166370-0.6811300.209078-0.279131-0.3521251.615434-0.7609370.1545100.5792150.294421-0.9415490.860177-2.255255-0.9506860.815197-0.7920210.3431000.615827-1.0814351.6041640.243987-0.935304-0.7962250.1709122.0042040.6700770.100818-0.8824380.300877-0.253892-0.4858371.173660-0.9308212.7699931.2209260.2823570.7332030.6578601.4765990.849873-0.5784140.1110010.597409-0.8188930.2094430.918042-0.0254800.3278210.8662430.3674801.3690170.809067-0.3866000.7381721.1099070.149974-1.4734310.794230-0.9370180.453209-0.9666540.4086821.115644-0.372408-2.275561-0.102069-0.667017-0.3146580.5080290.670779-0.1719030.635510
20.6238520.880763-1.547759-2.158798-0.1592572.666677-0.4260620.485207-0.460878-0.840187-1.242152-0.2297950.8223690.887160-2.7213441.097931-0.5044890.7986110.468300-1.4973040.140385-0.623004-0.532707-1.3263930.358515-1.359614-0.823432-0.282064-1.0709840.775804-1.325108-0.2862920.0919112.382751-1.216101-1.220655-0.6066930.2515450.2000660.9236200.084320-0.511591-0.6363270.891451-0.4293411.842804-0.193507-0.074958-0.225739-0.457991-0.760285-0.750717-2.0804191.0586380.336812-0.2434861.7944440.7932631.2641260.0040240.380951-0.976445-1.9642410.5117350.100613-1.1153550.638604-1.4566621.0622851.622414-0.079938-0.9140730.759539-0.4317410.633745-1.025637-0.242221-0.275623-0.0908280.1496940.034730-0.7979571.7711830.0616180.5202971.034154-1.477142-0.8341420.071788-1.948337-0.882583-1.652706-0.338930-2.198115-0.2265740.075781-2.214336-1.060942-0.1524610.284741
3-0.8851330.8728080.492826-0.134433-0.6774231.706353-1.187095-0.7608221.6809210.297227-0.3021450.8224100.1683970.333490-0.7321180.291324-0.6172960.535366-1.286263-0.404460-0.6089820.7890740.7211071.0767852.2693920.362099-0.074423-1.194329-0.014150-0.016602-1.3575220.8648030.0777420.935987-0.186647-0.2376100.798131-1.014528-0.448424-0.453515-0.175128-0.538875-0.0366640.1640111.714213-0.7937762.0772981.3026671.1691490.691683-1.0814120.1156410.0777590.4250850.298821-0.1284210.4820780.8635291.820006-2.053175-0.686764-0.5312950.1409021.118639-0.7629320.583160-2.1628410.0909590.698218-1.405964-1.0701160.385016-0.646642-0.4807681.4042370.6525790.3950901.174948-0.4499131.3602280.556748-0.2243651.8328021.7982150.791683-0.147293-1.538604-0.1325341.542305-1.5242541.5950590.458568-1.0605320.6613910.408761-0.184403-0.5822301.2519890.719041-1.508928
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 65, + "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.\n", + "\n", + "Note that if you're using `Styler` on untrusted, user-provided input to serve HTML then you should escape the input to prevent security vulnerabilities. See the Jinja2 documentation for more." + ] + }, + { + "cell_type": "code", + "execution_count": 66, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:50.364739Z", + "iopub.status.busy": "2025-04-20T21:37:50.364493Z", + "iopub.status.idle": "2025-04-20T21:37:50.373956Z", + "shell.execute_reply": "2025-04-20T21:37:50.372247Z" + } + }, + "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": 66, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df4 = pd.DataFrame([[\"
\", '\"&other\"', \"\"]])\n", + "df4.style" + ] + }, + { + "cell_type": "code", + "execution_count": 67, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:50.376720Z", + "iopub.status.busy": "2025-04-20T21:37:50.376474Z", + "iopub.status.idle": "2025-04-20T21:37:50.385440Z", + "shell.execute_reply": "2025-04-20T21:37:50.383926Z" + } + }, + "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": 67, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df4.style.format(escape=\"html\")" + ] + }, + { + "cell_type": "code", + "execution_count": 68, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:50.390140Z", + "iopub.status.busy": "2025-04-20T21:37:50.389867Z", + "iopub.status.idle": "2025-04-20T21:37:50.397721Z", + "shell.execute_reply": "2025-04-20T21:37:50.396780Z" + } + }, + "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": 68, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df4.style.format(\n", + " '{}', escape=\"html\"\n", + ")" + ] + }, + { + "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.map` methods." + ] + }, + { + "cell_type": "code", + "execution_count": 69, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:50.402916Z", + "iopub.status.busy": "2025-04-20T21:37:50.401606Z", + "iopub.status.idle": "2025-04-20T21:37:50.660178Z", + "shell.execute_reply": "2025-04-20T21:37:50.658453Z" + } + }, + "outputs": [], + "source": [ + "df2.style.map(style_negative, props=\"color:red;\").highlight_max(axis=0).to_excel(\n", + " \"styled.xlsx\", engine=\"openpyxl\"\n", + ")" + ] + }, + { + "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": 70, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:50.663874Z", + "iopub.status.busy": "2025-04-20T21:37:50.663501Z", + "iopub.status.idle": "2025-04-20T21:37:50.671311Z", + "shell.execute_reply": "2025-04-20T21:37:50.670172Z" + } + }, + "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(\n", + " pd.DataFrame(\n", + " [[1, 2], [3, 4]], index=[\"i1\", \"i2\"], columns=[\"c1\", \"c2\"]\n", + " ).style.to_html()\n", + ")" + ] + }, + { + "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": 71, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:50.675693Z", + "iopub.status.busy": "2025-04-20T21:37:50.675370Z", + "iopub.status.idle": "2025-04-20T21:37:50.685060Z", + "shell.execute_reply": "2025-04-20T21:37:50.683427Z" + } + }, + "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 = pd.DataFrame([[\"text\"]])\n", + "df4.style.map(lambda x: \"color:green;\").map(lambda x: \"color:red;\")" + ] + }, + { + "cell_type": "code", + "execution_count": 72, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:50.689393Z", + "iopub.status.busy": "2025-04-20T21:37:50.688284Z", + "iopub.status.idle": "2025-04-20T21:37:50.698438Z", + "shell.execute_reply": "2025-04-20T21:37:50.696773Z" + } + }, + "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.map(lambda x: \"color:red;\").map(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": 73, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:50.703129Z", + "iopub.status.busy": "2025-04-20T21:37:50.702917Z", + "iopub.status.idle": "2025-04-20T21:37:50.712930Z", + "shell.execute_reply": "2025-04-20T21:37:50.711412Z" + } + }, + "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(\"a_\").set_table_styles(\n", + " [{\"selector\": \"td\", \"props\": \"color:red;\"}]\n", + ").map(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": 74, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:50.718757Z", + "iopub.status.busy": "2025-04-20T21:37:50.717388Z", + "iopub.status.idle": "2025-04-20T21:37:50.728384Z", + "shell.execute_reply": "2025-04-20T21:37:50.726731Z" + } + }, + "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(\"b_\").set_table_styles(\n", + " [\n", + " {\"selector\": \"td\", \"props\": \"color:red;\"},\n", + " {\"selector\": \".cls-1\", \"props\": \"color:blue;\"},\n", + " ]\n", + ").map(lambda x: \"color:green;\").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": 75, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:50.732405Z", + "iopub.status.busy": "2025-04-20T21:37:50.731368Z", + "iopub.status.idle": "2025-04-20T21:37:50.742993Z", + "shell.execute_reply": "2025-04-20T21:37:50.741369Z" + } + }, + "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": 75, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df4.style.set_uuid(\"c_\").set_table_styles(\n", + " [\n", + " {\"selector\": \"td\", \"props\": \"color:red;\"},\n", + " {\"selector\": \".cls-1\", \"props\": \"color:blue;\"},\n", + " {\"selector\": \"td.data\", \"props\": \"color:yellow;\"},\n", + " ]\n", + ").map(lambda x: \"color:green;\").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": 76, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:50.747638Z", + "iopub.status.busy": "2025-04-20T21:37:50.746606Z", + "iopub.status.idle": "2025-04-20T21:37:50.757898Z", + "shell.execute_reply": "2025-04-20T21:37:50.756650Z" + } + }, + "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": 76, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df4.style.set_uuid(\"d_\").set_table_styles(\n", + " [\n", + " {\"selector\": \"td\", \"props\": \"color:red;\"},\n", + " {\"selector\": \".cls-1\", \"props\": \"color:blue;\"},\n", + " {\"selector\": \"td.data\", \"props\": \"color:yellow;\"},\n", + " ]\n", + ").map(lambda x: \"color:green !important;\").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/community/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": 77, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:50.762631Z", + "iopub.status.busy": "2025-04-20T21:37:50.760914Z", + "iopub.status.idle": "2025-04-20T21:37:50.766851Z", + "shell.execute_reply": "2025-04-20T21:37:50.765557Z" + } + }, + "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": 78, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:50.769897Z", + "iopub.status.busy": "2025-04-20T21:37:50.769635Z", + "iopub.status.idle": "2025-04-20T21:37:50.776608Z", + "shell.execute_reply": "2025-04-20T21:37:50.775234Z" + } + }, + "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_html:\n", + " print(f_html.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": 79, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:50.780850Z", + "iopub.status.busy": "2025-04-20T21:37:50.779890Z", + "iopub.status.idle": "2025-04-20T21:37:50.788275Z", + "shell.execute_reply": "2025-04-20T21:37:50.787282Z" + } + }, + "outputs": [], + "source": [ + "class MyStyler(Styler):\n", + " env = Environment(\n", + " loader=ChoiceLoader(\n", + " [\n", + " FileSystemLoader(\"templates\"), # contains ours\n", + " Styler.loader, # the default\n", + " ]\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": 80, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:50.792237Z", + "iopub.status.busy": "2025-04-20T21:37:50.791818Z", + "iopub.status.idle": "2025-04-20T21:37:50.815863Z", + "shell.execute_reply": "2025-04-20T21:37:50.814770Z" + } + }, + "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
Ar11.0164880.2639000.466660-0.671318
r20.9207880.702660-0.8344680.993752
Br1-0.810651-0.097565-0.5410681.465816
r2-0.2642301.6739610.246209-0.434415
\n", + "\n", + "\n" + ], + "text/plain": [ + "<__main__.MyStyler at 0x7ff8c343a7b0>" + ] + }, + "execution_count": 80, + "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": 81, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:50.820402Z", + "iopub.status.busy": "2025-04-20T21:37:50.820087Z", + "iopub.status.idle": "2025-04-20T21:37:50.830769Z", + "shell.execute_reply": "2025-04-20T21:37:50.828937Z" + } + }, + "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
Ar11.0164880.2639000.466660-0.671318
r20.9207880.702660-0.8344680.993752
Br1-0.810651-0.097565-0.5410681.465816
r2-0.2642301.6739610.246209-0.434415
\n", + "\n", + "\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 81, + "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": 82, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:50.834453Z", + "iopub.status.busy": "2025-04-20T21:37:50.833578Z", + "iopub.status.idle": "2025-04-20T21:37:50.860222Z", + "shell.execute_reply": "2025-04-20T21:37:50.858799Z" + } + }, + "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
Ar11.0164880.2639000.466660-0.671318
r20.9207880.702660-0.8344680.993752
Br1-0.810651-0.097565-0.5410681.465816
r2-0.2642301.6739610.246209-0.434415
\n", + "\n", + "\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 82, + "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": 83, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:50.864091Z", + "iopub.status.busy": "2025-04-20T21:37:50.863684Z", + "iopub.status.idle": "2025-04-20T21:37:50.870101Z", + "shell.execute_reply": "2025-04-20T21:37:50.868130Z" + }, + "nbsphinx": "hidden" + }, + "outputs": [], + "source": [ + "with open(\"templates/html_style_structure.html\") as f_sty:\n", + " style_structure = f_sty.read()" + ] + }, + { + "cell_type": "code", + "execution_count": 84, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:50.874962Z", + "iopub.status.busy": "2025-04-20T21:37:50.874698Z", + "iopub.status.idle": "2025-04-20T21:37:50.880589Z", + "shell.execute_reply": "2025-04-20T21:37:50.879489Z" + } + }, + "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": 84, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "HTML(style_structure)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Table template:" + ] + }, + { + "cell_type": "code", + "execution_count": 85, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:50.885248Z", + "iopub.status.busy": "2025-04-20T21:37:50.884597Z", + "iopub.status.idle": "2025-04-20T21:37:50.890972Z", + "shell.execute_reply": "2025-04-20T21:37:50.890088Z" + }, + "nbsphinx": "hidden" + }, + "outputs": [], + "source": [ + "with open(\"templates/html_table_structure.html\") as f_table_struct:\n", + " table_structure = f_table_struct.read()" + ] + }, + { + "cell_type": "code", + "execution_count": 86, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:50.895721Z", + "iopub.status.busy": "2025-04-20T21:37:50.894906Z", + "iopub.status.idle": "2025-04-20T21:37:50.903727Z", + "shell.execute_reply": "2025-04-20T21:37:50.902379Z" + } + }, + "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": 86, + "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": 87, + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-20T21:37:50.907267Z", + "iopub.status.busy": "2025-04-20T21:37:50.906998Z", + "iopub.status.idle": "2025-04-20T21:37:50.911113Z", + "shell.execute_reply": "2025-04-20T21:37:50.910277Z" + }, + "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.13.2" + }, + "widgets": { + "application/vnd.jupyter.widget-state+json": { + "state": { + "1d84a21b3fe94876acee2d2d12fa5c6e": { + "model_module": "@jupyter-widgets/controls", + "model_module_version": "2.0.0", + "model_name": "VBoxModel", + "state": { + "_dom_classes": [ + "widget-interact" + ], + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "2.0.0", + "_model_name": "VBoxModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/controls", + "_view_module_version": "2.0.0", + "_view_name": "VBoxView", + "box_style": "", + "children": [ + "IPY_MODEL_be68d12ab3cf4804b7eff74860bba9d7", + "IPY_MODEL_c780f6d65e0b4bd282c1466acf1f4f20", + "IPY_MODEL_5f71cbdd1b0147a494ab46fadbfda2a7", + "IPY_MODEL_b51f1a2a47064228ae5d347a4c18c023", + "IPY_MODEL_5bb32f41d83f4c5598327a71c6336f88" + ], + "layout": "IPY_MODEL_564dc3b6cffa4f1a96b276af7862e0b0", + "tabbable": null, + "tooltip": null + } + }, + "35a70a7d47c64c1781a61aef0d5c2423": { + "model_module": "@jupyter-widgets/base", + "model_module_version": "2.0.0", + "model_name": "LayoutModel", + "state": { + "_model_module": "@jupyter-widgets/base", + "_model_module_version": "2.0.0", + "_model_name": "LayoutModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "2.0.0", + "_view_name": "LayoutView", + "align_content": null, + "align_items": null, + "align_self": null, + "border_bottom": null, + "border_left": null, + "border_right": null, + "border_top": 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, + "padding": null, + "right": null, + "top": null, + "visibility": null, + "width": null + } + }, + "51b0711ebc244447bea6617b8503b492": { + "model_module": "@jupyter-widgets/base", + "model_module_version": "2.0.0", + "model_name": "LayoutModel", + "state": { + "_model_module": "@jupyter-widgets/base", + "_model_module_version": "2.0.0", + "_model_name": "LayoutModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "2.0.0", + "_view_name": "LayoutView", + "align_content": null, + "align_items": null, + "align_self": null, + "border_bottom": null, + "border_left": null, + "border_right": null, + "border_top": 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, + "padding": null, + "right": null, + "top": null, + "visibility": null, + "width": null + } + }, + "564dc3b6cffa4f1a96b276af7862e0b0": { + "model_module": "@jupyter-widgets/base", + "model_module_version": "2.0.0", + "model_name": "LayoutModel", + "state": { + "_model_module": "@jupyter-widgets/base", + "_model_module_version": "2.0.0", + "_model_name": "LayoutModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "2.0.0", + "_view_name": "LayoutView", + "align_content": null, + "align_items": null, + "align_self": null, + "border_bottom": null, + "border_left": null, + "border_right": null, + "border_top": 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, + "padding": null, + "right": null, + "top": null, + "visibility": null, + "width": null + } + }, + "5801e88d7abd4e5ea383f5e373a52fac": { + "model_module": "@jupyter-widgets/controls", + "model_module_version": "2.0.0", + "model_name": "SliderStyleModel", + "state": { + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "2.0.0", + "_model_name": "SliderStyleModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "2.0.0", + "_view_name": "StyleView", + "description_width": "", + "handle_color": null + } + }, + "5bb32f41d83f4c5598327a71c6336f88": { + "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_7fef651fd75d4e599b57ea0a42a32900", + "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
00.125730-0.132105nan0.104900
1-0.5356690.3615951.3040000.947081
2-0.703735-1.265421-0.6232740.041326
3-2.325031-0.218792-1.245911-0.732267
4-0.544259-0.3163000.411631nan
5-0.1285351.366463-0.6651950.351510
60.9034700.094012-0.743499-0.921725
7-0.4577260.220195-1.009618-0.209176
8-0.1592250.5408460.2146590.355373
9-0.653829-0.1296140.7839751.493431
\n", + "text/plain": "" + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "tabbable": null, + "tooltip": null + } + }, + "5f71cbdd1b0147a494ab46fadbfda2a7": { + "model_module": "@jupyter-widgets/controls", + "model_module_version": "2.0.0", + "model_name": "FloatSliderModel", + "state": { + "_dom_classes": [], + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "2.0.0", + "_model_name": "FloatSliderModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/controls", + "_view_module_version": "2.0.0", + "_view_name": "FloatSliderView", + "behavior": "drag-tap", + "continuous_update": true, + "description": "s", + "description_allow_html": false, + "disabled": false, + "layout": "IPY_MODEL_a3531fca701447c2aab06dd1fd30a593", + "max": 99.9, + "min": 0.0, + "orientation": "horizontal", + "readout": true, + "readout_format": ".2f", + "step": 0.1, + "style": "IPY_MODEL_76be0a662a694c97b0b54e67fb1eca1d", + "tabbable": null, + "tooltip": null, + "value": 49.95 + } + }, + "76be0a662a694c97b0b54e67fb1eca1d": { + "model_module": "@jupyter-widgets/controls", + "model_module_version": "2.0.0", + "model_name": "SliderStyleModel", + "state": { + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "2.0.0", + "_model_name": "SliderStyleModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "2.0.0", + "_view_name": "StyleView", + "description_width": "", + "handle_color": null + } + }, + "7fef651fd75d4e599b57ea0a42a32900": { + "model_module": "@jupyter-widgets/base", + "model_module_version": "2.0.0", + "model_name": "LayoutModel", + "state": { + "_model_module": "@jupyter-widgets/base", + "_model_module_version": "2.0.0", + "_model_name": "LayoutModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "2.0.0", + "_view_name": "LayoutView", + "align_content": null, + "align_items": null, + "align_self": null, + "border_bottom": null, + "border_left": null, + "border_right": null, + "border_top": 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, + "padding": null, + "right": null, + "top": null, + "visibility": null, + "width": null + } + }, + "a3531fca701447c2aab06dd1fd30a593": { + "model_module": "@jupyter-widgets/base", + "model_module_version": "2.0.0", + "model_name": "LayoutModel", + "state": { + "_model_module": "@jupyter-widgets/base", + "_model_module_version": "2.0.0", + "_model_name": "LayoutModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "2.0.0", + "_view_name": "LayoutView", + "align_content": null, + "align_items": null, + "align_self": null, + "border_bottom": null, + "border_left": null, + "border_right": null, + "border_top": 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, + "padding": null, + "right": null, + "top": null, + "visibility": null, + "width": null + } + }, + "ad4a09fb83f64b5c9bb9c12257ee94e7": { + "model_module": "@jupyter-widgets/controls", + "model_module_version": "2.0.0", + "model_name": "SliderStyleModel", + "state": { + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "2.0.0", + "_model_name": "SliderStyleModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "2.0.0", + "_view_name": "StyleView", + "description_width": "", + "handle_color": null + } + }, + "b51f1a2a47064228ae5d347a4c18c023": { + "model_module": "@jupyter-widgets/controls", + "model_module_version": "2.0.0", + "model_name": "FloatSliderModel", + "state": { + "_dom_classes": [], + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "2.0.0", + "_model_name": "FloatSliderModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/controls", + "_view_module_version": "2.0.0", + "_view_name": "FloatSliderView", + "behavior": "drag-tap", + "continuous_update": true, + "description": "l_post", + "description_allow_html": false, + "disabled": false, + "layout": "IPY_MODEL_51b0711ebc244447bea6617b8503b492", + "max": 99.9, + "min": 0.0, + "orientation": "horizontal", + "readout": true, + "readout_format": ".2f", + "step": 0.1, + "style": "IPY_MODEL_ad4a09fb83f64b5c9bb9c12257ee94e7", + "tabbable": null, + "tooltip": null, + "value": 49.95 + } + }, + "be68d12ab3cf4804b7eff74860bba9d7": { + "model_module": "@jupyter-widgets/controls", + "model_module_version": "2.0.0", + "model_name": "IntSliderModel", + "state": { + "_dom_classes": [], + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "2.0.0", + "_model_name": "IntSliderModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/controls", + "_view_module_version": "2.0.0", + "_view_name": "IntSliderView", + "behavior": "drag-tap", + "continuous_update": true, + "description": "h_neg", + "description_allow_html": false, + "disabled": false, + "layout": "IPY_MODEL_e66be4437da04e8f8b510433bb62ad96", + "max": 359, + "min": 0, + "orientation": "horizontal", + "readout": true, + "readout_format": "d", + "step": 1, + "style": "IPY_MODEL_ee232d67119e48869704624fc69996dd", + "tabbable": null, + "tooltip": null, + "value": 179 + } + }, + "c780f6d65e0b4bd282c1466acf1f4f20": { + "model_module": "@jupyter-widgets/controls", + "model_module_version": "2.0.0", + "model_name": "IntSliderModel", + "state": { + "_dom_classes": [], + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "2.0.0", + "_model_name": "IntSliderModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/controls", + "_view_module_version": "2.0.0", + "_view_name": "IntSliderView", + "behavior": "drag-tap", + "continuous_update": true, + "description": "h_pos", + "description_allow_html": false, + "disabled": false, + "layout": "IPY_MODEL_35a70a7d47c64c1781a61aef0d5c2423", + "max": 359, + "min": 0, + "orientation": "horizontal", + "readout": true, + "readout_format": "d", + "step": 1, + "style": "IPY_MODEL_5801e88d7abd4e5ea383f5e373a52fac", + "tabbable": null, + "tooltip": null, + "value": 179 + } + }, + "e66be4437da04e8f8b510433bb62ad96": { + "model_module": "@jupyter-widgets/base", + "model_module_version": "2.0.0", + "model_name": "LayoutModel", + "state": { + "_model_module": "@jupyter-widgets/base", + "_model_module_version": "2.0.0", + "_model_name": "LayoutModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "2.0.0", + "_view_name": "LayoutView", + "align_content": null, + "align_items": null, + "align_self": null, + "border_bottom": null, + "border_left": null, + "border_right": null, + "border_top": 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, + "padding": null, + "right": null, + "top": null, + "visibility": null, + "width": null + } + }, + "ee232d67119e48869704624fc69996dd": { + "model_module": "@jupyter-widgets/controls", + "model_module_version": "2.0.0", + "model_name": "SliderStyleModel", + "state": { + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "2.0.0", + "_model_name": "SliderStyleModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "2.0.0", + "_view_name": "StyleView", + "description_width": "", + "handle_color": null + } + } + }, + "version_major": 2, + "version_minor": 0 + } + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 7945c9fc13725..f1293b4a17ebc 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -7740,7 +7740,7 @@ def select_by_substr( Returns ------- - DataFrame or None + DataFrame DataFrame containing only the columns whose names match the specified substring(s). Returns None if no columns match. @@ -7781,23 +7781,22 @@ def select_by_substr( 1 30 """ substr = [substr] if isinstance(substr, str) else substr - selected_cols = self.columns - - if ignore_case: - selected_cols = [ - col for col in self.columns - if any(sub.casefold() in col.casefold() - for sub in substr) - ] - else: - selected_cols = [ - col for col in self.columns - if any(sub in col - for sub in substr) - ] - - selected_cols = list(set(selected_cols)) - return self[selected_cols] + substr = [s.strip() for s in substr if isinstance(s, str)] + substr = [s for s in substr if s] + + if not substr: + return self[[]] + + selected_cols = [] + for col in self.columns: + for sub in substr: + col_to_check = col.casefold() if ignore_case else col + sub_to_check = sub.casefold() if ignore_case else sub + if sub_to_check in col_to_check: + selected_cols.append(col) + break + + return self[selected_cols] if selected_cols else self[[]] def swaplevel(self, i: Axis = -2, j: Axis = -1, axis: Axis = 0) -> DataFrame: """ diff --git a/pandas/tests/frame/test_ b/pandas/tests/frame/test_ deleted file mode 100644 index e69de29bb2d1d..0000000000000 diff --git a/pandas/tests/frame/test_select_by_substr.py b/pandas/tests/frame/test_select_by_substr.py new file mode 100644 index 0000000000000..43f8d5b332309 --- /dev/null +++ b/pandas/tests/frame/test_select_by_substr.py @@ -0,0 +1,82 @@ +import pytest +from pandas import DataFrame +import pandas._testing as tm + +class TestSelectBySubstr: + @pytest.fixture + def df(self): + return DataFrame({ + "first_name": ["Alice", "Bob"], + "last_name": ["Smith", "Jones"], + "age": [25, 30], + "City": ["NY", "LA"], + "FOO_column": [1.1, 2.2], + "bar_col": [True, False] + }) + + def test_basic_substring(self, df): + result = df.select_by_substr("name") + expected = df[["first_name", "last_name"]] + tm.assert_frame_equal(result, expected) + + def test_multiple_substrings(self, df): + result = df.select_by_substr(["name", "city"]) + expected = df[["first_name", "last_name", "City"]] + tm.assert_frame_equal(result, expected) + + def test_case_sensitivity(self, df): + # Case-sensitive search (no match) + result = df.select_by_substr("city", ignore_case=False) + expected = df[[]] + tm.assert_frame_equal(result, expected) + + # Case-insensitive search (matches "City") + result = df.select_by_substr("city") + expected = df[["City"]] + tm.assert_frame_equal(result, expected) + + def test_no_matches(self, df): + result = df.select_by_substr("xyz") + expected = df[[]] + tm.assert_frame_equal(result, expected) + + def test_empty_dataframe(self): + df = DataFrame() + result = df.select_by_substr("test") + expected = df[[]] + tm.assert_frame_equal(result, expected) + + def test_duplicate_columns(self): + df = DataFrame([[1, 2]], columns=["foo", "foo"]) + result = df.select_by_substr("foo") + expected = df[["foo", "foo"]] + tm.assert_frame_equal(result, expected) + + @pytest.mark.parametrize("substr,expected_cols", [ + ("", []), # Empty substring is ignored + (["", "name"], ["first_name", "last_name"]), # "" is ignored + ([" ", "age"], ["age"]), # " " is ignored + ]) + def test_edge_cases(self, df, substr, expected_cols): + result = df.select_by_substr(substr) + expected = df[expected_cols] if expected_cols else df[[]] + tm.assert_frame_equal(result, expected) + + def test_mixed_case_columns(self, df): + result = df.select_by_substr("foo") + expected = df[["FOO_column"]] + tm.assert_frame_equal(result, expected) + + def test_return_type(self, df): + # With matches + result = df.select_by_substr("name") + assert isinstance(result, DataFrame) + # Without matches + result = df.select_by_substr("invalid") + assert isinstance(result, DataFrame) + assert result.empty + + def test_original_frame_unmodified(self, df): + original_cols = df.columns.copy() + df.select_by_substr("name") + tm.assert_index_equal(df.columns, original_cols) diff --git a/placeholder.txt b/placeholder.txt deleted file mode 100644 index ec10be0abd110..0000000000000 --- a/placeholder.txt +++ /dev/null @@ -1,125 +0,0 @@ -Return the first `n` rows ordered by `columns` in ascending order. - - Return the first `n` rows with the smallest values in `columns`, in - ascending order. The columns that are not specified are returned as - well, but not used for ordering. - - This method is equivalent to - ``df.sort_values(columns, ascending=True).head(n)``, but more - performant. - - Parameters - ---------- - n : int - Number of items to retrieve. - columns : list or str - Column name or names to order by. - keep : {'first', 'last', 'all'}, default 'first' - Where there are duplicate values: - - - ``first`` : take the first occurrence. - - ``last`` : take the last occurrence. - - ``all`` : keep all the ties of the largest item even if it means - selecting more than ``n`` items. - - Returns - ------- - DataFrame - DataFrame with the first `n` rows ordered by `columns` in ascending order. - - See Also - -------- - DataFrame.nlargest : Return the first `n` rows ordered by `columns` in - descending order. - DataFrame.sort_values : Sort DataFrame by the values. - DataFrame.head : Return the first `n` rows without re-ordering. - - Examples - -------- - >>> df = pd.DataFrame( - ... { - ... "population": [ - ... 59000000, - ... 65000000, - ... 434000, - ... 434000, - ... 434000, - ... 337000, - ... 337000, - ... 11300, - ... 11300, - ... ], - ... "GDP": [1937894, 2583560, 12011, 4520, 12128, 17036, 182, 38, 311], - ... "alpha-2": ["IT", "FR", "MT", "MV", "BN", "IS", "NR", "TV", "AI"], - ... }, - ... index=[ - ... "Italy", - ... "France", - ... "Malta", - ... "Maldives", - ... "Brunei", - ... "Iceland", - ... "Nauru", - ... "Tuvalu", - ... "Anguilla", - ... ], - ... ) - >>> df - population GDP alpha-2 - Italy 59000000 1937894 IT - France 65000000 2583560 FR - Malta 434000 12011 MT - Maldives 434000 4520 MV - Brunei 434000 12128 BN - Iceland 337000 17036 IS - Nauru 337000 182 NR - Tuvalu 11300 38 TV - Anguilla 11300 311 AI - - In the following example, we will use ``nsmallest`` to select the - three rows having the smallest values in column "population". - - >>> df.nsmallest(3, "population") - population GDP alpha-2 - Tuvalu 11300 38 TV - Anguilla 11300 311 AI - Iceland 337000 17036 IS - - When using ``keep='last'``, ties are resolved in reverse order: - - >>> df.nsmallest(3, "population", keep="last") - population GDP alpha-2 - Anguilla 11300 311 AI - Tuvalu 11300 38 TV - Nauru 337000 182 NR - - When using ``keep='all'``, the number of element kept can go beyond ``n`` - if there are duplicate values for the largest element, all the - ties are kept. - - >>> df.nsmallest(3, "population", keep="all") - population GDP alpha-2 - Tuvalu 11300 38 TV - Anguilla 11300 311 AI - Iceland 337000 17036 IS - Nauru 337000 182 NR - - However, ``nsmallest`` does not keep ``n`` distinct - smallest elements: - - >>> df.nsmallest(4, "population", keep="all") - population GDP alpha-2 - Tuvalu 11300 38 TV - Anguilla 11300 311 AI - Iceland 337000 17036 IS - Nauru 337000 182 NR - - To order by the smallest values in column "population" and then "GDP", we can - specify multiple columns like in the next example. - - >>> df.nsmallest(3, ["population", "GDP"]) - population GDP alpha-2 - Tuvalu 11300 38 TV - Anguilla 11300 311 AI - Nauru 337000 182 NR - """ \ No newline at end of file diff --git a/test.py b/test.py deleted file mode 100644 index 34fd68207ab8b..0000000000000 --- a/test.py +++ /dev/null @@ -1,15 +0,0 @@ -# contributing guide: https://pandas.pydata.org/docs/dev/development/contributing.html#pushing-your-changes -import pandas as pd - -df = pd.DataFrame({ - "yes": [5000, 2, 3], - "Byesyes": [4, 5, 6], - "no": [7, 8, 9], - "Byesno": [10, 11, 12], - "YES": [13, 14, 15], - "NO": [16, 17, 18], - "YESYES": [19, 20, 21], -}) - -# Test the DataFrame creation -print(df.select_by_substr("skibidi")) \ No newline at end of file From 451aa4e8b9e2c1d0bf5d85e512c29cf83f0a2c7d Mon Sep 17 00:00:00 2001 From: Rahul Hoque Date: Mon, 21 Apr 2025 09:13:12 -0400 Subject: [PATCH 3/4] update whatsnew --- doc/source/whatsnew/v3.0.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index b03b2305172a7..7038268f9798d 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -86,7 +86,7 @@ Other enhancements - Support passing a :class:`Iterable[Hashable]` input to :meth:`DataFrame.drop_duplicates` (:issue:`59237`) - Support reading Stata 102-format (Stata 1) dta files (:issue:`58978`) - Support reading Stata 110-format (Stata 7) dta files (:issue:`47176`) - +- :meth:`Dataframe.select_by_substr` is a new method to select columns by substring, with the option to ignore case (defaulted to true) (:issue:`61319`) .. --------------------------------------------------------------------------- .. _whatsnew_300.notable_bug_fixes: From a061e3956b1d3954dae739939cda9f7a257a8ec8 Mon Sep 17 00:00:00 2001 From: Rahul Hoque Date: Mon, 21 Apr 2025 09:25:02 -0400 Subject: [PATCH 4/4] update docstring for pylint --- pandas/core/frame.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index f1293b4a17ebc..6d6775e0507fe 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -7746,8 +7746,10 @@ def select_by_substr( See Also -------- - DataFrame.filter : Subset the columns or rows of a DataFrame according to labels or a boolean array. - DataFrame.loc : Access a group of rows and columns by label(s) or a boolean array. + DataFrame.filter : Subset the columns or rows of a DataFrame according to + labels or a boolean array. + DataFrame.loc : Access a group of rows and columns by label(s) or a + boolean array. Notes -----