{ "cells": [ { "cell_type": "markdown", "id": "079371a5", "metadata": {}, "source": [ "# Downsampling\n", "\n", "When an interactive table is displayed by `itables`, the table data is embedded in the notebook output. As we don't want your notebook to become super heavy just because you displayed a large table, we have a downsampling mechanism in place.\n", "\n", "When the data in a table is larger than `maxBytes`, which is equal to 64KB by default, `itables` will display only a subset of the table - one that fits into `maxBytes`, and display a warning that points to the `itables` documentation.\n", "\n", "If you wish, you can increase the value of `maxBytes` or even deactivate the limit (with `maxBytes=0`). Similarly, you can set a limit on the number of rows (`maxRows`, defaults to 0) or columns (`maxColumns`, defaults to `200`)." ] }, { "cell_type": "code", "execution_count": 1, "id": "c6dacf3c", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "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", "This is the init_notebook_mode cell from ITables v2.0.1
\n", "(you should not see this message - is your notebook trusted?)\n", "
\n", "
\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import itables.options as opt\n", "from itables import init_notebook_mode, show\n", "from itables.downsample import as_nbytes, nbytes\n", "from itables.sample_dfs import get_indicators\n", "\n", "init_notebook_mode(all_interactive=True)" ] }, { "cell_type": "code", "execution_count": 2, "id": "eb57a8da", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(8192, 28000)" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "opt.lengthMenu = [2, 5, 10, 20, 50, 100, 200, 500]\n", "opt.maxBytes = \"8KB\"\n", "\n", "df = get_indicators()\n", "as_nbytes(opt.maxBytes), nbytes(df)" ] }, { "cell_type": "code", "execution_count": 3, "id": "579cd8de", "metadata": { "tags": [ "full-width" ] }, "outputs": [ { "data": { "text/html": [ "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", "
idnameunitsourcesourceNotesourceOrganizationtopics
\n", "\n", "
\n", "Loading ITables v2.0.1 from the init_notebook_mode cell...\n", "(need help?)
\n", "\n" ], "text/plain": [ " id \\\n", "0 1.0.HCount.1.90usd \n", "1 1.0.HCount.2.5usd \n", "2 1.0.HCount.Mid10to50 \n", "3 1.0.HCount.Ofcl \n", "4 1.0.HCount.Poor4uds \n", ".. ... \n", "495 5.2.11_ETH.BAS.AID.JICA \n", "496 5.2.11_KHM.BAS.AID.WB \n", "497 5.2.11_LAO.BAS.AID.INGOS \n", "498 5.2.11_MWI.BAS.AID.WB \n", "499 5.2.11_TLS.TOT.AID.UNICEF \n", "\n", " name unit \\\n", "0 Poverty Headcount ($1.90 a day) NaN \n", "1 Poverty Headcount ($2.50 a day) NaN \n", "2 Middle Class ($10-50 a day) Headcount NaN \n", "3 Official Moderate Poverty Rate-National NaN \n", "4 Poverty Headcount ($4 a day) NaN \n", ".. ... ... \n", "495 International aid disbursed to basic education... NaN \n", "496 International aid disbursed to basic educatio... NaN \n", "497 International aid disbursed to basic educatio... NaN \n", "498 International aid disbursed to basic education... NaN \n", "499 International aid disbursed to total educatio... NaN \n", "\n", " source \\\n", "0 LAC Equity Lab \n", "1 LAC Equity Lab \n", "2 LAC Equity Lab \n", "3 LAC Equity Lab \n", "4 LAC Equity Lab \n", ".. ... \n", "495 Global Partnership for Education \n", "496 Global Partnership for Education \n", "497 Global Partnership for Education \n", "498 Global Partnership for Education \n", "499 Global Partnership for Education \n", "\n", " sourceNote \\\n", "0 The poverty headcount index measures the propo... \n", "1 The poverty headcount index measures the propo... \n", "2 The poverty headcount index measures the propo... \n", "3 The poverty headcount index measures the propo... \n", "4 The poverty headcount index measures the propo... \n", ".. ... \n", "495 International concessional aid disbursed by th... \n", "496 International concessional aid disbursed by th... \n", "497 International concessional aid disbursed by th... \n", "498 International concessional aid disbursed by th... \n", "499 International concessional aid disbursed by th... \n", "\n", " sourceOrganization topics \n", "0 LAC Equity Lab tabulations of SEDLAC (CEDLAS a... Poverty \n", "1 LAC Equity Lab tabulations of SEDLAC (CEDLAS a... Poverty \n", "2 LAC Equity Lab tabulations of SEDLAC (CEDLAS a... Poverty \n", "3 LAC Equity Lab tabulations of data from Nation... Poverty \n", "4 LAC Equity Lab tabulations of SEDLAC (CEDLAS a... Poverty \n", ".. ... ... \n", "495 The 2011 Monitoring Exercise on Aid Effectiven... NaN \n", "496 The 2011 Monitoring Exercise on Aid Effectiven... NaN \n", "497 The 2011 Monitoring Exercise on Aid Effectiven... NaN \n", "498 The 2011 Monitoring Exercise on Aid Effectiven... NaN \n", "499 The 2011 Monitoring Exercise on Aid Effectiven... NaN \n", "\n", "[500 rows x 7 columns]" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df" ] }, { "cell_type": "markdown", "id": "aeeeae7d", "metadata": {}, "source": [ "To show the table in full, we can modify the value of `maxBytes` either locally:" ] }, { "cell_type": "code", "execution_count": 4, "id": "73cdb68e", "metadata": { "tags": [ "full-width" ] }, "outputs": [ { "data": { "text/html": [ "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", "
idnameunitsourcesourceNotesourceOrganizationtopics
\n", "\n", "
\n", "Loading ITables v2.0.1 from the init_notebook_mode cell...\n", "(need help?)
\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "show(df, maxBytes=0)" ] }, { "cell_type": "markdown", "id": "47614041", "metadata": {}, "source": [ "or globally:" ] }, { "cell_type": "code", "execution_count": 5, "id": "2880dfc8", "metadata": { "tags": [ "full-width" ] }, "outputs": [ { "data": { "text/html": [ "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", "
idnameunitsourcesourceNotesourceOrganizationtopics
\n", "\n", "
\n", "Loading ITables v2.0.1 from the init_notebook_mode cell...\n", "(need help?)
\n", "\n" ], "text/plain": [ " id \\\n", "0 1.0.HCount.1.90usd \n", "1 1.0.HCount.2.5usd \n", "2 1.0.HCount.Mid10to50 \n", "3 1.0.HCount.Ofcl \n", "4 1.0.HCount.Poor4uds \n", ".. ... \n", "495 5.2.11_ETH.BAS.AID.JICA \n", "496 5.2.11_KHM.BAS.AID.WB \n", "497 5.2.11_LAO.BAS.AID.INGOS \n", "498 5.2.11_MWI.BAS.AID.WB \n", "499 5.2.11_TLS.TOT.AID.UNICEF \n", "\n", " name unit \\\n", "0 Poverty Headcount ($1.90 a day) NaN \n", "1 Poverty Headcount ($2.50 a day) NaN \n", "2 Middle Class ($10-50 a day) Headcount NaN \n", "3 Official Moderate Poverty Rate-National NaN \n", "4 Poverty Headcount ($4 a day) NaN \n", ".. ... ... \n", "495 International aid disbursed to basic education... NaN \n", "496 International aid disbursed to basic educatio... NaN \n", "497 International aid disbursed to basic educatio... NaN \n", "498 International aid disbursed to basic education... NaN \n", "499 International aid disbursed to total educatio... NaN \n", "\n", " source \\\n", "0 LAC Equity Lab \n", "1 LAC Equity Lab \n", "2 LAC Equity Lab \n", "3 LAC Equity Lab \n", "4 LAC Equity Lab \n", ".. ... \n", "495 Global Partnership for Education \n", "496 Global Partnership for Education \n", "497 Global Partnership for Education \n", "498 Global Partnership for Education \n", "499 Global Partnership for Education \n", "\n", " sourceNote \\\n", "0 The poverty headcount index measures the propo... \n", "1 The poverty headcount index measures the propo... \n", "2 The poverty headcount index measures the propo... \n", "3 The poverty headcount index measures the propo... \n", "4 The poverty headcount index measures the propo... \n", ".. ... \n", "495 International concessional aid disbursed by th... \n", "496 International concessional aid disbursed by th... \n", "497 International concessional aid disbursed by th... \n", "498 International concessional aid disbursed by th... \n", "499 International concessional aid disbursed by th... \n", "\n", " sourceOrganization topics \n", "0 LAC Equity Lab tabulations of SEDLAC (CEDLAS a... Poverty \n", "1 LAC Equity Lab tabulations of SEDLAC (CEDLAS a... Poverty \n", "2 LAC Equity Lab tabulations of SEDLAC (CEDLAS a... Poverty \n", "3 LAC Equity Lab tabulations of data from Nation... Poverty \n", "4 LAC Equity Lab tabulations of SEDLAC (CEDLAS a... Poverty \n", ".. ... ... \n", "495 The 2011 Monitoring Exercise on Aid Effectiven... NaN \n", "496 The 2011 Monitoring Exercise on Aid Effectiven... NaN \n", "497 The 2011 Monitoring Exercise on Aid Effectiven... NaN \n", "498 The 2011 Monitoring Exercise on Aid Effectiven... NaN \n", "499 The 2011 Monitoring Exercise on Aid Effectiven... NaN \n", "\n", "[500 rows x 7 columns]" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "opt.maxBytes = \"1MB\"\n", "df" ] } ], "metadata": { "jupytext": { "formats": "md:myst", "text_representation": { "extension": ".md", "format_name": "myst", "format_version": 0.13, "jupytext_version": "1.14.5" } }, "kernelspec": { "display_name": "itables", "language": "python", "name": "itables" }, "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.11.9" }, "source_map": [ 13, 23, 32, 40, 44, 48, 52, 56 ] }, "nbformat": 4, "nbformat_minor": 5 }