From 43bfae8d03f2e473ccea5962a75743b1fa864c21 Mon Sep 17 00:00:00 2001 From: Lu Weizheng Date: Wed, 29 Nov 2023 13:51:45 +0800 Subject: [PATCH] update pandas --- ch-pandas/dataframe-merge-concat.ipynb | 1 + ch-pandas/dataframe-pivot-melt.ipynb | 60 ++++++++----------- .../ch-pandas/dataframe-merge-concat.ipynb | 1 + .../ch-pandas/dataframe-pivot-melt.ipynb | 60 ++++++++----------- docs/ch-pandas/dataframe-merge-concat.html | 3 +- docs/ch-pandas/dataframe-pivot-melt.html | 12 ++-- docs/searchindex.js | 2 +- 7 files changed, 61 insertions(+), 78 deletions(-) diff --git a/ch-pandas/dataframe-merge-concat.ipynb b/ch-pandas/dataframe-merge-concat.ipynb index 335c76b..19edd66 100644 --- a/ch-pandas/dataframe-merge-concat.ipynb +++ b/ch-pandas/dataframe-merge-concat.ipynb @@ -15,6 +15,7 @@ "\n", "```{figure} ../img/ch-pandas/merge.svg\n", "---\n", + "width: 500px\n", "name: merge-img\n", "---\n", "对两个 DataFrame 进行 merge 操作\n", diff --git a/ch-pandas/dataframe-pivot-melt.ipynb b/ch-pandas/dataframe-pivot-melt.ipynb index f8df793..100727c 100644 --- a/ch-pandas/dataframe-pivot-melt.ipynb +++ b/ch-pandas/dataframe-pivot-melt.ipynb @@ -25,7 +25,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 34, "metadata": { "tags": [ "hide cell", @@ -67,7 +67,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 35, "metadata": {}, "outputs": [ { @@ -333,7 +333,7 @@ "16 Monitor 2 5000 presented " ] }, - "execution_count": 15, + "execution_count": 35, "metadata": {}, "output_type": "execute_result" } @@ -369,7 +369,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 36, "metadata": {}, "outputs": [ { @@ -484,7 +484,7 @@ "Trantow-Barrows 15000.0 1.333333" ] }, - "execution_count": 16, + "execution_count": 36, "metadata": {}, "output_type": "execute_result" } @@ -502,7 +502,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 37, "metadata": {}, "outputs": [ { @@ -579,7 +579,7 @@ " Wendy Yule 44250.000000 3.000000" ] }, - "execution_count": 17, + "execution_count": 37, "metadata": {}, "output_type": "execute_result" } @@ -597,7 +597,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 38, "metadata": {}, "outputs": [ { @@ -736,7 +736,7 @@ " Wendy Yule 3.0 2.0 NaN " ] }, - "execution_count": 18, + "execution_count": 38, "metadata": {}, "output_type": "execute_result" } @@ -765,7 +765,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 39, "metadata": {}, "outputs": [ { @@ -835,7 +835,7 @@ " Wendy Yule 44250.000000" ] }, - "execution_count": 19, + "execution_count": 39, "metadata": {}, "output_type": "execute_result" } @@ -857,17 +857,9 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 40, "metadata": {}, "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/var/folders/4n/v40br47s46ggrjm9bdm64lwh0000gn/T/ipykernel_34035/1265594602.py:1: FutureWarning: The provided callable is currently using DataFrameGroupBy.mean. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass the string \"mean\" instead.\n", - " pd.pivot_table(sales_df, index=[\"Manager\",\"Rep\"], values=[\"Price\"], aggfunc=[np.mean, len])\n" - ] - }, { "data": { "text/html": [ @@ -953,13 +945,13 @@ " Wendy Yule 44250.000000 4" ] }, - "execution_count": 20, + "execution_count": 40, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "pd.pivot_table(sales_df, index=[\"Manager\",\"Rep\"], values=[\"Price\"], aggfunc=[np.mean, len])" + "pd.pivot_table(sales_df, index=[\"Manager\",\"Rep\"], values=[\"Price\"], aggfunc=[\"mean\", len])" ] }, { @@ -973,7 +965,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 41, "metadata": {}, "outputs": [ { @@ -1185,7 +1177,7 @@ "All 1.764706 " ] }, - "execution_count": 21, + "execution_count": 41, "metadata": {}, "output_type": "execute_result" } @@ -1207,7 +1199,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 42, "metadata": {}, "outputs": [ { @@ -1401,7 +1393,7 @@ " won 1 0 0 " ] }, - "execution_count": 22, + "execution_count": 42, "metadata": {}, "output_type": "execute_result" } @@ -1429,7 +1421,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 43, "metadata": {}, "outputs": [ { @@ -1562,7 +1554,7 @@ " won 0 0 0 " ] }, - "execution_count": 23, + "execution_count": 43, "metadata": {}, "output_type": "execute_result" } @@ -1580,7 +1572,7 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 44, "metadata": {}, "outputs": [ { @@ -1714,7 +1706,7 @@ " won 1 0 0 " ] }, - "execution_count": 24, + "execution_count": 44, "metadata": {}, "output_type": "execute_result" } @@ -1734,7 +1726,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 45, "metadata": {}, "outputs": [ { @@ -1801,7 +1793,7 @@ "2 3 John 88 79 90" ] }, - "execution_count": 25, + "execution_count": 45, "metadata": {}, "output_type": "execute_result" } @@ -1820,7 +1812,7 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 46, "metadata": {}, "outputs": [ { @@ -1931,7 +1923,7 @@ "8 3 John History 90" ] }, - "execution_count": 26, + "execution_count": 46, "metadata": {}, "output_type": "execute_result" } diff --git a/docs/_sources/ch-pandas/dataframe-merge-concat.ipynb b/docs/_sources/ch-pandas/dataframe-merge-concat.ipynb index 335c76b..19edd66 100644 --- a/docs/_sources/ch-pandas/dataframe-merge-concat.ipynb +++ b/docs/_sources/ch-pandas/dataframe-merge-concat.ipynb @@ -15,6 +15,7 @@ "\n", "```{figure} ../img/ch-pandas/merge.svg\n", "---\n", + "width: 500px\n", "name: merge-img\n", "---\n", "对两个 DataFrame 进行 merge 操作\n", diff --git a/docs/_sources/ch-pandas/dataframe-pivot-melt.ipynb b/docs/_sources/ch-pandas/dataframe-pivot-melt.ipynb index f8df793..100727c 100644 --- a/docs/_sources/ch-pandas/dataframe-pivot-melt.ipynb +++ b/docs/_sources/ch-pandas/dataframe-pivot-melt.ipynb @@ -25,7 +25,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 34, "metadata": { "tags": [ "hide cell", @@ -67,7 +67,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 35, "metadata": {}, "outputs": [ { @@ -333,7 +333,7 @@ "16 Monitor 2 5000 presented " ] }, - "execution_count": 15, + "execution_count": 35, "metadata": {}, "output_type": "execute_result" } @@ -369,7 +369,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 36, "metadata": {}, "outputs": [ { @@ -484,7 +484,7 @@ "Trantow-Barrows 15000.0 1.333333" ] }, - "execution_count": 16, + "execution_count": 36, "metadata": {}, "output_type": "execute_result" } @@ -502,7 +502,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 37, "metadata": {}, "outputs": [ { @@ -579,7 +579,7 @@ " Wendy Yule 44250.000000 3.000000" ] }, - "execution_count": 17, + "execution_count": 37, "metadata": {}, "output_type": "execute_result" } @@ -597,7 +597,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 38, "metadata": {}, "outputs": [ { @@ -736,7 +736,7 @@ " Wendy Yule 3.0 2.0 NaN " ] }, - "execution_count": 18, + "execution_count": 38, "metadata": {}, "output_type": "execute_result" } @@ -765,7 +765,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 39, "metadata": {}, "outputs": [ { @@ -835,7 +835,7 @@ " Wendy Yule 44250.000000" ] }, - "execution_count": 19, + "execution_count": 39, "metadata": {}, "output_type": "execute_result" } @@ -857,17 +857,9 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 40, "metadata": {}, "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/var/folders/4n/v40br47s46ggrjm9bdm64lwh0000gn/T/ipykernel_34035/1265594602.py:1: FutureWarning: The provided callable is currently using DataFrameGroupBy.mean. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass the string \"mean\" instead.\n", - " pd.pivot_table(sales_df, index=[\"Manager\",\"Rep\"], values=[\"Price\"], aggfunc=[np.mean, len])\n" - ] - }, { "data": { "text/html": [ @@ -953,13 +945,13 @@ " Wendy Yule 44250.000000 4" ] }, - "execution_count": 20, + "execution_count": 40, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "pd.pivot_table(sales_df, index=[\"Manager\",\"Rep\"], values=[\"Price\"], aggfunc=[np.mean, len])" + "pd.pivot_table(sales_df, index=[\"Manager\",\"Rep\"], values=[\"Price\"], aggfunc=[\"mean\", len])" ] }, { @@ -973,7 +965,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 41, "metadata": {}, "outputs": [ { @@ -1185,7 +1177,7 @@ "All 1.764706 " ] }, - "execution_count": 21, + "execution_count": 41, "metadata": {}, "output_type": "execute_result" } @@ -1207,7 +1199,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 42, "metadata": {}, "outputs": [ { @@ -1401,7 +1393,7 @@ " won 1 0 0 " ] }, - "execution_count": 22, + "execution_count": 42, "metadata": {}, "output_type": "execute_result" } @@ -1429,7 +1421,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 43, "metadata": {}, "outputs": [ { @@ -1562,7 +1554,7 @@ " won 0 0 0 " ] }, - "execution_count": 23, + "execution_count": 43, "metadata": {}, "output_type": "execute_result" } @@ -1580,7 +1572,7 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 44, "metadata": {}, "outputs": [ { @@ -1714,7 +1706,7 @@ " won 1 0 0 " ] }, - "execution_count": 24, + "execution_count": 44, "metadata": {}, "output_type": "execute_result" } @@ -1734,7 +1726,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 45, "metadata": {}, "outputs": [ { @@ -1801,7 +1793,7 @@ "2 3 John 88 79 90" ] }, - "execution_count": 25, + "execution_count": 45, "metadata": {}, "output_type": "execute_result" } @@ -1820,7 +1812,7 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 46, "metadata": {}, "outputs": [ { @@ -1931,7 +1923,7 @@ "8 3 John History 90" ] }, - "execution_count": 26, + "execution_count": 46, "metadata": {}, "output_type": "execute_result" } diff --git a/docs/ch-pandas/dataframe-merge-concat.html b/docs/ch-pandas/dataframe-merge-concat.html index f5dc43c..79ac4e4 100644 --- a/docs/ch-pandas/dataframe-merge-concat.html +++ b/docs/ch-pandas/dataframe-merge-concat.html @@ -416,7 +416,8 @@

2.6. 多表操作2.6.1. merge#

pandas 的 merge() 操作可以合并两个 DataFrame(或者称为表) ,类似于 SQL 中的 JOIN 操作。 我们可以想象成:一个大表被拆分成两个小表,两个小表都包含一些同样的数据。现在我们需要把两个小表合并,生成一个大表,大表包含了两个小表的字段。

-../_images/merge.svg
+../_images/merge.svg +

图 2.8 对两个 DataFrame 进行 merge 操作#

diff --git a/docs/ch-pandas/dataframe-pivot-melt.html b/docs/ch-pandas/dataframe-pivot-melt.html index adbcff1..1e915ee 100644 --- a/docs/ch-pandas/dataframe-pivot-melt.html +++ b/docs/ch-pandas/dataframe-pivot-melt.html @@ -1064,15 +1064,11 @@

2.7.1.3. aggfunc 参数meanlen 两列结果。

-
pd.pivot_table(sales_df, index=["Manager","Rep"], values=["Price"], aggfunc=[np.mean, len])
+
pd.pivot_table(sales_df, index=["Manager","Rep"], values=["Price"], aggfunc=["mean", len])
 
-
/var/folders/4n/v40br47s46ggrjm9bdm64lwh0000gn/T/ipykernel_42863/1265594602.py:1: FutureWarning: The provided callable <function mean at 0x10f8080e0> is currently using DataFrameGroupBy.mean. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass the string "mean" instead.
-  pd.pivot_table(sales_df, index=["Manager","Rep"], values=["Price"], aggfunc=[np.mean, len])
-
-