{ "cells": [ { "cell_type": "markdown", "id": "26508211", "metadata": {}, "source": [ "# Stat `na_rm` Checks\n", "\n", "Small examples for checking `na_rm` handling in selected stats." ] }, { "cell_type": "code", "execution_count": 1, "id": "cdcd2d5d", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import numpy as np\n", "import pandas as pd\n", "\n", "from lets_plot import *\n", "\n", "LetsPlot.setup_html()" ] }, { "cell_type": "code", "execution_count": 2, "id": "3fa7f86e", "metadata": {}, "outputs": [], "source": [ "df_x = pd.DataFrame({\n", " \"x\": [1, 2, np.nan, 4, 5, np.nan]\n", "})\n", "\n", "df_xy = pd.DataFrame({\n", " \"x\": [1, 2, np.nan, 4, 5, np.nan],\n", " \"y\": [2, np.nan, 3, 4, 5, np.nan],\n", " \"g\": [\"A\", \"A\", \"A\", \"B\", \"B\", \"B\"]\n", "})" ] }, { "cell_type": "markdown", "id": "28a9298e", "metadata": {}, "source": [ "## `stat_summary`" ] }, { "cell_type": "code", "execution_count": 3, "id": "229f5e9a", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ggplot(df_xy, aes(\"g\", \"y\")) + stat_summary()" ] }, { "cell_type": "code", "execution_count": 4, "id": "eb323bec", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ggplot(df_xy, aes(\"g\", \"y\")) + stat_summary(na_rm=True)" ] }, { "cell_type": "markdown", "id": "674406fe", "metadata": {}, "source": [ "## `stat_summary_bin`" ] }, { "cell_type": "code", "execution_count": 5, "id": "d86bb259", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ggplot(df_xy, aes(\"x\", \"y\")) + stat_summary_bin(bins=3)" ] }, { "cell_type": "code", "execution_count": 6, "id": "e7757392", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ggplot(df_xy, aes(\"x\", \"y\")) + stat_summary_bin(bins=3, na_rm=True)" ] }, { "cell_type": "markdown", "id": "b948a26c", "metadata": {}, "source": [ "## `stat_ecdf`" ] }, { "cell_type": "code", "execution_count": 7, "id": "cf19348d", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ggplot(df_x, aes(\"x\")) + stat_ecdf()" ] }, { "cell_type": "code", "execution_count": 8, "id": "15fba4b4", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ggplot(df_x, aes(\"x\")) + stat_ecdf(na_rm=True)" ] }, { "cell_type": "markdown", "id": "ea91992a", "metadata": {}, "source": [ "## `stat_sum`" ] }, { "cell_type": "code", "execution_count": 9, "id": "cf7c453c", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ggplot(df_xy, aes(\"x\", \"y\")) + stat_sum()" ] }, { "cell_type": "code", "execution_count": 10, "id": "a125b4e7", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", " \n", " \n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ggplot(df_xy, aes(\"x\", \"y\")) + stat_sum(na_rm=True)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.20" } }, "nbformat": 4, "nbformat_minor": 5 }