diff --git "a/Day31-35/31-35.\347\216\251\350\275\254Linux\346\223\215\344\275\234\347\263\273\347\273\237.md" "b/Day31-35/31-35.\347\216\251\350\275\254Linux\346\223\215\344\275\234\347\263\273\347\273\237.md"
index 2bcc59878..93103633d 100644
--- "a/Day31-35/31-35.\347\216\251\350\275\254Linux\346\223\215\344\275\234\347\263\273\347\273\237.md"
+++ "b/Day31-35/31-35.\347\216\251\350\275\254Linux\346\223\215\344\275\234\347\263\273\347\273\237.md"
@@ -230,7 +230,7 @@ Linux系统的命令通常都是如下所示的格式:
[root@iZwz97tbgo9lkabnat2lo8Z ~]# !454
```
- > 说明:查看到历史命令之后,可以用`!历史命令编号`来重新执行该命令;通过`history -c`可以清除历史命令。
+ > **说明**:查看到历史命令之后,可以用`!历史命令编号`来重新执行该命令;通过`history -c`可以清除历史命令。
### 实用程序
@@ -308,7 +308,7 @@ Linux系统的命令通常都是如下所示的格式:
...
```
- > 说明:上面用到了一个名为`wget`的命令,它是一个网络下载器程序,可以从指定的URL下载资源。
+ > **说明**:上面用到了一个名为`wget`的命令,它是一个网络下载器程序,可以从指定的URL下载资源。
6. 拷贝/移动文件 - **cp** / **mv**。
@@ -350,7 +350,7 @@ Linux系统的命令通常都是如下所示的格式:
52:
...
```
- > 说明:`grep`在搜索字符串时可以使用正则表达式,如果需要使用正则表达式可以用`grep -E`或者直接使用`egrep`。
+ > **说明**:`grep`在搜索字符串时可以使用正则表达式,如果需要使用正则表达式可以用`grep -E`或者直接使用`egrep`。
9. 创建链接和查看链接 - **ln** / **readlink**。
@@ -372,7 +372,7 @@ Linux系统的命令通常都是如下所示的格式:
CentOS Linux release 7.4.1708 (Core)
```
- > 说明:链接可以分为硬链接和软链接(符号链接)。硬链接可以认为是一个指向文件数据的指针,就像Python中对象的引用计数,每添加一个硬链接,文件的对应链接数就增加1,只有当文件的链接数为0时,文件所对应的存储空间才有可能被其他文件覆盖。我们平常删除文件时其实并没有删除硬盘上的数据,我们删除的只是一个指针,或者说是数据的一条使用记录,所以类似于“文件粉碎机”之类的软件在“粉碎”文件时除了删除文件指针,还会在文件对应的存储区域填入数据来保证文件无法再恢复。软链接类似于Windows系统下的快捷方式,当软链接链接的文件被删除时,软链接也就失效了。
+ > **说明**:链接可以分为硬链接和软链接(符号链接)。硬链接可以认为是一个指向文件数据的指针,就像Python中对象的引用计数,每添加一个硬链接,文件的对应链接数就增加1,只有当文件的链接数为0时,文件所对应的存储空间才有可能被其他文件覆盖。我们平常删除文件时其实并没有删除硬盘上的数据,我们删除的只是一个指针,或者说是数据的一条使用记录,所以类似于“文件粉碎机”之类的软件在“粉碎”文件时除了删除文件指针,还会在文件对应的存储区域填入数据来保证文件无法再恢复。软链接类似于Windows系统下的快捷方式,当软链接链接的文件被删除时,软链接也就失效了。
10. 压缩/解压缩和归档/解归档 - **gzip** / **gunzip** / **xz**。
@@ -429,7 +429,7 @@ Linux系统的命令通常都是如下所示的格式:
[root@iZwz97tbgo9lkabnat2lo8Z ~]# xargs < a.txt > b.txt
```
- > 说明:这个命令就像上面演示的那样常在管道(实现进程间通信的一种方式)和重定向(重新指定输入输出的位置)操作中用到,后面的内容中会讲到管道操作和输入输出重定向操作。
+ > **说明**:这个命令就像上面演示的那样常在管道(实现进程间通信的一种方式)和重定向(重新指定输入输出的位置)操作中用到,后面的内容中会讲到管道操作和输入输出重定向操作。
13. 显示文件或目录 - **basename** / **dirname**。
diff --git "a/Day41-55/48.\345\211\215\345\220\216\347\253\257\345\210\206\347\246\273\345\274\200\345\217\221\345\205\245\351\227\250.md" "b/Day41-55/48.\345\211\215\345\220\216\347\253\257\345\210\206\347\246\273\345\274\200\345\217\221\345\205\245\351\227\250.md"
index 974a9cc47..0675a7558 100644
--- "a/Day41-55/48.\345\211\215\345\220\216\347\253\257\345\210\206\347\246\273\345\274\200\345\217\221\345\205\245\351\227\250.md"
+++ "b/Day41-55/48.\345\211\215\345\220\216\347\253\257\345\210\206\347\246\273\345\274\200\345\217\221\345\205\245\351\227\250.md"
@@ -133,21 +133,7 @@ class SubjectMapper(ModelMapper):
学科信息
@@ -157,7 +143,9 @@ class SubjectMapper(ModelMapper):
-
- {{ subject.name }}
+
+ {{ subject.name }}
+
- {{ subject.intro }}
diff --git "a/Day41-55/49.RESTful\346\236\266\346\236\204\345\222\214DRF\345\205\245\351\227\250.md" "b/Day41-55/49.RESTful\346\236\266\346\236\204\345\222\214DRF\345\205\245\351\227\250.md"
index 0004429fc..04eb692ad 100644
--- "a/Day41-55/49.RESTful\346\236\266\346\236\204\345\222\214DRF\345\205\245\351\227\250.md"
+++ "b/Day41-55/49.RESTful\346\236\266\346\236\204\345\222\214DRF\345\205\245\351\227\250.md"
@@ -156,48 +156,14 @@ urlpatterns = [
通过Vue.js渲染页面。
-```Python
+```HTML
老师信息
@@ -217,9 +183,11 @@ urlpatterns = [
{{ teacher.intro }}
@@ -355,7 +323,7 @@ JSON Web Token通常简称为JWT,它是一种开放标准(RFC 7519)。随
2. 在令牌过期之前,无法作废已经颁发的令牌,要解决这个问题,还需要额外的中间层和代码来辅助。
3. JWT是用户的身份令牌,一旦泄露,任何人都可以获得该用户的所有权限。为了降低令牌被盗用后产生的风险,JWT的有效期应该设置得比较短。对于一些比较重要的权限,使用时应通过其他方式再次对用户进行认证,例如短信验证码等。
-#### 使用PyJWT生成和验证令牌
+#### 使用PyJWT
在Python代码中,可以使用三方库`PyJWT`生成和验证JWT,下面是安装`PyJWT`的命令。
diff --git "a/Day76-90/code/.ipynb_checkpoints/1-pandas\345\205\245\351\227\250-checkpoint.ipynb" "b/Day76-90/code/.ipynb_checkpoints/1-pandas\345\205\245\351\227\250-checkpoint.ipynb"
index b5b3acc8b..d10293f1e 100644
--- "a/Day76-90/code/.ipynb_checkpoints/1-pandas\345\205\245\351\227\250-checkpoint.ipynb"
+++ "b/Day76-90/code/.ipynb_checkpoints/1-pandas\345\205\245\351\227\250-checkpoint.ipynb"
@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
- "execution_count": 2,
+ "execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
@@ -13,7 +13,7 @@
},
{
"cell_type": "code",
- "execution_count": 3,
+ "execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
@@ -22,14 +22,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": []
- },
- {
- "cell_type": "code",
- "execution_count": 4,
+ "execution_count": 5,
"metadata": {
"scrolled": false
},
@@ -44,7 +37,7 @@
"dtype: int64"
]
},
- "execution_count": 4,
+ "execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
@@ -52,13 +45,13 @@
"source": [
"# 创建\n",
"# Series是一维的数据\n",
- "s = Series(data = [120,136,128,99],index = ['Math','Python','En','Chinese'])\n",
+ "s = Series(data=[120,136,128,99], index=['Math','Python','En','Chinese'])\n",
"s"
]
},
{
"cell_type": "code",
- "execution_count": 5,
+ "execution_count": 6,
"metadata": {},
"outputs": [
{
@@ -67,7 +60,7 @@
"(4,)"
]
},
- "execution_count": 5,
+ "execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
@@ -78,16 +71,16 @@
},
{
"cell_type": "code",
- "execution_count": 6,
+ "execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
- "array([120, 136, 128, 99], dtype=int64)"
+ "array([120, 136, 128, 99])"
]
},
- "execution_count": 6,
+ "execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
@@ -99,7 +92,7 @@
},
{
"cell_type": "code",
- "execution_count": 7,
+ "execution_count": 8,
"metadata": {},
"outputs": [
{
@@ -108,7 +101,7 @@
"numpy.ndarray"
]
},
- "execution_count": 7,
+ "execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
@@ -119,7 +112,7 @@
},
{
"cell_type": "code",
- "execution_count": 8,
+ "execution_count": 9,
"metadata": {},
"outputs": [
{
@@ -128,7 +121,7 @@
"120.75"
]
},
- "execution_count": 8,
+ "execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
@@ -139,7 +132,7 @@
},
{
"cell_type": "code",
- "execution_count": 9,
+ "execution_count": 10,
"metadata": {},
"outputs": [
{
@@ -148,7 +141,7 @@
"136"
]
},
- "execution_count": 9,
+ "execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
@@ -159,7 +152,7 @@
},
{
"cell_type": "code",
- "execution_count": 10,
+ "execution_count": 11,
"metadata": {},
"outputs": [
{
@@ -168,7 +161,7 @@
"15.903353943953666"
]
},
- "execution_count": 10,
+ "execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
@@ -179,36 +172,33 @@
},
{
"cell_type": "code",
- "execution_count": 11,
- "metadata": {
- "collapsed": true
- },
+ "execution_count": 20,
+ "metadata": {},
"outputs": [
{
"data": {
"text/plain": [
- "Math 14400\n",
- "Python 18496\n",
- "En 16384\n",
- "Chinese 9801\n",
+ "Math 122\n",
+ "Python 138\n",
+ "En 130\n",
+ "Chinese 101\n",
"dtype: int64"
]
},
- "execution_count": 11,
+ "execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
- "s.pow(2)"
+ "s.add(1)\n",
+ "s"
]
},
{
"cell_type": "code",
- "execution_count": 12,
- "metadata": {
- "collapsed": true
- },
+ "execution_count": 21,
+ "metadata": {},
"outputs": [
{
"data": {
@@ -238,64 +228,64 @@
" \n",
" \n",
" \n",
- " a | \n",
- " 113 | \n",
- " 116 | \n",
- " 75 | \n",
+ " a | \n",
+ " 109 | \n",
+ " 120 | \n",
+ " 23 | \n",
"
\n",
" \n",
- " b | \n",
- " 19 | \n",
- " 145 | \n",
- " 23 | \n",
+ " b | \n",
+ " 54 | \n",
+ " 39 | \n",
+ " 54 | \n",
"
\n",
" \n",
- " c | \n",
- " 57 | \n",
- " 107 | \n",
- " 113 | \n",
+ " c | \n",
+ " 97 | \n",
+ " 22 | \n",
+ " 106 | \n",
"
\n",
" \n",
- " d | \n",
- " 95 | \n",
+ " d | \n",
+ " 21 | \n",
+ " 96 | \n",
" 3 | \n",
- " 66 | \n",
"
\n",
" \n",
- " e | \n",
- " 28 | \n",
- " 121 | \n",
- " 120 | \n",
+ " e | \n",
+ " 23 | \n",
+ " 145 | \n",
+ " 147 | \n",
"
\n",
" \n",
- " f | \n",
- " 141 | \n",
- " 85 | \n",
- " 132 | \n",
+ " f | \n",
+ " 80 | \n",
+ " 62 | \n",
+ " 83 | \n",
"
\n",
" \n",
- " h | \n",
- " 124 | \n",
- " 39 | \n",
- " 10 | \n",
+ " h | \n",
+ " 70 | \n",
+ " 31 | \n",
+ " 134 | \n",
"
\n",
" \n",
- " i | \n",
- " 80 | \n",
- " 35 | \n",
- " 17 | \n",
+ " i | \n",
+ " 132 | \n",
+ " 51 | \n",
+ " 115 | \n",
"
\n",
" \n",
- " j | \n",
- " 68 | \n",
- " 99 | \n",
- " 31 | \n",
+ " j | \n",
+ " 95 | \n",
+ " 143 | \n",
+ " 111 | \n",
"
\n",
" \n",
- " k | \n",
- " 74 | \n",
- " 12 | \n",
- " 11 | \n",
+ " k | \n",
+ " 66 | \n",
+ " 94 | \n",
+ " 7 | \n",
"
\n",
" \n",
"\n",
@@ -303,19 +293,19 @@
],
"text/plain": [
" Python En Math\n",
- "a 113 116 75\n",
- "b 19 145 23\n",
- "c 57 107 113\n",
- "d 95 3 66\n",
- "e 28 121 120\n",
- "f 141 85 132\n",
- "h 124 39 10\n",
- "i 80 35 17\n",
- "j 68 99 31\n",
- "k 74 12 11"
+ "a 109 120 23\n",
+ "b 54 39 54\n",
+ "c 97 22 106\n",
+ "d 21 96 3\n",
+ "e 23 145 147\n",
+ "f 80 62 83\n",
+ "h 70 31 134\n",
+ "i 132 51 115\n",
+ "j 95 143 111\n",
+ "k 66 94 7"
]
},
- "execution_count": 12,
+ "execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
@@ -324,7 +314,7 @@
"# DataFrame是二维的数据\n",
"# excel就非常相似\n",
"# 所有进行数据分析,数据挖掘的工具最基础的结果:行和列,行表示样本,列表示的是属性\n",
- "df = DataFrame(data = np.random.randint(0,150,size = (10,3)),index = list('abcdefhijk'),columns=['Python','En','Math'])\n",
+ "df = DataFrame(data=np.random.randint(0, 150, size=(10, 3)), index=list('abcdefhijk'), columns=['Python', 'En', 'Math'])\n",
"df"
]
},
@@ -553,7 +543,7 @@
},
{
"cell_type": "code",
- "execution_count": 19,
+ "execution_count": 22,
"metadata": {
"scrolled": true
},
@@ -561,50 +551,57 @@
{
"data": {
"text/plain": [
- "Python 79.9\n",
- "En 76.2\n",
- "Math 59.8\n",
+ "Python 74.7\n",
+ "En 80.3\n",
+ "Math 78.3\n",
"dtype: float64"
]
},
- "execution_count": 19,
+ "execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
- "df.mean(axis = 0)"
+ "df.mean(axis=0)"
]
},
{
"cell_type": "code",
- "execution_count": 20,
+ "execution_count": 23,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
- "a 101.333333\n",
- "b 62.333333\n",
- "c 92.333333\n",
- "d 54.666667\n",
- "e 89.666667\n",
- "f 119.333333\n",
- "h 57.666667\n",
- "i 44.000000\n",
- "j 66.000000\n",
- "k 32.333333\n",
+ "a 84.000000\n",
+ "b 49.000000\n",
+ "c 75.000000\n",
+ "d 40.000000\n",
+ "e 105.000000\n",
+ "f 75.000000\n",
+ "h 78.333333\n",
+ "i 99.333333\n",
+ "j 116.333333\n",
+ "k 55.666667\n",
"dtype: float64"
]
},
- "execution_count": 20,
+ "execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
- "df.mean(axis = 1)"
+ "df.mean(axis=1)"
]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": []
}
],
"metadata": {
@@ -623,7 +620,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.7.3"
+ "version": "3.7.7"
}
},
"nbformat": 4,
diff --git "a/Day76-90/code/.ipynb_checkpoints/2-pandas-\347\264\242\345\274\225-checkpoint.ipynb" "b/Day76-90/code/.ipynb_checkpoints/2-pandas-\347\264\242\345\274\225-checkpoint.ipynb"
new file mode 100644
index 000000000..98c1704a5
--- /dev/null
+++ "b/Day76-90/code/.ipynb_checkpoints/2-pandas-\347\264\242\345\274\225-checkpoint.ipynb"
@@ -0,0 +1,372 @@
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "import numpy as np\n",
+ "\n",
+ "import pandas as pd\n",
+ "\n",
+ "from pandas import Series, DataFrame"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "s = Series(np.random.randint(0,150,size = 100),index = np.arange(10,110),dtype=np.int16,name = 'Python')\n",
+ "s"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "s[10]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "s[[10,20]]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# 切片操作\n",
+ "s[10:20]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "s[::2]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "s[::-2]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# 可以使用pandas为开发者提供方法,去进行检索\n",
+ "s.loc[10]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [],
+ "source": [
+ "s.loc[[10,20]]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "s.loc[10:20]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "s.loc[::2]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "s.loc[::-2]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "s.index"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# iloc 索引从0开始,数字化自然索引\n",
+ "s.iloc[0]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "s.iloc[[0,10]]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "s.iloc[0:20]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "s.iloc[::-2]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# DataFrame是二维,索引大同小异,\n",
+ "df = DataFrame(data = np.random.randint(0,150,size= (10,3)),index=list('ABCDEFHIJK'),columns=['Python','En','Math'])\n",
+ "\n",
+ "df"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "df['A']"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "df['Python']"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "df[['Python','En']]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [],
+ "source": [
+ "df['Python':'Math']"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "df['A':'D']"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "df.loc['Python']"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [],
+ "source": [
+ "df.loc['A']"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "df.loc[['A','H']]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "df.loc['A':'E']"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "df.loc[::2]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "df.loc[::-2]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "df.iloc['A']"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "df.iloc[0]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [],
+ "source": [
+ "df.iloc[[0,5]]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "df.iloc[0:5]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [],
+ "source": [
+ "df.iloc[::-2]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [],
+ "source": [
+ "df"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "df.iloc[::2,1:]"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 3",
+ "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.7.7"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}
diff --git "a/Day76-90/code/.ipynb_checkpoints/3-pandas\346\225\260\346\215\256\346\270\205\346\264\227\344\271\213\347\251\272\346\225\260\346\215\256-checkpoint.ipynb" "b/Day76-90/code/.ipynb_checkpoints/3-pandas\346\225\260\346\215\256\346\270\205\346\264\227\344\271\213\347\251\272\346\225\260\346\215\256-checkpoint.ipynb"
new file mode 100644
index 000000000..17346ba23
--- /dev/null
+++ "b/Day76-90/code/.ipynb_checkpoints/3-pandas\346\225\260\346\215\256\346\270\205\346\264\227\344\271\213\347\251\272\346\225\260\346\215\256-checkpoint.ipynb"
@@ -0,0 +1,5834 @@
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "import numpy as np\n",
+ "\n",
+ "import pandas as pd\n",
+ "\n",
+ "from pandas import Series,DataFrame"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Python | \n",
+ " En | \n",
+ " Math | \n",
+ " Physic | \n",
+ " Chem | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " 100 | \n",
+ " 4 | \n",
+ " 55 | \n",
+ " 0 | \n",
+ " 79 | \n",
+ " 129 | \n",
+ "
\n",
+ " \n",
+ " 101 | \n",
+ " 72 | \n",
+ " 82 | \n",
+ " 57 | \n",
+ " 138 | \n",
+ " 111 | \n",
+ "
\n",
+ " \n",
+ " 102 | \n",
+ " 54 | \n",
+ " 115 | \n",
+ " 81 | \n",
+ " 81 | \n",
+ " 51 | \n",
+ "
\n",
+ " \n",
+ " 103 | \n",
+ " 13 | \n",
+ " 80 | \n",
+ " 54 | \n",
+ " 129 | \n",
+ " 40 | \n",
+ "
\n",
+ " \n",
+ " 104 | \n",
+ " 113 | \n",
+ " 91 | \n",
+ " 39 | \n",
+ " 34 | \n",
+ " 98 | \n",
+ "
\n",
+ " \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ "
\n",
+ " \n",
+ " 195 | \n",
+ " 135 | \n",
+ " 104 | \n",
+ " 102 | \n",
+ " 76 | \n",
+ " 40 | \n",
+ "
\n",
+ " \n",
+ " 196 | \n",
+ " 75 | \n",
+ " 72 | \n",
+ " 28 | \n",
+ " 39 | \n",
+ " 31 | \n",
+ "
\n",
+ " \n",
+ " 197 | \n",
+ " 136 | \n",
+ " 26 | \n",
+ " 123 | \n",
+ " 62 | \n",
+ " 81 | \n",
+ "
\n",
+ " \n",
+ " 198 | \n",
+ " 50 | \n",
+ " 48 | \n",
+ " 103 | \n",
+ " 60 | \n",
+ " 6 | \n",
+ "
\n",
+ " \n",
+ " 199 | \n",
+ " 77 | \n",
+ " 13 | \n",
+ " 91 | \n",
+ " 145 | \n",
+ " 147 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
100 rows × 5 columns
\n",
+ "
"
+ ],
+ "text/plain": [
+ " Python En Math Physic Chem\n",
+ "100 4 55 0 79 129\n",
+ "101 72 82 57 138 111\n",
+ "102 54 115 81 81 51\n",
+ "103 13 80 54 129 40\n",
+ "104 113 91 39 34 98\n",
+ ".. ... ... ... ... ...\n",
+ "195 135 104 102 76 40\n",
+ "196 75 72 28 39 31\n",
+ "197 136 26 123 62 81\n",
+ "198 50 48 103 60 6\n",
+ "199 77 13 91 145 147\n",
+ "\n",
+ "[100 rows x 5 columns]"
+ ]
+ },
+ "execution_count": 6,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "df = DataFrame(np.random.randint(0,150,size = (100,5)),index = np.arange(100,200),columns=['Python','En','Math','Physic','Chem'])\n",
+ "df\n",
+ "df[100]['Python']"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "Python False\n",
+ "En False\n",
+ "Math False\n",
+ "Physic False\n",
+ "Chem False\n",
+ "dtype: bool"
+ ]
+ },
+ "execution_count": 3,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "# 判断DataFrame是否存在空数据\n",
+ "df.isnull().any()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "Python True\n",
+ "En True\n",
+ "Math True\n",
+ "Physic True\n",
+ "Chem True\n",
+ "dtype: bool"
+ ]
+ },
+ "execution_count": 6,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "df.notnull().all()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 12,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "500"
+ ]
+ },
+ "execution_count": 12,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "100*5"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 13,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "for i in range(50):\n",
+ " # 行索引\n",
+ " index = np.random.randint(100,200,size =1)[0]\n",
+ "\n",
+ " cols = df.columns\n",
+ "\n",
+ " # 列索引\n",
+ " col = np.random.choice(cols)\n",
+ "\n",
+ " df.loc[index,col] = None"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 15,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "for i in range(20):\n",
+ " # 行索引\n",
+ " index = np.random.randint(100,200,size =1)[0]\n",
+ "\n",
+ " cols = df.columns\n",
+ "\n",
+ " # 列索引\n",
+ " col = np.random.choice(cols)\n",
+ "\n",
+ "# not a number 不是一个数\n",
+ " df.loc[index,col] = np.NAN"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 16,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Python | \n",
+ " En | \n",
+ " Math | \n",
+ " Physic | \n",
+ " Chem | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " 100 | \n",
+ " 122.0 | \n",
+ " 10.0 | \n",
+ " 5.0 | \n",
+ " 28.0 | \n",
+ " 57.0 | \n",
+ "
\n",
+ " \n",
+ " 101 | \n",
+ " NaN | \n",
+ " 129.0 | \n",
+ " 16.0 | \n",
+ " 114.0 | \n",
+ " 26.0 | \n",
+ "
\n",
+ " \n",
+ " 102 | \n",
+ " 97.0 | \n",
+ " 121.0 | \n",
+ " 122.0 | \n",
+ " 29.0 | \n",
+ " 65.0 | \n",
+ "
\n",
+ " \n",
+ " 103 | \n",
+ " 141.0 | \n",
+ " 73.0 | \n",
+ " 120.0 | \n",
+ " 147.0 | \n",
+ " 1.0 | \n",
+ "
\n",
+ " \n",
+ " 104 | \n",
+ " 126.0 | \n",
+ " NaN | \n",
+ " 86.0 | \n",
+ " 116.0 | \n",
+ " 17.0 | \n",
+ "
\n",
+ " \n",
+ " 105 | \n",
+ " 85.0 | \n",
+ " NaN | \n",
+ " 42.0 | \n",
+ " 121.0 | \n",
+ " 66.0 | \n",
+ "
\n",
+ " \n",
+ " 106 | \n",
+ " 142.0 | \n",
+ " 65.0 | \n",
+ " 1.0 | \n",
+ " 124.0 | \n",
+ " 83.0 | \n",
+ "
\n",
+ " \n",
+ " 107 | \n",
+ " 136.0 | \n",
+ " 141.0 | \n",
+ " NaN | \n",
+ " 86.0 | \n",
+ " 113.0 | \n",
+ "
\n",
+ " \n",
+ " 108 | \n",
+ " 15.0 | \n",
+ " 37.0 | \n",
+ " 124.0 | \n",
+ " 110.0 | \n",
+ " 102.0 | \n",
+ "
\n",
+ " \n",
+ " 109 | \n",
+ " 63.0 | \n",
+ " 30.0 | \n",
+ " NaN | \n",
+ " 69.0 | \n",
+ " 58.0 | \n",
+ "
\n",
+ " \n",
+ " 110 | \n",
+ " NaN | \n",
+ " NaN | \n",
+ " 113.0 | \n",
+ " 109.0 | \n",
+ " 16.0 | \n",
+ "
\n",
+ " \n",
+ " 111 | \n",
+ " 5.0 | \n",
+ " 51.0 | \n",
+ " 87.0 | \n",
+ " 58.0 | \n",
+ " 126.0 | \n",
+ "
\n",
+ " \n",
+ " 112 | \n",
+ " 53.0 | \n",
+ " 97.0 | \n",
+ " 76.0 | \n",
+ " 37.0 | \n",
+ " 45.0 | \n",
+ "
\n",
+ " \n",
+ " 113 | \n",
+ " 42.0 | \n",
+ " 148.0 | \n",
+ " NaN | \n",
+ " 97.0 | \n",
+ " NaN | \n",
+ "
\n",
+ " \n",
+ " 114 | \n",
+ " 70.0 | \n",
+ " 138.0 | \n",
+ " 69.0 | \n",
+ " 68.0 | \n",
+ " 134.0 | \n",
+ "
\n",
+ " \n",
+ " 115 | \n",
+ " NaN | \n",
+ " 136.0 | \n",
+ " 113.0 | \n",
+ " 22.0 | \n",
+ " 94.0 | \n",
+ "
\n",
+ " \n",
+ " 116 | \n",
+ " 31.0 | \n",
+ " 137.0 | \n",
+ " 6.0 | \n",
+ " 20.0 | \n",
+ " 28.0 | \n",
+ "
\n",
+ " \n",
+ " 117 | \n",
+ " 148.0 | \n",
+ " 74.0 | \n",
+ " 134.0 | \n",
+ " 4.0 | \n",
+ " 124.0 | \n",
+ "
\n",
+ " \n",
+ " 118 | \n",
+ " 102.0 | \n",
+ " 81.0 | \n",
+ " 138.0 | \n",
+ " 128.0 | \n",
+ " 32.0 | \n",
+ "
\n",
+ " \n",
+ " 119 | \n",
+ " 27.0 | \n",
+ " 111.0 | \n",
+ " 13.0 | \n",
+ " NaN | \n",
+ " 22.0 | \n",
+ "
\n",
+ " \n",
+ " 120 | \n",
+ " 28.0 | \n",
+ " 93.0 | \n",
+ " 121.0 | \n",
+ " NaN | \n",
+ " 4.0 | \n",
+ "
\n",
+ " \n",
+ " 121 | \n",
+ " 136.0 | \n",
+ " NaN | \n",
+ " 25.0 | \n",
+ " 97.0 | \n",
+ " 19.0 | \n",
+ "
\n",
+ " \n",
+ " 122 | \n",
+ " 111.0 | \n",
+ " 70.0 | \n",
+ " 12.0 | \n",
+ " 38.0 | \n",
+ " 58.0 | \n",
+ "
\n",
+ " \n",
+ " 123 | \n",
+ " NaN | \n",
+ " 103.0 | \n",
+ " 147.0 | \n",
+ " 86.0 | \n",
+ " 8.0 | \n",
+ "
\n",
+ " \n",
+ " 124 | \n",
+ " 10.0 | \n",
+ " 10.0 | \n",
+ " 46.0 | \n",
+ " 63.0 | \n",
+ " 149.0 | \n",
+ "
\n",
+ " \n",
+ " 125 | \n",
+ " 7.0 | \n",
+ " 75.0 | \n",
+ " 97.0 | \n",
+ " 108.0 | \n",
+ " 31.0 | \n",
+ "
\n",
+ " \n",
+ " 126 | \n",
+ " 88.0 | \n",
+ " 6.0 | \n",
+ " NaN | \n",
+ " NaN | \n",
+ " 55.0 | \n",
+ "
\n",
+ " \n",
+ " 127 | \n",
+ " 33.0 | \n",
+ " 74.0 | \n",
+ " 106.0 | \n",
+ " 50.0 | \n",
+ " 46.0 | \n",
+ "
\n",
+ " \n",
+ " 128 | \n",
+ " 74.0 | \n",
+ " 28.0 | \n",
+ " 26.0 | \n",
+ " 100.0 | \n",
+ " 76.0 | \n",
+ "
\n",
+ " \n",
+ " 129 | \n",
+ " 76.0 | \n",
+ " 18.0 | \n",
+ " 101.0 | \n",
+ " NaN | \n",
+ " NaN | \n",
+ "
\n",
+ " \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ "
\n",
+ " \n",
+ " 170 | \n",
+ " 144.0 | \n",
+ " 124.0 | \n",
+ " 77.0 | \n",
+ " 92.0 | \n",
+ " 82.0 | \n",
+ "
\n",
+ " \n",
+ " 171 | \n",
+ " 36.0 | \n",
+ " 98.0 | \n",
+ " NaN | \n",
+ " 43.0 | \n",
+ " 80.0 | \n",
+ "
\n",
+ " \n",
+ " 172 | \n",
+ " 51.0 | \n",
+ " NaN | \n",
+ " 68.0 | \n",
+ " 34.0 | \n",
+ " 74.0 | \n",
+ "
\n",
+ " \n",
+ " 173 | \n",
+ " 149.0 | \n",
+ " NaN | \n",
+ " 18.0 | \n",
+ " 141.0 | \n",
+ " NaN | \n",
+ "
\n",
+ " \n",
+ " 174 | \n",
+ " 8.0 | \n",
+ " 139.0 | \n",
+ " 146.0 | \n",
+ " 112.0 | \n",
+ " NaN | \n",
+ "
\n",
+ " \n",
+ " 175 | \n",
+ " 115.0 | \n",
+ " NaN | \n",
+ " 64.0 | \n",
+ " 62.0 | \n",
+ " 9.0 | \n",
+ "
\n",
+ " \n",
+ " 176 | \n",
+ " NaN | \n",
+ " 7.0 | \n",
+ " 140.0 | \n",
+ " 45.0 | \n",
+ " 148.0 | \n",
+ "
\n",
+ " \n",
+ " 177 | \n",
+ " NaN | \n",
+ " 43.0 | \n",
+ " 68.0 | \n",
+ " 109.0 | \n",
+ " 18.0 | \n",
+ "
\n",
+ " \n",
+ " 178 | \n",
+ " 31.0 | \n",
+ " 100.0 | \n",
+ " NaN | \n",
+ " 49.0 | \n",
+ " 123.0 | \n",
+ "
\n",
+ " \n",
+ " 179 | \n",
+ " 29.0 | \n",
+ " 46.0 | \n",
+ " 69.0 | \n",
+ " 57.0 | \n",
+ " 90.0 | \n",
+ "
\n",
+ " \n",
+ " 180 | \n",
+ " 146.0 | \n",
+ " 86.0 | \n",
+ " 18.0 | \n",
+ " 22.0 | \n",
+ " 46.0 | \n",
+ "
\n",
+ " \n",
+ " 181 | \n",
+ " 71.0 | \n",
+ " 50.0 | \n",
+ " 40.0 | \n",
+ " NaN | \n",
+ " 140.0 | \n",
+ "
\n",
+ " \n",
+ " 182 | \n",
+ " 4.0 | \n",
+ " 100.0 | \n",
+ " 147.0 | \n",
+ " 116.0 | \n",
+ " 110.0 | \n",
+ "
\n",
+ " \n",
+ " 183 | \n",
+ " 55.0 | \n",
+ " 87.0 | \n",
+ " 93.0 | \n",
+ " NaN | \n",
+ " 34.0 | \n",
+ "
\n",
+ " \n",
+ " 184 | \n",
+ " NaN | \n",
+ " 109.0 | \n",
+ " 124.0 | \n",
+ " 87.0 | \n",
+ " 82.0 | \n",
+ "
\n",
+ " \n",
+ " 185 | \n",
+ " 10.0 | \n",
+ " 118.0 | \n",
+ " 139.0 | \n",
+ " 50.0 | \n",
+ " 51.0 | \n",
+ "
\n",
+ " \n",
+ " 186 | \n",
+ " 32.0 | \n",
+ " 12.0 | \n",
+ " 71.0 | \n",
+ " 36.0 | \n",
+ " NaN | \n",
+ "
\n",
+ " \n",
+ " 187 | \n",
+ " 94.0 | \n",
+ " NaN | \n",
+ " 138.0 | \n",
+ " 13.0 | \n",
+ " 149.0 | \n",
+ "
\n",
+ " \n",
+ " 188 | \n",
+ " 65.0 | \n",
+ " 101.0 | \n",
+ " 123.0 | \n",
+ " 128.0 | \n",
+ " 86.0 | \n",
+ "
\n",
+ " \n",
+ " 189 | \n",
+ " 43.0 | \n",
+ " 94.0 | \n",
+ " NaN | \n",
+ " 29.0 | \n",
+ " 132.0 | \n",
+ "
\n",
+ " \n",
+ " 190 | \n",
+ " 68.0 | \n",
+ " 135.0 | \n",
+ " 94.0 | \n",
+ " 28.0 | \n",
+ " 125.0 | \n",
+ "
\n",
+ " \n",
+ " 191 | \n",
+ " 30.0 | \n",
+ " 60.0 | \n",
+ " 98.0 | \n",
+ " NaN | \n",
+ " 15.0 | \n",
+ "
\n",
+ " \n",
+ " 192 | \n",
+ " 89.0 | \n",
+ " 16.0 | \n",
+ " 10.0 | \n",
+ " 135.0 | \n",
+ " 4.0 | \n",
+ "
\n",
+ " \n",
+ " 193 | \n",
+ " 104.0 | \n",
+ " 139.0 | \n",
+ " 97.0 | \n",
+ " 29.0 | \n",
+ " 17.0 | \n",
+ "
\n",
+ " \n",
+ " 194 | \n",
+ " 5.0 | \n",
+ " 29.0 | \n",
+ " 41.0 | \n",
+ " 99.0 | \n",
+ " NaN | \n",
+ "
\n",
+ " \n",
+ " 195 | \n",
+ " 19.0 | \n",
+ " 102.0 | \n",
+ " 135.0 | \n",
+ " 41.0 | \n",
+ " 40.0 | \n",
+ "
\n",
+ " \n",
+ " 196 | \n",
+ " 58.0 | \n",
+ " NaN | \n",
+ " 70.0 | \n",
+ " 82.0 | \n",
+ " 64.0 | \n",
+ "
\n",
+ " \n",
+ " 197 | \n",
+ " NaN | \n",
+ " 97.0 | \n",
+ " 129.0 | \n",
+ " 76.0 | \n",
+ " 13.0 | \n",
+ "
\n",
+ " \n",
+ " 198 | \n",
+ " 131.0 | \n",
+ " 15.0 | \n",
+ " NaN | \n",
+ " 44.0 | \n",
+ " 114.0 | \n",
+ "
\n",
+ " \n",
+ " 199 | \n",
+ " 79.0 | \n",
+ " NaN | \n",
+ " 95.0 | \n",
+ " 128.0 | \n",
+ " NaN | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
100 rows × 5 columns
\n",
+ "
"
+ ],
+ "text/plain": [
+ " Python En Math Physic Chem\n",
+ "100 122.0 10.0 5.0 28.0 57.0\n",
+ "101 NaN 129.0 16.0 114.0 26.0\n",
+ "102 97.0 121.0 122.0 29.0 65.0\n",
+ "103 141.0 73.0 120.0 147.0 1.0\n",
+ "104 126.0 NaN 86.0 116.0 17.0\n",
+ "105 85.0 NaN 42.0 121.0 66.0\n",
+ "106 142.0 65.0 1.0 124.0 83.0\n",
+ "107 136.0 141.0 NaN 86.0 113.0\n",
+ "108 15.0 37.0 124.0 110.0 102.0\n",
+ "109 63.0 30.0 NaN 69.0 58.0\n",
+ "110 NaN NaN 113.0 109.0 16.0\n",
+ "111 5.0 51.0 87.0 58.0 126.0\n",
+ "112 53.0 97.0 76.0 37.0 45.0\n",
+ "113 42.0 148.0 NaN 97.0 NaN\n",
+ "114 70.0 138.0 69.0 68.0 134.0\n",
+ "115 NaN 136.0 113.0 22.0 94.0\n",
+ "116 31.0 137.0 6.0 20.0 28.0\n",
+ "117 148.0 74.0 134.0 4.0 124.0\n",
+ "118 102.0 81.0 138.0 128.0 32.0\n",
+ "119 27.0 111.0 13.0 NaN 22.0\n",
+ "120 28.0 93.0 121.0 NaN 4.0\n",
+ "121 136.0 NaN 25.0 97.0 19.0\n",
+ "122 111.0 70.0 12.0 38.0 58.0\n",
+ "123 NaN 103.0 147.0 86.0 8.0\n",
+ "124 10.0 10.0 46.0 63.0 149.0\n",
+ "125 7.0 75.0 97.0 108.0 31.0\n",
+ "126 88.0 6.0 NaN NaN 55.0\n",
+ "127 33.0 74.0 106.0 50.0 46.0\n",
+ "128 74.0 28.0 26.0 100.0 76.0\n",
+ "129 76.0 18.0 101.0 NaN NaN\n",
+ ".. ... ... ... ... ...\n",
+ "170 144.0 124.0 77.0 92.0 82.0\n",
+ "171 36.0 98.0 NaN 43.0 80.0\n",
+ "172 51.0 NaN 68.0 34.0 74.0\n",
+ "173 149.0 NaN 18.0 141.0 NaN\n",
+ "174 8.0 139.0 146.0 112.0 NaN\n",
+ "175 115.0 NaN 64.0 62.0 9.0\n",
+ "176 NaN 7.0 140.0 45.0 148.0\n",
+ "177 NaN 43.0 68.0 109.0 18.0\n",
+ "178 31.0 100.0 NaN 49.0 123.0\n",
+ "179 29.0 46.0 69.0 57.0 90.0\n",
+ "180 146.0 86.0 18.0 22.0 46.0\n",
+ "181 71.0 50.0 40.0 NaN 140.0\n",
+ "182 4.0 100.0 147.0 116.0 110.0\n",
+ "183 55.0 87.0 93.0 NaN 34.0\n",
+ "184 NaN 109.0 124.0 87.0 82.0\n",
+ "185 10.0 118.0 139.0 50.0 51.0\n",
+ "186 32.0 12.0 71.0 36.0 NaN\n",
+ "187 94.0 NaN 138.0 13.0 149.0\n",
+ "188 65.0 101.0 123.0 128.0 86.0\n",
+ "189 43.0 94.0 NaN 29.0 132.0\n",
+ "190 68.0 135.0 94.0 28.0 125.0\n",
+ "191 30.0 60.0 98.0 NaN 15.0\n",
+ "192 89.0 16.0 10.0 135.0 4.0\n",
+ "193 104.0 139.0 97.0 29.0 17.0\n",
+ "194 5.0 29.0 41.0 99.0 NaN\n",
+ "195 19.0 102.0 135.0 41.0 40.0\n",
+ "196 58.0 NaN 70.0 82.0 64.0\n",
+ "197 NaN 97.0 129.0 76.0 13.0\n",
+ "198 131.0 15.0 NaN 44.0 114.0\n",
+ "199 79.0 NaN 95.0 128.0 NaN\n",
+ "\n",
+ "[100 rows x 5 columns]"
+ ]
+ },
+ "execution_count": 16,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "df"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 18,
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "Python True\n",
+ "En True\n",
+ "Math True\n",
+ "Physic True\n",
+ "Chem True\n",
+ "dtype: bool"
+ ]
+ },
+ "execution_count": 18,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "df.isnull().any()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 22,
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "Python 14\n",
+ "En 14\n",
+ "Math 15\n",
+ "Physic 11\n",
+ "Chem 13\n",
+ "dtype: int64"
+ ]
+ },
+ "execution_count": 22,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "df.isnull().sum()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 23,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "df2 = df.copy()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 24,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "Python 14\n",
+ "En 14\n",
+ "Math 15\n",
+ "Physic 11\n",
+ "Chem 13\n",
+ "dtype: int64"
+ ]
+ },
+ "execution_count": 24,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "df2.isnull().sum()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 26,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Python | \n",
+ " En | \n",
+ " Math | \n",
+ " Physic | \n",
+ " Chem | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " 100 | \n",
+ " 122.0 | \n",
+ " 10.0 | \n",
+ " 5.0 | \n",
+ " 28.0 | \n",
+ " 57.0 | \n",
+ "
\n",
+ " \n",
+ " 101 | \n",
+ " 100.0 | \n",
+ " 129.0 | \n",
+ " 16.0 | \n",
+ " 114.0 | \n",
+ " 26.0 | \n",
+ "
\n",
+ " \n",
+ " 102 | \n",
+ " 97.0 | \n",
+ " 121.0 | \n",
+ " 122.0 | \n",
+ " 29.0 | \n",
+ " 65.0 | \n",
+ "
\n",
+ " \n",
+ " 103 | \n",
+ " 141.0 | \n",
+ " 73.0 | \n",
+ " 120.0 | \n",
+ " 147.0 | \n",
+ " 1.0 | \n",
+ "
\n",
+ " \n",
+ " 104 | \n",
+ " 126.0 | \n",
+ " 100.0 | \n",
+ " 86.0 | \n",
+ " 116.0 | \n",
+ " 17.0 | \n",
+ "
\n",
+ " \n",
+ " 105 | \n",
+ " 85.0 | \n",
+ " 100.0 | \n",
+ " 42.0 | \n",
+ " 121.0 | \n",
+ " 66.0 | \n",
+ "
\n",
+ " \n",
+ " 106 | \n",
+ " 142.0 | \n",
+ " 65.0 | \n",
+ " 1.0 | \n",
+ " 124.0 | \n",
+ " 83.0 | \n",
+ "
\n",
+ " \n",
+ " 107 | \n",
+ " 136.0 | \n",
+ " 141.0 | \n",
+ " 100.0 | \n",
+ " 86.0 | \n",
+ " 113.0 | \n",
+ "
\n",
+ " \n",
+ " 108 | \n",
+ " 15.0 | \n",
+ " 37.0 | \n",
+ " 124.0 | \n",
+ " 110.0 | \n",
+ " 102.0 | \n",
+ "
\n",
+ " \n",
+ " 109 | \n",
+ " 63.0 | \n",
+ " 30.0 | \n",
+ " 100.0 | \n",
+ " 69.0 | \n",
+ " 58.0 | \n",
+ "
\n",
+ " \n",
+ " 110 | \n",
+ " 100.0 | \n",
+ " 100.0 | \n",
+ " 113.0 | \n",
+ " 109.0 | \n",
+ " 16.0 | \n",
+ "
\n",
+ " \n",
+ " 111 | \n",
+ " 5.0 | \n",
+ " 51.0 | \n",
+ " 87.0 | \n",
+ " 58.0 | \n",
+ " 126.0 | \n",
+ "
\n",
+ " \n",
+ " 112 | \n",
+ " 53.0 | \n",
+ " 97.0 | \n",
+ " 76.0 | \n",
+ " 37.0 | \n",
+ " 45.0 | \n",
+ "
\n",
+ " \n",
+ " 113 | \n",
+ " 42.0 | \n",
+ " 148.0 | \n",
+ " 100.0 | \n",
+ " 97.0 | \n",
+ " 100.0 | \n",
+ "
\n",
+ " \n",
+ " 114 | \n",
+ " 70.0 | \n",
+ " 138.0 | \n",
+ " 69.0 | \n",
+ " 68.0 | \n",
+ " 134.0 | \n",
+ "
\n",
+ " \n",
+ " 115 | \n",
+ " 100.0 | \n",
+ " 136.0 | \n",
+ " 113.0 | \n",
+ " 22.0 | \n",
+ " 94.0 | \n",
+ "
\n",
+ " \n",
+ " 116 | \n",
+ " 31.0 | \n",
+ " 137.0 | \n",
+ " 6.0 | \n",
+ " 20.0 | \n",
+ " 28.0 | \n",
+ "
\n",
+ " \n",
+ " 117 | \n",
+ " 148.0 | \n",
+ " 74.0 | \n",
+ " 134.0 | \n",
+ " 4.0 | \n",
+ " 124.0 | \n",
+ "
\n",
+ " \n",
+ " 118 | \n",
+ " 102.0 | \n",
+ " 81.0 | \n",
+ " 138.0 | \n",
+ " 128.0 | \n",
+ " 32.0 | \n",
+ "
\n",
+ " \n",
+ " 119 | \n",
+ " 27.0 | \n",
+ " 111.0 | \n",
+ " 13.0 | \n",
+ " 100.0 | \n",
+ " 22.0 | \n",
+ "
\n",
+ " \n",
+ " 120 | \n",
+ " 28.0 | \n",
+ " 93.0 | \n",
+ " 121.0 | \n",
+ " 100.0 | \n",
+ " 4.0 | \n",
+ "
\n",
+ " \n",
+ " 121 | \n",
+ " 136.0 | \n",
+ " 100.0 | \n",
+ " 25.0 | \n",
+ " 97.0 | \n",
+ " 19.0 | \n",
+ "
\n",
+ " \n",
+ " 122 | \n",
+ " 111.0 | \n",
+ " 70.0 | \n",
+ " 12.0 | \n",
+ " 38.0 | \n",
+ " 58.0 | \n",
+ "
\n",
+ " \n",
+ " 123 | \n",
+ " 100.0 | \n",
+ " 103.0 | \n",
+ " 147.0 | \n",
+ " 86.0 | \n",
+ " 8.0 | \n",
+ "
\n",
+ " \n",
+ " 124 | \n",
+ " 10.0 | \n",
+ " 10.0 | \n",
+ " 46.0 | \n",
+ " 63.0 | \n",
+ " 149.0 | \n",
+ "
\n",
+ " \n",
+ " 125 | \n",
+ " 7.0 | \n",
+ " 75.0 | \n",
+ " 97.0 | \n",
+ " 108.0 | \n",
+ " 31.0 | \n",
+ "
\n",
+ " \n",
+ " 126 | \n",
+ " 88.0 | \n",
+ " 6.0 | \n",
+ " 100.0 | \n",
+ " 100.0 | \n",
+ " 55.0 | \n",
+ "
\n",
+ " \n",
+ " 127 | \n",
+ " 33.0 | \n",
+ " 74.0 | \n",
+ " 106.0 | \n",
+ " 50.0 | \n",
+ " 46.0 | \n",
+ "
\n",
+ " \n",
+ " 128 | \n",
+ " 74.0 | \n",
+ " 28.0 | \n",
+ " 26.0 | \n",
+ " 100.0 | \n",
+ " 76.0 | \n",
+ "
\n",
+ " \n",
+ " 129 | \n",
+ " 76.0 | \n",
+ " 18.0 | \n",
+ " 101.0 | \n",
+ " 100.0 | \n",
+ " 100.0 | \n",
+ "
\n",
+ " \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ "
\n",
+ " \n",
+ " 170 | \n",
+ " 144.0 | \n",
+ " 124.0 | \n",
+ " 77.0 | \n",
+ " 92.0 | \n",
+ " 82.0 | \n",
+ "
\n",
+ " \n",
+ " 171 | \n",
+ " 36.0 | \n",
+ " 98.0 | \n",
+ " 100.0 | \n",
+ " 43.0 | \n",
+ " 80.0 | \n",
+ "
\n",
+ " \n",
+ " 172 | \n",
+ " 51.0 | \n",
+ " 100.0 | \n",
+ " 68.0 | \n",
+ " 34.0 | \n",
+ " 74.0 | \n",
+ "
\n",
+ " \n",
+ " 173 | \n",
+ " 149.0 | \n",
+ " 100.0 | \n",
+ " 18.0 | \n",
+ " 141.0 | \n",
+ " 100.0 | \n",
+ "
\n",
+ " \n",
+ " 174 | \n",
+ " 8.0 | \n",
+ " 139.0 | \n",
+ " 146.0 | \n",
+ " 112.0 | \n",
+ " 100.0 | \n",
+ "
\n",
+ " \n",
+ " 175 | \n",
+ " 115.0 | \n",
+ " 100.0 | \n",
+ " 64.0 | \n",
+ " 62.0 | \n",
+ " 9.0 | \n",
+ "
\n",
+ " \n",
+ " 176 | \n",
+ " 100.0 | \n",
+ " 7.0 | \n",
+ " 140.0 | \n",
+ " 45.0 | \n",
+ " 148.0 | \n",
+ "
\n",
+ " \n",
+ " 177 | \n",
+ " 100.0 | \n",
+ " 43.0 | \n",
+ " 68.0 | \n",
+ " 109.0 | \n",
+ " 18.0 | \n",
+ "
\n",
+ " \n",
+ " 178 | \n",
+ " 31.0 | \n",
+ " 100.0 | \n",
+ " 100.0 | \n",
+ " 49.0 | \n",
+ " 123.0 | \n",
+ "
\n",
+ " \n",
+ " 179 | \n",
+ " 29.0 | \n",
+ " 46.0 | \n",
+ " 69.0 | \n",
+ " 57.0 | \n",
+ " 90.0 | \n",
+ "
\n",
+ " \n",
+ " 180 | \n",
+ " 146.0 | \n",
+ " 86.0 | \n",
+ " 18.0 | \n",
+ " 22.0 | \n",
+ " 46.0 | \n",
+ "
\n",
+ " \n",
+ " 181 | \n",
+ " 71.0 | \n",
+ " 50.0 | \n",
+ " 40.0 | \n",
+ " 100.0 | \n",
+ " 140.0 | \n",
+ "
\n",
+ " \n",
+ " 182 | \n",
+ " 4.0 | \n",
+ " 100.0 | \n",
+ " 147.0 | \n",
+ " 116.0 | \n",
+ " 110.0 | \n",
+ "
\n",
+ " \n",
+ " 183 | \n",
+ " 55.0 | \n",
+ " 87.0 | \n",
+ " 93.0 | \n",
+ " 100.0 | \n",
+ " 34.0 | \n",
+ "
\n",
+ " \n",
+ " 184 | \n",
+ " 100.0 | \n",
+ " 109.0 | \n",
+ " 124.0 | \n",
+ " 87.0 | \n",
+ " 82.0 | \n",
+ "
\n",
+ " \n",
+ " 185 | \n",
+ " 10.0 | \n",
+ " 118.0 | \n",
+ " 139.0 | \n",
+ " 50.0 | \n",
+ " 51.0 | \n",
+ "
\n",
+ " \n",
+ " 186 | \n",
+ " 32.0 | \n",
+ " 12.0 | \n",
+ " 71.0 | \n",
+ " 36.0 | \n",
+ " 100.0 | \n",
+ "
\n",
+ " \n",
+ " 187 | \n",
+ " 94.0 | \n",
+ " 100.0 | \n",
+ " 138.0 | \n",
+ " 13.0 | \n",
+ " 149.0 | \n",
+ "
\n",
+ " \n",
+ " 188 | \n",
+ " 65.0 | \n",
+ " 101.0 | \n",
+ " 123.0 | \n",
+ " 128.0 | \n",
+ " 86.0 | \n",
+ "
\n",
+ " \n",
+ " 189 | \n",
+ " 43.0 | \n",
+ " 94.0 | \n",
+ " 100.0 | \n",
+ " 29.0 | \n",
+ " 132.0 | \n",
+ "
\n",
+ " \n",
+ " 190 | \n",
+ " 68.0 | \n",
+ " 135.0 | \n",
+ " 94.0 | \n",
+ " 28.0 | \n",
+ " 125.0 | \n",
+ "
\n",
+ " \n",
+ " 191 | \n",
+ " 30.0 | \n",
+ " 60.0 | \n",
+ " 98.0 | \n",
+ " 100.0 | \n",
+ " 15.0 | \n",
+ "
\n",
+ " \n",
+ " 192 | \n",
+ " 89.0 | \n",
+ " 16.0 | \n",
+ " 10.0 | \n",
+ " 135.0 | \n",
+ " 4.0 | \n",
+ "
\n",
+ " \n",
+ " 193 | \n",
+ " 104.0 | \n",
+ " 139.0 | \n",
+ " 97.0 | \n",
+ " 29.0 | \n",
+ " 17.0 | \n",
+ "
\n",
+ " \n",
+ " 194 | \n",
+ " 5.0 | \n",
+ " 29.0 | \n",
+ " 41.0 | \n",
+ " 99.0 | \n",
+ " 100.0 | \n",
+ "
\n",
+ " \n",
+ " 195 | \n",
+ " 19.0 | \n",
+ " 102.0 | \n",
+ " 135.0 | \n",
+ " 41.0 | \n",
+ " 40.0 | \n",
+ "
\n",
+ " \n",
+ " 196 | \n",
+ " 58.0 | \n",
+ " 100.0 | \n",
+ " 70.0 | \n",
+ " 82.0 | \n",
+ " 64.0 | \n",
+ "
\n",
+ " \n",
+ " 197 | \n",
+ " 100.0 | \n",
+ " 97.0 | \n",
+ " 129.0 | \n",
+ " 76.0 | \n",
+ " 13.0 | \n",
+ "
\n",
+ " \n",
+ " 198 | \n",
+ " 131.0 | \n",
+ " 15.0 | \n",
+ " 100.0 | \n",
+ " 44.0 | \n",
+ " 114.0 | \n",
+ "
\n",
+ " \n",
+ " 199 | \n",
+ " 79.0 | \n",
+ " 100.0 | \n",
+ " 95.0 | \n",
+ " 128.0 | \n",
+ " 100.0 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
100 rows × 5 columns
\n",
+ "
"
+ ],
+ "text/plain": [
+ " Python En Math Physic Chem\n",
+ "100 122.0 10.0 5.0 28.0 57.0\n",
+ "101 100.0 129.0 16.0 114.0 26.0\n",
+ "102 97.0 121.0 122.0 29.0 65.0\n",
+ "103 141.0 73.0 120.0 147.0 1.0\n",
+ "104 126.0 100.0 86.0 116.0 17.0\n",
+ "105 85.0 100.0 42.0 121.0 66.0\n",
+ "106 142.0 65.0 1.0 124.0 83.0\n",
+ "107 136.0 141.0 100.0 86.0 113.0\n",
+ "108 15.0 37.0 124.0 110.0 102.0\n",
+ "109 63.0 30.0 100.0 69.0 58.0\n",
+ "110 100.0 100.0 113.0 109.0 16.0\n",
+ "111 5.0 51.0 87.0 58.0 126.0\n",
+ "112 53.0 97.0 76.0 37.0 45.0\n",
+ "113 42.0 148.0 100.0 97.0 100.0\n",
+ "114 70.0 138.0 69.0 68.0 134.0\n",
+ "115 100.0 136.0 113.0 22.0 94.0\n",
+ "116 31.0 137.0 6.0 20.0 28.0\n",
+ "117 148.0 74.0 134.0 4.0 124.0\n",
+ "118 102.0 81.0 138.0 128.0 32.0\n",
+ "119 27.0 111.0 13.0 100.0 22.0\n",
+ "120 28.0 93.0 121.0 100.0 4.0\n",
+ "121 136.0 100.0 25.0 97.0 19.0\n",
+ "122 111.0 70.0 12.0 38.0 58.0\n",
+ "123 100.0 103.0 147.0 86.0 8.0\n",
+ "124 10.0 10.0 46.0 63.0 149.0\n",
+ "125 7.0 75.0 97.0 108.0 31.0\n",
+ "126 88.0 6.0 100.0 100.0 55.0\n",
+ "127 33.0 74.0 106.0 50.0 46.0\n",
+ "128 74.0 28.0 26.0 100.0 76.0\n",
+ "129 76.0 18.0 101.0 100.0 100.0\n",
+ ".. ... ... ... ... ...\n",
+ "170 144.0 124.0 77.0 92.0 82.0\n",
+ "171 36.0 98.0 100.0 43.0 80.0\n",
+ "172 51.0 100.0 68.0 34.0 74.0\n",
+ "173 149.0 100.0 18.0 141.0 100.0\n",
+ "174 8.0 139.0 146.0 112.0 100.0\n",
+ "175 115.0 100.0 64.0 62.0 9.0\n",
+ "176 100.0 7.0 140.0 45.0 148.0\n",
+ "177 100.0 43.0 68.0 109.0 18.0\n",
+ "178 31.0 100.0 100.0 49.0 123.0\n",
+ "179 29.0 46.0 69.0 57.0 90.0\n",
+ "180 146.0 86.0 18.0 22.0 46.0\n",
+ "181 71.0 50.0 40.0 100.0 140.0\n",
+ "182 4.0 100.0 147.0 116.0 110.0\n",
+ "183 55.0 87.0 93.0 100.0 34.0\n",
+ "184 100.0 109.0 124.0 87.0 82.0\n",
+ "185 10.0 118.0 139.0 50.0 51.0\n",
+ "186 32.0 12.0 71.0 36.0 100.0\n",
+ "187 94.0 100.0 138.0 13.0 149.0\n",
+ "188 65.0 101.0 123.0 128.0 86.0\n",
+ "189 43.0 94.0 100.0 29.0 132.0\n",
+ "190 68.0 135.0 94.0 28.0 125.0\n",
+ "191 30.0 60.0 98.0 100.0 15.0\n",
+ "192 89.0 16.0 10.0 135.0 4.0\n",
+ "193 104.0 139.0 97.0 29.0 17.0\n",
+ "194 5.0 29.0 41.0 99.0 100.0\n",
+ "195 19.0 102.0 135.0 41.0 40.0\n",
+ "196 58.0 100.0 70.0 82.0 64.0\n",
+ "197 100.0 97.0 129.0 76.0 13.0\n",
+ "198 131.0 15.0 100.0 44.0 114.0\n",
+ "199 79.0 100.0 95.0 128.0 100.0\n",
+ "\n",
+ "[100 rows x 5 columns]"
+ ]
+ },
+ "execution_count": 26,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "# 固定值填充\n",
+ "df2.fillna(value=100)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 27,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "Python 71.662791\n",
+ "En 75.627907\n",
+ "Math 77.929412\n",
+ "Physic 73.471910\n",
+ "Chem 69.080460\n",
+ "dtype: float64"
+ ]
+ },
+ "execution_count": 27,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "df2.mean()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": []
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 29,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Python | \n",
+ " En | \n",
+ " Math | \n",
+ " Physic | \n",
+ " Chem | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " 100 | \n",
+ " 122 | \n",
+ " 10 | \n",
+ " 5 | \n",
+ " 28 | \n",
+ " 57 | \n",
+ "
\n",
+ " \n",
+ " 101 | \n",
+ " 71 | \n",
+ " 129 | \n",
+ " 16 | \n",
+ " 114 | \n",
+ " 26 | \n",
+ "
\n",
+ " \n",
+ " 102 | \n",
+ " 97 | \n",
+ " 121 | \n",
+ " 122 | \n",
+ " 29 | \n",
+ " 65 | \n",
+ "
\n",
+ " \n",
+ " 103 | \n",
+ " 141 | \n",
+ " 73 | \n",
+ " 120 | \n",
+ " 147 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " 104 | \n",
+ " 126 | \n",
+ " 75 | \n",
+ " 86 | \n",
+ " 116 | \n",
+ " 17 | \n",
+ "
\n",
+ " \n",
+ " 105 | \n",
+ " 85 | \n",
+ " 75 | \n",
+ " 42 | \n",
+ " 121 | \n",
+ " 66 | \n",
+ "
\n",
+ " \n",
+ " 106 | \n",
+ " 142 | \n",
+ " 65 | \n",
+ " 1 | \n",
+ " 124 | \n",
+ " 83 | \n",
+ "
\n",
+ " \n",
+ " 107 | \n",
+ " 136 | \n",
+ " 141 | \n",
+ " 77 | \n",
+ " 86 | \n",
+ " 113 | \n",
+ "
\n",
+ " \n",
+ " 108 | \n",
+ " 15 | \n",
+ " 37 | \n",
+ " 124 | \n",
+ " 110 | \n",
+ " 102 | \n",
+ "
\n",
+ " \n",
+ " 109 | \n",
+ " 63 | \n",
+ " 30 | \n",
+ " 77 | \n",
+ " 69 | \n",
+ " 58 | \n",
+ "
\n",
+ " \n",
+ " 110 | \n",
+ " 71 | \n",
+ " 75 | \n",
+ " 113 | \n",
+ " 109 | \n",
+ " 16 | \n",
+ "
\n",
+ " \n",
+ " 111 | \n",
+ " 5 | \n",
+ " 51 | \n",
+ " 87 | \n",
+ " 58 | \n",
+ " 126 | \n",
+ "
\n",
+ " \n",
+ " 112 | \n",
+ " 53 | \n",
+ " 97 | \n",
+ " 76 | \n",
+ " 37 | \n",
+ " 45 | \n",
+ "
\n",
+ " \n",
+ " 113 | \n",
+ " 42 | \n",
+ " 148 | \n",
+ " 77 | \n",
+ " 97 | \n",
+ " 69 | \n",
+ "
\n",
+ " \n",
+ " 114 | \n",
+ " 70 | \n",
+ " 138 | \n",
+ " 69 | \n",
+ " 68 | \n",
+ " 134 | \n",
+ "
\n",
+ " \n",
+ " 115 | \n",
+ " 71 | \n",
+ " 136 | \n",
+ " 113 | \n",
+ " 22 | \n",
+ " 94 | \n",
+ "
\n",
+ " \n",
+ " 116 | \n",
+ " 31 | \n",
+ " 137 | \n",
+ " 6 | \n",
+ " 20 | \n",
+ " 28 | \n",
+ "
\n",
+ " \n",
+ " 117 | \n",
+ " 148 | \n",
+ " 74 | \n",
+ " 134 | \n",
+ " 4 | \n",
+ " 124 | \n",
+ "
\n",
+ " \n",
+ " 118 | \n",
+ " 102 | \n",
+ " 81 | \n",
+ " 138 | \n",
+ " 128 | \n",
+ " 32 | \n",
+ "
\n",
+ " \n",
+ " 119 | \n",
+ " 27 | \n",
+ " 111 | \n",
+ " 13 | \n",
+ " 73 | \n",
+ " 22 | \n",
+ "
\n",
+ " \n",
+ " 120 | \n",
+ " 28 | \n",
+ " 93 | \n",
+ " 121 | \n",
+ " 73 | \n",
+ " 4 | \n",
+ "
\n",
+ " \n",
+ " 121 | \n",
+ " 136 | \n",
+ " 75 | \n",
+ " 25 | \n",
+ " 97 | \n",
+ " 19 | \n",
+ "
\n",
+ " \n",
+ " 122 | \n",
+ " 111 | \n",
+ " 70 | \n",
+ " 12 | \n",
+ " 38 | \n",
+ " 58 | \n",
+ "
\n",
+ " \n",
+ " 123 | \n",
+ " 71 | \n",
+ " 103 | \n",
+ " 147 | \n",
+ " 86 | \n",
+ " 8 | \n",
+ "
\n",
+ " \n",
+ " 124 | \n",
+ " 10 | \n",
+ " 10 | \n",
+ " 46 | \n",
+ " 63 | \n",
+ " 149 | \n",
+ "
\n",
+ " \n",
+ " 125 | \n",
+ " 7 | \n",
+ " 75 | \n",
+ " 97 | \n",
+ " 108 | \n",
+ " 31 | \n",
+ "
\n",
+ " \n",
+ " 126 | \n",
+ " 88 | \n",
+ " 6 | \n",
+ " 77 | \n",
+ " 73 | \n",
+ " 55 | \n",
+ "
\n",
+ " \n",
+ " 127 | \n",
+ " 33 | \n",
+ " 74 | \n",
+ " 106 | \n",
+ " 50 | \n",
+ " 46 | \n",
+ "
\n",
+ " \n",
+ " 128 | \n",
+ " 74 | \n",
+ " 28 | \n",
+ " 26 | \n",
+ " 100 | \n",
+ " 76 | \n",
+ "
\n",
+ " \n",
+ " 129 | \n",
+ " 76 | \n",
+ " 18 | \n",
+ " 101 | \n",
+ " 73 | \n",
+ " 69 | \n",
+ "
\n",
+ " \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ "
\n",
+ " \n",
+ " 170 | \n",
+ " 144 | \n",
+ " 124 | \n",
+ " 77 | \n",
+ " 92 | \n",
+ " 82 | \n",
+ "
\n",
+ " \n",
+ " 171 | \n",
+ " 36 | \n",
+ " 98 | \n",
+ " 77 | \n",
+ " 43 | \n",
+ " 80 | \n",
+ "
\n",
+ " \n",
+ " 172 | \n",
+ " 51 | \n",
+ " 75 | \n",
+ " 68 | \n",
+ " 34 | \n",
+ " 74 | \n",
+ "
\n",
+ " \n",
+ " 173 | \n",
+ " 149 | \n",
+ " 75 | \n",
+ " 18 | \n",
+ " 141 | \n",
+ " 69 | \n",
+ "
\n",
+ " \n",
+ " 174 | \n",
+ " 8 | \n",
+ " 139 | \n",
+ " 146 | \n",
+ " 112 | \n",
+ " 69 | \n",
+ "
\n",
+ " \n",
+ " 175 | \n",
+ " 115 | \n",
+ " 75 | \n",
+ " 64 | \n",
+ " 62 | \n",
+ " 9 | \n",
+ "
\n",
+ " \n",
+ " 176 | \n",
+ " 71 | \n",
+ " 7 | \n",
+ " 140 | \n",
+ " 45 | \n",
+ " 148 | \n",
+ "
\n",
+ " \n",
+ " 177 | \n",
+ " 71 | \n",
+ " 43 | \n",
+ " 68 | \n",
+ " 109 | \n",
+ " 18 | \n",
+ "
\n",
+ " \n",
+ " 178 | \n",
+ " 31 | \n",
+ " 100 | \n",
+ " 77 | \n",
+ " 49 | \n",
+ " 123 | \n",
+ "
\n",
+ " \n",
+ " 179 | \n",
+ " 29 | \n",
+ " 46 | \n",
+ " 69 | \n",
+ " 57 | \n",
+ " 90 | \n",
+ "
\n",
+ " \n",
+ " 180 | \n",
+ " 146 | \n",
+ " 86 | \n",
+ " 18 | \n",
+ " 22 | \n",
+ " 46 | \n",
+ "
\n",
+ " \n",
+ " 181 | \n",
+ " 71 | \n",
+ " 50 | \n",
+ " 40 | \n",
+ " 73 | \n",
+ " 140 | \n",
+ "
\n",
+ " \n",
+ " 182 | \n",
+ " 4 | \n",
+ " 100 | \n",
+ " 147 | \n",
+ " 116 | \n",
+ " 110 | \n",
+ "
\n",
+ " \n",
+ " 183 | \n",
+ " 55 | \n",
+ " 87 | \n",
+ " 93 | \n",
+ " 73 | \n",
+ " 34 | \n",
+ "
\n",
+ " \n",
+ " 184 | \n",
+ " 71 | \n",
+ " 109 | \n",
+ " 124 | \n",
+ " 87 | \n",
+ " 82 | \n",
+ "
\n",
+ " \n",
+ " 185 | \n",
+ " 10 | \n",
+ " 118 | \n",
+ " 139 | \n",
+ " 50 | \n",
+ " 51 | \n",
+ "
\n",
+ " \n",
+ " 186 | \n",
+ " 32 | \n",
+ " 12 | \n",
+ " 71 | \n",
+ " 36 | \n",
+ " 69 | \n",
+ "
\n",
+ " \n",
+ " 187 | \n",
+ " 94 | \n",
+ " 75 | \n",
+ " 138 | \n",
+ " 13 | \n",
+ " 149 | \n",
+ "
\n",
+ " \n",
+ " 188 | \n",
+ " 65 | \n",
+ " 101 | \n",
+ " 123 | \n",
+ " 128 | \n",
+ " 86 | \n",
+ "
\n",
+ " \n",
+ " 189 | \n",
+ " 43 | \n",
+ " 94 | \n",
+ " 77 | \n",
+ " 29 | \n",
+ " 132 | \n",
+ "
\n",
+ " \n",
+ " 190 | \n",
+ " 68 | \n",
+ " 135 | \n",
+ " 94 | \n",
+ " 28 | \n",
+ " 125 | \n",
+ "
\n",
+ " \n",
+ " 191 | \n",
+ " 30 | \n",
+ " 60 | \n",
+ " 98 | \n",
+ " 73 | \n",
+ " 15 | \n",
+ "
\n",
+ " \n",
+ " 192 | \n",
+ " 89 | \n",
+ " 16 | \n",
+ " 10 | \n",
+ " 135 | \n",
+ " 4 | \n",
+ "
\n",
+ " \n",
+ " 193 | \n",
+ " 104 | \n",
+ " 139 | \n",
+ " 97 | \n",
+ " 29 | \n",
+ " 17 | \n",
+ "
\n",
+ " \n",
+ " 194 | \n",
+ " 5 | \n",
+ " 29 | \n",
+ " 41 | \n",
+ " 99 | \n",
+ " 69 | \n",
+ "
\n",
+ " \n",
+ " 195 | \n",
+ " 19 | \n",
+ " 102 | \n",
+ " 135 | \n",
+ " 41 | \n",
+ " 40 | \n",
+ "
\n",
+ " \n",
+ " 196 | \n",
+ " 58 | \n",
+ " 75 | \n",
+ " 70 | \n",
+ " 82 | \n",
+ " 64 | \n",
+ "
\n",
+ " \n",
+ " 197 | \n",
+ " 71 | \n",
+ " 97 | \n",
+ " 129 | \n",
+ " 76 | \n",
+ " 13 | \n",
+ "
\n",
+ " \n",
+ " 198 | \n",
+ " 131 | \n",
+ " 15 | \n",
+ " 77 | \n",
+ " 44 | \n",
+ " 114 | \n",
+ "
\n",
+ " \n",
+ " 199 | \n",
+ " 79 | \n",
+ " 75 | \n",
+ " 95 | \n",
+ " 128 | \n",
+ " 69 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
100 rows × 5 columns
\n",
+ "
"
+ ],
+ "text/plain": [
+ " Python En Math Physic Chem\n",
+ "100 122 10 5 28 57\n",
+ "101 71 129 16 114 26\n",
+ "102 97 121 122 29 65\n",
+ "103 141 73 120 147 1\n",
+ "104 126 75 86 116 17\n",
+ "105 85 75 42 121 66\n",
+ "106 142 65 1 124 83\n",
+ "107 136 141 77 86 113\n",
+ "108 15 37 124 110 102\n",
+ "109 63 30 77 69 58\n",
+ "110 71 75 113 109 16\n",
+ "111 5 51 87 58 126\n",
+ "112 53 97 76 37 45\n",
+ "113 42 148 77 97 69\n",
+ "114 70 138 69 68 134\n",
+ "115 71 136 113 22 94\n",
+ "116 31 137 6 20 28\n",
+ "117 148 74 134 4 124\n",
+ "118 102 81 138 128 32\n",
+ "119 27 111 13 73 22\n",
+ "120 28 93 121 73 4\n",
+ "121 136 75 25 97 19\n",
+ "122 111 70 12 38 58\n",
+ "123 71 103 147 86 8\n",
+ "124 10 10 46 63 149\n",
+ "125 7 75 97 108 31\n",
+ "126 88 6 77 73 55\n",
+ "127 33 74 106 50 46\n",
+ "128 74 28 26 100 76\n",
+ "129 76 18 101 73 69\n",
+ ".. ... ... ... ... ...\n",
+ "170 144 124 77 92 82\n",
+ "171 36 98 77 43 80\n",
+ "172 51 75 68 34 74\n",
+ "173 149 75 18 141 69\n",
+ "174 8 139 146 112 69\n",
+ "175 115 75 64 62 9\n",
+ "176 71 7 140 45 148\n",
+ "177 71 43 68 109 18\n",
+ "178 31 100 77 49 123\n",
+ "179 29 46 69 57 90\n",
+ "180 146 86 18 22 46\n",
+ "181 71 50 40 73 140\n",
+ "182 4 100 147 116 110\n",
+ "183 55 87 93 73 34\n",
+ "184 71 109 124 87 82\n",
+ "185 10 118 139 50 51\n",
+ "186 32 12 71 36 69\n",
+ "187 94 75 138 13 149\n",
+ "188 65 101 123 128 86\n",
+ "189 43 94 77 29 132\n",
+ "190 68 135 94 28 125\n",
+ "191 30 60 98 73 15\n",
+ "192 89 16 10 135 4\n",
+ "193 104 139 97 29 17\n",
+ "194 5 29 41 99 69\n",
+ "195 19 102 135 41 40\n",
+ "196 58 75 70 82 64\n",
+ "197 71 97 129 76 13\n",
+ "198 131 15 77 44 114\n",
+ "199 79 75 95 128 69\n",
+ "\n",
+ "[100 rows x 5 columns]"
+ ]
+ },
+ "execution_count": 29,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "# 均值\n",
+ "df3 = df2.fillna(value=df2.mean())\n",
+ "df3.astype(np.int16)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 31,
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "array([ 6, 18, 1, 17, 19, 5, 17, 16, 13, 3])"
+ ]
+ },
+ "execution_count": 31,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "nd = np.random.randint(0,20,size = 10)\n",
+ "nd"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 33,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "array([ 1, 3, 5, 6, 13, 16, 17, 17, 18, 19])"
+ ]
+ },
+ "execution_count": 33,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "nd.sort()\n",
+ "nd"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 34,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "14.5"
+ ]
+ },
+ "execution_count": 34,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "(13 + 16)/2"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 35,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "14.5"
+ ]
+ },
+ "execution_count": 35,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "np.median(nd)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 36,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Python | \n",
+ " En | \n",
+ " Math | \n",
+ " Physic | \n",
+ " Chem | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " 100 | \n",
+ " 122.0 | \n",
+ " 10.0 | \n",
+ " 5.0 | \n",
+ " 28.0 | \n",
+ " 57.0 | \n",
+ "
\n",
+ " \n",
+ " 101 | \n",
+ " 68.0 | \n",
+ " 129.0 | \n",
+ " 16.0 | \n",
+ " 114.0 | \n",
+ " 26.0 | \n",
+ "
\n",
+ " \n",
+ " 102 | \n",
+ " 97.0 | \n",
+ " 121.0 | \n",
+ " 122.0 | \n",
+ " 29.0 | \n",
+ " 65.0 | \n",
+ "
\n",
+ " \n",
+ " 103 | \n",
+ " 141.0 | \n",
+ " 73.0 | \n",
+ " 120.0 | \n",
+ " 147.0 | \n",
+ " 1.0 | \n",
+ "
\n",
+ " \n",
+ " 104 | \n",
+ " 126.0 | \n",
+ " 82.5 | \n",
+ " 86.0 | \n",
+ " 116.0 | \n",
+ " 17.0 | \n",
+ "
\n",
+ " \n",
+ " 105 | \n",
+ " 85.0 | \n",
+ " 82.5 | \n",
+ " 42.0 | \n",
+ " 121.0 | \n",
+ " 66.0 | \n",
+ "
\n",
+ " \n",
+ " 106 | \n",
+ " 142.0 | \n",
+ " 65.0 | \n",
+ " 1.0 | \n",
+ " 124.0 | \n",
+ " 83.0 | \n",
+ "
\n",
+ " \n",
+ " 107 | \n",
+ " 136.0 | \n",
+ " 141.0 | \n",
+ " 86.0 | \n",
+ " 86.0 | \n",
+ " 113.0 | \n",
+ "
\n",
+ " \n",
+ " 108 | \n",
+ " 15.0 | \n",
+ " 37.0 | \n",
+ " 124.0 | \n",
+ " 110.0 | \n",
+ " 102.0 | \n",
+ "
\n",
+ " \n",
+ " 109 | \n",
+ " 63.0 | \n",
+ " 30.0 | \n",
+ " 86.0 | \n",
+ " 69.0 | \n",
+ " 58.0 | \n",
+ "
\n",
+ " \n",
+ " 110 | \n",
+ " 68.0 | \n",
+ " 82.5 | \n",
+ " 113.0 | \n",
+ " 109.0 | \n",
+ " 16.0 | \n",
+ "
\n",
+ " \n",
+ " 111 | \n",
+ " 5.0 | \n",
+ " 51.0 | \n",
+ " 87.0 | \n",
+ " 58.0 | \n",
+ " 126.0 | \n",
+ "
\n",
+ " \n",
+ " 112 | \n",
+ " 53.0 | \n",
+ " 97.0 | \n",
+ " 76.0 | \n",
+ " 37.0 | \n",
+ " 45.0 | \n",
+ "
\n",
+ " \n",
+ " 113 | \n",
+ " 42.0 | \n",
+ " 148.0 | \n",
+ " 86.0 | \n",
+ " 97.0 | \n",
+ " 65.0 | \n",
+ "
\n",
+ " \n",
+ " 114 | \n",
+ " 70.0 | \n",
+ " 138.0 | \n",
+ " 69.0 | \n",
+ " 68.0 | \n",
+ " 134.0 | \n",
+ "
\n",
+ " \n",
+ " 115 | \n",
+ " 68.0 | \n",
+ " 136.0 | \n",
+ " 113.0 | \n",
+ " 22.0 | \n",
+ " 94.0 | \n",
+ "
\n",
+ " \n",
+ " 116 | \n",
+ " 31.0 | \n",
+ " 137.0 | \n",
+ " 6.0 | \n",
+ " 20.0 | \n",
+ " 28.0 | \n",
+ "
\n",
+ " \n",
+ " 117 | \n",
+ " 148.0 | \n",
+ " 74.0 | \n",
+ " 134.0 | \n",
+ " 4.0 | \n",
+ " 124.0 | \n",
+ "
\n",
+ " \n",
+ " 118 | \n",
+ " 102.0 | \n",
+ " 81.0 | \n",
+ " 138.0 | \n",
+ " 128.0 | \n",
+ " 32.0 | \n",
+ "
\n",
+ " \n",
+ " 119 | \n",
+ " 27.0 | \n",
+ " 111.0 | \n",
+ " 13.0 | \n",
+ " 69.0 | \n",
+ " 22.0 | \n",
+ "
\n",
+ " \n",
+ " 120 | \n",
+ " 28.0 | \n",
+ " 93.0 | \n",
+ " 121.0 | \n",
+ " 69.0 | \n",
+ " 4.0 | \n",
+ "
\n",
+ " \n",
+ " 121 | \n",
+ " 136.0 | \n",
+ " 82.5 | \n",
+ " 25.0 | \n",
+ " 97.0 | \n",
+ " 19.0 | \n",
+ "
\n",
+ " \n",
+ " 122 | \n",
+ " 111.0 | \n",
+ " 70.0 | \n",
+ " 12.0 | \n",
+ " 38.0 | \n",
+ " 58.0 | \n",
+ "
\n",
+ " \n",
+ " 123 | \n",
+ " 68.0 | \n",
+ " 103.0 | \n",
+ " 147.0 | \n",
+ " 86.0 | \n",
+ " 8.0 | \n",
+ "
\n",
+ " \n",
+ " 124 | \n",
+ " 10.0 | \n",
+ " 10.0 | \n",
+ " 46.0 | \n",
+ " 63.0 | \n",
+ " 149.0 | \n",
+ "
\n",
+ " \n",
+ " 125 | \n",
+ " 7.0 | \n",
+ " 75.0 | \n",
+ " 97.0 | \n",
+ " 108.0 | \n",
+ " 31.0 | \n",
+ "
\n",
+ " \n",
+ " 126 | \n",
+ " 88.0 | \n",
+ " 6.0 | \n",
+ " 86.0 | \n",
+ " 69.0 | \n",
+ " 55.0 | \n",
+ "
\n",
+ " \n",
+ " 127 | \n",
+ " 33.0 | \n",
+ " 74.0 | \n",
+ " 106.0 | \n",
+ " 50.0 | \n",
+ " 46.0 | \n",
+ "
\n",
+ " \n",
+ " 128 | \n",
+ " 74.0 | \n",
+ " 28.0 | \n",
+ " 26.0 | \n",
+ " 100.0 | \n",
+ " 76.0 | \n",
+ "
\n",
+ " \n",
+ " 129 | \n",
+ " 76.0 | \n",
+ " 18.0 | \n",
+ " 101.0 | \n",
+ " 69.0 | \n",
+ " 65.0 | \n",
+ "
\n",
+ " \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ "
\n",
+ " \n",
+ " 170 | \n",
+ " 144.0 | \n",
+ " 124.0 | \n",
+ " 77.0 | \n",
+ " 92.0 | \n",
+ " 82.0 | \n",
+ "
\n",
+ " \n",
+ " 171 | \n",
+ " 36.0 | \n",
+ " 98.0 | \n",
+ " 86.0 | \n",
+ " 43.0 | \n",
+ " 80.0 | \n",
+ "
\n",
+ " \n",
+ " 172 | \n",
+ " 51.0 | \n",
+ " 82.5 | \n",
+ " 68.0 | \n",
+ " 34.0 | \n",
+ " 74.0 | \n",
+ "
\n",
+ " \n",
+ " 173 | \n",
+ " 149.0 | \n",
+ " 82.5 | \n",
+ " 18.0 | \n",
+ " 141.0 | \n",
+ " 65.0 | \n",
+ "
\n",
+ " \n",
+ " 174 | \n",
+ " 8.0 | \n",
+ " 139.0 | \n",
+ " 146.0 | \n",
+ " 112.0 | \n",
+ " 65.0 | \n",
+ "
\n",
+ " \n",
+ " 175 | \n",
+ " 115.0 | \n",
+ " 82.5 | \n",
+ " 64.0 | \n",
+ " 62.0 | \n",
+ " 9.0 | \n",
+ "
\n",
+ " \n",
+ " 176 | \n",
+ " 68.0 | \n",
+ " 7.0 | \n",
+ " 140.0 | \n",
+ " 45.0 | \n",
+ " 148.0 | \n",
+ "
\n",
+ " \n",
+ " 177 | \n",
+ " 68.0 | \n",
+ " 43.0 | \n",
+ " 68.0 | \n",
+ " 109.0 | \n",
+ " 18.0 | \n",
+ "
\n",
+ " \n",
+ " 178 | \n",
+ " 31.0 | \n",
+ " 100.0 | \n",
+ " 86.0 | \n",
+ " 49.0 | \n",
+ " 123.0 | \n",
+ "
\n",
+ " \n",
+ " 179 | \n",
+ " 29.0 | \n",
+ " 46.0 | \n",
+ " 69.0 | \n",
+ " 57.0 | \n",
+ " 90.0 | \n",
+ "
\n",
+ " \n",
+ " 180 | \n",
+ " 146.0 | \n",
+ " 86.0 | \n",
+ " 18.0 | \n",
+ " 22.0 | \n",
+ " 46.0 | \n",
+ "
\n",
+ " \n",
+ " 181 | \n",
+ " 71.0 | \n",
+ " 50.0 | \n",
+ " 40.0 | \n",
+ " 69.0 | \n",
+ " 140.0 | \n",
+ "
\n",
+ " \n",
+ " 182 | \n",
+ " 4.0 | \n",
+ " 100.0 | \n",
+ " 147.0 | \n",
+ " 116.0 | \n",
+ " 110.0 | \n",
+ "
\n",
+ " \n",
+ " 183 | \n",
+ " 55.0 | \n",
+ " 87.0 | \n",
+ " 93.0 | \n",
+ " 69.0 | \n",
+ " 34.0 | \n",
+ "
\n",
+ " \n",
+ " 184 | \n",
+ " 68.0 | \n",
+ " 109.0 | \n",
+ " 124.0 | \n",
+ " 87.0 | \n",
+ " 82.0 | \n",
+ "
\n",
+ " \n",
+ " 185 | \n",
+ " 10.0 | \n",
+ " 118.0 | \n",
+ " 139.0 | \n",
+ " 50.0 | \n",
+ " 51.0 | \n",
+ "
\n",
+ " \n",
+ " 186 | \n",
+ " 32.0 | \n",
+ " 12.0 | \n",
+ " 71.0 | \n",
+ " 36.0 | \n",
+ " 65.0 | \n",
+ "
\n",
+ " \n",
+ " 187 | \n",
+ " 94.0 | \n",
+ " 82.5 | \n",
+ " 138.0 | \n",
+ " 13.0 | \n",
+ " 149.0 | \n",
+ "
\n",
+ " \n",
+ " 188 | \n",
+ " 65.0 | \n",
+ " 101.0 | \n",
+ " 123.0 | \n",
+ " 128.0 | \n",
+ " 86.0 | \n",
+ "
\n",
+ " \n",
+ " 189 | \n",
+ " 43.0 | \n",
+ " 94.0 | \n",
+ " 86.0 | \n",
+ " 29.0 | \n",
+ " 132.0 | \n",
+ "
\n",
+ " \n",
+ " 190 | \n",
+ " 68.0 | \n",
+ " 135.0 | \n",
+ " 94.0 | \n",
+ " 28.0 | \n",
+ " 125.0 | \n",
+ "
\n",
+ " \n",
+ " 191 | \n",
+ " 30.0 | \n",
+ " 60.0 | \n",
+ " 98.0 | \n",
+ " 69.0 | \n",
+ " 15.0 | \n",
+ "
\n",
+ " \n",
+ " 192 | \n",
+ " 89.0 | \n",
+ " 16.0 | \n",
+ " 10.0 | \n",
+ " 135.0 | \n",
+ " 4.0 | \n",
+ "
\n",
+ " \n",
+ " 193 | \n",
+ " 104.0 | \n",
+ " 139.0 | \n",
+ " 97.0 | \n",
+ " 29.0 | \n",
+ " 17.0 | \n",
+ "
\n",
+ " \n",
+ " 194 | \n",
+ " 5.0 | \n",
+ " 29.0 | \n",
+ " 41.0 | \n",
+ " 99.0 | \n",
+ " 65.0 | \n",
+ "
\n",
+ " \n",
+ " 195 | \n",
+ " 19.0 | \n",
+ " 102.0 | \n",
+ " 135.0 | \n",
+ " 41.0 | \n",
+ " 40.0 | \n",
+ "
\n",
+ " \n",
+ " 196 | \n",
+ " 58.0 | \n",
+ " 82.5 | \n",
+ " 70.0 | \n",
+ " 82.0 | \n",
+ " 64.0 | \n",
+ "
\n",
+ " \n",
+ " 197 | \n",
+ " 68.0 | \n",
+ " 97.0 | \n",
+ " 129.0 | \n",
+ " 76.0 | \n",
+ " 13.0 | \n",
+ "
\n",
+ " \n",
+ " 198 | \n",
+ " 131.0 | \n",
+ " 15.0 | \n",
+ " 86.0 | \n",
+ " 44.0 | \n",
+ " 114.0 | \n",
+ "
\n",
+ " \n",
+ " 199 | \n",
+ " 79.0 | \n",
+ " 82.5 | \n",
+ " 95.0 | \n",
+ " 128.0 | \n",
+ " 65.0 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
100 rows × 5 columns
\n",
+ "
"
+ ],
+ "text/plain": [
+ " Python En Math Physic Chem\n",
+ "100 122.0 10.0 5.0 28.0 57.0\n",
+ "101 68.0 129.0 16.0 114.0 26.0\n",
+ "102 97.0 121.0 122.0 29.0 65.0\n",
+ "103 141.0 73.0 120.0 147.0 1.0\n",
+ "104 126.0 82.5 86.0 116.0 17.0\n",
+ "105 85.0 82.5 42.0 121.0 66.0\n",
+ "106 142.0 65.0 1.0 124.0 83.0\n",
+ "107 136.0 141.0 86.0 86.0 113.0\n",
+ "108 15.0 37.0 124.0 110.0 102.0\n",
+ "109 63.0 30.0 86.0 69.0 58.0\n",
+ "110 68.0 82.5 113.0 109.0 16.0\n",
+ "111 5.0 51.0 87.0 58.0 126.0\n",
+ "112 53.0 97.0 76.0 37.0 45.0\n",
+ "113 42.0 148.0 86.0 97.0 65.0\n",
+ "114 70.0 138.0 69.0 68.0 134.0\n",
+ "115 68.0 136.0 113.0 22.0 94.0\n",
+ "116 31.0 137.0 6.0 20.0 28.0\n",
+ "117 148.0 74.0 134.0 4.0 124.0\n",
+ "118 102.0 81.0 138.0 128.0 32.0\n",
+ "119 27.0 111.0 13.0 69.0 22.0\n",
+ "120 28.0 93.0 121.0 69.0 4.0\n",
+ "121 136.0 82.5 25.0 97.0 19.0\n",
+ "122 111.0 70.0 12.0 38.0 58.0\n",
+ "123 68.0 103.0 147.0 86.0 8.0\n",
+ "124 10.0 10.0 46.0 63.0 149.0\n",
+ "125 7.0 75.0 97.0 108.0 31.0\n",
+ "126 88.0 6.0 86.0 69.0 55.0\n",
+ "127 33.0 74.0 106.0 50.0 46.0\n",
+ "128 74.0 28.0 26.0 100.0 76.0\n",
+ "129 76.0 18.0 101.0 69.0 65.0\n",
+ ".. ... ... ... ... ...\n",
+ "170 144.0 124.0 77.0 92.0 82.0\n",
+ "171 36.0 98.0 86.0 43.0 80.0\n",
+ "172 51.0 82.5 68.0 34.0 74.0\n",
+ "173 149.0 82.5 18.0 141.0 65.0\n",
+ "174 8.0 139.0 146.0 112.0 65.0\n",
+ "175 115.0 82.5 64.0 62.0 9.0\n",
+ "176 68.0 7.0 140.0 45.0 148.0\n",
+ "177 68.0 43.0 68.0 109.0 18.0\n",
+ "178 31.0 100.0 86.0 49.0 123.0\n",
+ "179 29.0 46.0 69.0 57.0 90.0\n",
+ "180 146.0 86.0 18.0 22.0 46.0\n",
+ "181 71.0 50.0 40.0 69.0 140.0\n",
+ "182 4.0 100.0 147.0 116.0 110.0\n",
+ "183 55.0 87.0 93.0 69.0 34.0\n",
+ "184 68.0 109.0 124.0 87.0 82.0\n",
+ "185 10.0 118.0 139.0 50.0 51.0\n",
+ "186 32.0 12.0 71.0 36.0 65.0\n",
+ "187 94.0 82.5 138.0 13.0 149.0\n",
+ "188 65.0 101.0 123.0 128.0 86.0\n",
+ "189 43.0 94.0 86.0 29.0 132.0\n",
+ "190 68.0 135.0 94.0 28.0 125.0\n",
+ "191 30.0 60.0 98.0 69.0 15.0\n",
+ "192 89.0 16.0 10.0 135.0 4.0\n",
+ "193 104.0 139.0 97.0 29.0 17.0\n",
+ "194 5.0 29.0 41.0 99.0 65.0\n",
+ "195 19.0 102.0 135.0 41.0 40.0\n",
+ "196 58.0 82.5 70.0 82.0 64.0\n",
+ "197 68.0 97.0 129.0 76.0 13.0\n",
+ "198 131.0 15.0 86.0 44.0 114.0\n",
+ "199 79.0 82.5 95.0 128.0 65.0\n",
+ "\n",
+ "[100 rows x 5 columns]"
+ ]
+ },
+ "execution_count": 36,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "# 中位数填充\n",
+ "df2.median()\n",
+ "df4 = df2.fillna(df2.median())\n",
+ "df4"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 37,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Python | \n",
+ " En | \n",
+ " Math | \n",
+ " Physic | \n",
+ " Chem | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " 100 | \n",
+ " 122.0 | \n",
+ " 10.0 | \n",
+ " 5.0 | \n",
+ " 28.0 | \n",
+ " 57.0 | \n",
+ "
\n",
+ " \n",
+ " 101 | \n",
+ " NaN | \n",
+ " 129.0 | \n",
+ " 16.0 | \n",
+ " 114.0 | \n",
+ " 26.0 | \n",
+ "
\n",
+ " \n",
+ " 102 | \n",
+ " 97.0 | \n",
+ " 121.0 | \n",
+ " 122.0 | \n",
+ " 29.0 | \n",
+ " 65.0 | \n",
+ "
\n",
+ " \n",
+ " 103 | \n",
+ " 141.0 | \n",
+ " 73.0 | \n",
+ " 120.0 | \n",
+ " 147.0 | \n",
+ " 1.0 | \n",
+ "
\n",
+ " \n",
+ " 104 | \n",
+ " 126.0 | \n",
+ " NaN | \n",
+ " 86.0 | \n",
+ " 116.0 | \n",
+ " 17.0 | \n",
+ "
\n",
+ " \n",
+ " 105 | \n",
+ " 85.0 | \n",
+ " NaN | \n",
+ " 42.0 | \n",
+ " 121.0 | \n",
+ " 66.0 | \n",
+ "
\n",
+ " \n",
+ " 106 | \n",
+ " 142.0 | \n",
+ " 65.0 | \n",
+ " 1.0 | \n",
+ " 124.0 | \n",
+ " 83.0 | \n",
+ "
\n",
+ " \n",
+ " 107 | \n",
+ " 136.0 | \n",
+ " 141.0 | \n",
+ " NaN | \n",
+ " 86.0 | \n",
+ " 113.0 | \n",
+ "
\n",
+ " \n",
+ " 108 | \n",
+ " 15.0 | \n",
+ " 37.0 | \n",
+ " 124.0 | \n",
+ " 110.0 | \n",
+ " 102.0 | \n",
+ "
\n",
+ " \n",
+ " 109 | \n",
+ " 63.0 | \n",
+ " 30.0 | \n",
+ " NaN | \n",
+ " 69.0 | \n",
+ " 58.0 | \n",
+ "
\n",
+ " \n",
+ " 110 | \n",
+ " NaN | \n",
+ " NaN | \n",
+ " 113.0 | \n",
+ " 109.0 | \n",
+ " 16.0 | \n",
+ "
\n",
+ " \n",
+ " 111 | \n",
+ " 5.0 | \n",
+ " 51.0 | \n",
+ " 87.0 | \n",
+ " 58.0 | \n",
+ " 126.0 | \n",
+ "
\n",
+ " \n",
+ " 112 | \n",
+ " 53.0 | \n",
+ " 97.0 | \n",
+ " 76.0 | \n",
+ " 37.0 | \n",
+ " 45.0 | \n",
+ "
\n",
+ " \n",
+ " 113 | \n",
+ " 42.0 | \n",
+ " 148.0 | \n",
+ " NaN | \n",
+ " 97.0 | \n",
+ " NaN | \n",
+ "
\n",
+ " \n",
+ " 114 | \n",
+ " 70.0 | \n",
+ " 138.0 | \n",
+ " 69.0 | \n",
+ " 68.0 | \n",
+ " 134.0 | \n",
+ "
\n",
+ " \n",
+ " 115 | \n",
+ " NaN | \n",
+ " 136.0 | \n",
+ " 113.0 | \n",
+ " 22.0 | \n",
+ " 94.0 | \n",
+ "
\n",
+ " \n",
+ " 116 | \n",
+ " 31.0 | \n",
+ " 137.0 | \n",
+ " 6.0 | \n",
+ " 20.0 | \n",
+ " 28.0 | \n",
+ "
\n",
+ " \n",
+ " 117 | \n",
+ " 148.0 | \n",
+ " 74.0 | \n",
+ " 134.0 | \n",
+ " 4.0 | \n",
+ " 124.0 | \n",
+ "
\n",
+ " \n",
+ " 118 | \n",
+ " 102.0 | \n",
+ " 81.0 | \n",
+ " 138.0 | \n",
+ " 128.0 | \n",
+ " 32.0 | \n",
+ "
\n",
+ " \n",
+ " 119 | \n",
+ " 27.0 | \n",
+ " 111.0 | \n",
+ " 13.0 | \n",
+ " NaN | \n",
+ " 22.0 | \n",
+ "
\n",
+ " \n",
+ " 120 | \n",
+ " 28.0 | \n",
+ " 93.0 | \n",
+ " 121.0 | \n",
+ " NaN | \n",
+ " 4.0 | \n",
+ "
\n",
+ " \n",
+ " 121 | \n",
+ " 136.0 | \n",
+ " NaN | \n",
+ " 25.0 | \n",
+ " 97.0 | \n",
+ " 19.0 | \n",
+ "
\n",
+ " \n",
+ " 122 | \n",
+ " 111.0 | \n",
+ " 70.0 | \n",
+ " 12.0 | \n",
+ " 38.0 | \n",
+ " 58.0 | \n",
+ "
\n",
+ " \n",
+ " 123 | \n",
+ " NaN | \n",
+ " 103.0 | \n",
+ " 147.0 | \n",
+ " 86.0 | \n",
+ " 8.0 | \n",
+ "
\n",
+ " \n",
+ " 124 | \n",
+ " 10.0 | \n",
+ " 10.0 | \n",
+ " 46.0 | \n",
+ " 63.0 | \n",
+ " 149.0 | \n",
+ "
\n",
+ " \n",
+ " 125 | \n",
+ " 7.0 | \n",
+ " 75.0 | \n",
+ " 97.0 | \n",
+ " 108.0 | \n",
+ " 31.0 | \n",
+ "
\n",
+ " \n",
+ " 126 | \n",
+ " 88.0 | \n",
+ " 6.0 | \n",
+ " NaN | \n",
+ " NaN | \n",
+ " 55.0 | \n",
+ "
\n",
+ " \n",
+ " 127 | \n",
+ " 33.0 | \n",
+ " 74.0 | \n",
+ " 106.0 | \n",
+ " 50.0 | \n",
+ " 46.0 | \n",
+ "
\n",
+ " \n",
+ " 128 | \n",
+ " 74.0 | \n",
+ " 28.0 | \n",
+ " 26.0 | \n",
+ " 100.0 | \n",
+ " 76.0 | \n",
+ "
\n",
+ " \n",
+ " 129 | \n",
+ " 76.0 | \n",
+ " 18.0 | \n",
+ " 101.0 | \n",
+ " NaN | \n",
+ " NaN | \n",
+ "
\n",
+ " \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ "
\n",
+ " \n",
+ " 170 | \n",
+ " 144.0 | \n",
+ " 124.0 | \n",
+ " 77.0 | \n",
+ " 92.0 | \n",
+ " 82.0 | \n",
+ "
\n",
+ " \n",
+ " 171 | \n",
+ " 36.0 | \n",
+ " 98.0 | \n",
+ " NaN | \n",
+ " 43.0 | \n",
+ " 80.0 | \n",
+ "
\n",
+ " \n",
+ " 172 | \n",
+ " 51.0 | \n",
+ " NaN | \n",
+ " 68.0 | \n",
+ " 34.0 | \n",
+ " 74.0 | \n",
+ "
\n",
+ " \n",
+ " 173 | \n",
+ " 149.0 | \n",
+ " NaN | \n",
+ " 18.0 | \n",
+ " 141.0 | \n",
+ " NaN | \n",
+ "
\n",
+ " \n",
+ " 174 | \n",
+ " 8.0 | \n",
+ " 139.0 | \n",
+ " 146.0 | \n",
+ " 112.0 | \n",
+ " NaN | \n",
+ "
\n",
+ " \n",
+ " 175 | \n",
+ " 115.0 | \n",
+ " NaN | \n",
+ " 64.0 | \n",
+ " 62.0 | \n",
+ " 9.0 | \n",
+ "
\n",
+ " \n",
+ " 176 | \n",
+ " NaN | \n",
+ " 7.0 | \n",
+ " 140.0 | \n",
+ " 45.0 | \n",
+ " 148.0 | \n",
+ "
\n",
+ " \n",
+ " 177 | \n",
+ " NaN | \n",
+ " 43.0 | \n",
+ " 68.0 | \n",
+ " 109.0 | \n",
+ " 18.0 | \n",
+ "
\n",
+ " \n",
+ " 178 | \n",
+ " 31.0 | \n",
+ " 100.0 | \n",
+ " NaN | \n",
+ " 49.0 | \n",
+ " 123.0 | \n",
+ "
\n",
+ " \n",
+ " 179 | \n",
+ " 29.0 | \n",
+ " 46.0 | \n",
+ " 69.0 | \n",
+ " 57.0 | \n",
+ " 90.0 | \n",
+ "
\n",
+ " \n",
+ " 180 | \n",
+ " 146.0 | \n",
+ " 86.0 | \n",
+ " 18.0 | \n",
+ " 22.0 | \n",
+ " 46.0 | \n",
+ "
\n",
+ " \n",
+ " 181 | \n",
+ " 71.0 | \n",
+ " 50.0 | \n",
+ " 40.0 | \n",
+ " NaN | \n",
+ " 140.0 | \n",
+ "
\n",
+ " \n",
+ " 182 | \n",
+ " 4.0 | \n",
+ " 100.0 | \n",
+ " 147.0 | \n",
+ " 116.0 | \n",
+ " 110.0 | \n",
+ "
\n",
+ " \n",
+ " 183 | \n",
+ " 55.0 | \n",
+ " 87.0 | \n",
+ " 93.0 | \n",
+ " NaN | \n",
+ " 34.0 | \n",
+ "
\n",
+ " \n",
+ " 184 | \n",
+ " NaN | \n",
+ " 109.0 | \n",
+ " 124.0 | \n",
+ " 87.0 | \n",
+ " 82.0 | \n",
+ "
\n",
+ " \n",
+ " 185 | \n",
+ " 10.0 | \n",
+ " 118.0 | \n",
+ " 139.0 | \n",
+ " 50.0 | \n",
+ " 51.0 | \n",
+ "
\n",
+ " \n",
+ " 186 | \n",
+ " 32.0 | \n",
+ " 12.0 | \n",
+ " 71.0 | \n",
+ " 36.0 | \n",
+ " NaN | \n",
+ "
\n",
+ " \n",
+ " 187 | \n",
+ " 94.0 | \n",
+ " NaN | \n",
+ " 138.0 | \n",
+ " 13.0 | \n",
+ " 149.0 | \n",
+ "
\n",
+ " \n",
+ " 188 | \n",
+ " 65.0 | \n",
+ " 101.0 | \n",
+ " 123.0 | \n",
+ " 128.0 | \n",
+ " 86.0 | \n",
+ "
\n",
+ " \n",
+ " 189 | \n",
+ " 43.0 | \n",
+ " 94.0 | \n",
+ " NaN | \n",
+ " 29.0 | \n",
+ " 132.0 | \n",
+ "
\n",
+ " \n",
+ " 190 | \n",
+ " 68.0 | \n",
+ " 135.0 | \n",
+ " 94.0 | \n",
+ " 28.0 | \n",
+ " 125.0 | \n",
+ "
\n",
+ " \n",
+ " 191 | \n",
+ " 30.0 | \n",
+ " 60.0 | \n",
+ " 98.0 | \n",
+ " NaN | \n",
+ " 15.0 | \n",
+ "
\n",
+ " \n",
+ " 192 | \n",
+ " 89.0 | \n",
+ " 16.0 | \n",
+ " 10.0 | \n",
+ " 135.0 | \n",
+ " 4.0 | \n",
+ "
\n",
+ " \n",
+ " 193 | \n",
+ " 104.0 | \n",
+ " 139.0 | \n",
+ " 97.0 | \n",
+ " 29.0 | \n",
+ " 17.0 | \n",
+ "
\n",
+ " \n",
+ " 194 | \n",
+ " 5.0 | \n",
+ " 29.0 | \n",
+ " 41.0 | \n",
+ " 99.0 | \n",
+ " NaN | \n",
+ "
\n",
+ " \n",
+ " 195 | \n",
+ " 19.0 | \n",
+ " 102.0 | \n",
+ " 135.0 | \n",
+ " 41.0 | \n",
+ " 40.0 | \n",
+ "
\n",
+ " \n",
+ " 196 | \n",
+ " 58.0 | \n",
+ " NaN | \n",
+ " 70.0 | \n",
+ " 82.0 | \n",
+ " 64.0 | \n",
+ "
\n",
+ " \n",
+ " 197 | \n",
+ " NaN | \n",
+ " 97.0 | \n",
+ " 129.0 | \n",
+ " 76.0 | \n",
+ " 13.0 | \n",
+ "
\n",
+ " \n",
+ " 198 | \n",
+ " 131.0 | \n",
+ " 15.0 | \n",
+ " NaN | \n",
+ " 44.0 | \n",
+ " 114.0 | \n",
+ "
\n",
+ " \n",
+ " 199 | \n",
+ " 79.0 | \n",
+ " NaN | \n",
+ " 95.0 | \n",
+ " 128.0 | \n",
+ " NaN | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
100 rows × 5 columns
\n",
+ "
"
+ ],
+ "text/plain": [
+ " Python En Math Physic Chem\n",
+ "100 122.0 10.0 5.0 28.0 57.0\n",
+ "101 NaN 129.0 16.0 114.0 26.0\n",
+ "102 97.0 121.0 122.0 29.0 65.0\n",
+ "103 141.0 73.0 120.0 147.0 1.0\n",
+ "104 126.0 NaN 86.0 116.0 17.0\n",
+ "105 85.0 NaN 42.0 121.0 66.0\n",
+ "106 142.0 65.0 1.0 124.0 83.0\n",
+ "107 136.0 141.0 NaN 86.0 113.0\n",
+ "108 15.0 37.0 124.0 110.0 102.0\n",
+ "109 63.0 30.0 NaN 69.0 58.0\n",
+ "110 NaN NaN 113.0 109.0 16.0\n",
+ "111 5.0 51.0 87.0 58.0 126.0\n",
+ "112 53.0 97.0 76.0 37.0 45.0\n",
+ "113 42.0 148.0 NaN 97.0 NaN\n",
+ "114 70.0 138.0 69.0 68.0 134.0\n",
+ "115 NaN 136.0 113.0 22.0 94.0\n",
+ "116 31.0 137.0 6.0 20.0 28.0\n",
+ "117 148.0 74.0 134.0 4.0 124.0\n",
+ "118 102.0 81.0 138.0 128.0 32.0\n",
+ "119 27.0 111.0 13.0 NaN 22.0\n",
+ "120 28.0 93.0 121.0 NaN 4.0\n",
+ "121 136.0 NaN 25.0 97.0 19.0\n",
+ "122 111.0 70.0 12.0 38.0 58.0\n",
+ "123 NaN 103.0 147.0 86.0 8.0\n",
+ "124 10.0 10.0 46.0 63.0 149.0\n",
+ "125 7.0 75.0 97.0 108.0 31.0\n",
+ "126 88.0 6.0 NaN NaN 55.0\n",
+ "127 33.0 74.0 106.0 50.0 46.0\n",
+ "128 74.0 28.0 26.0 100.0 76.0\n",
+ "129 76.0 18.0 101.0 NaN NaN\n",
+ ".. ... ... ... ... ...\n",
+ "170 144.0 124.0 77.0 92.0 82.0\n",
+ "171 36.0 98.0 NaN 43.0 80.0\n",
+ "172 51.0 NaN 68.0 34.0 74.0\n",
+ "173 149.0 NaN 18.0 141.0 NaN\n",
+ "174 8.0 139.0 146.0 112.0 NaN\n",
+ "175 115.0 NaN 64.0 62.0 9.0\n",
+ "176 NaN 7.0 140.0 45.0 148.0\n",
+ "177 NaN 43.0 68.0 109.0 18.0\n",
+ "178 31.0 100.0 NaN 49.0 123.0\n",
+ "179 29.0 46.0 69.0 57.0 90.0\n",
+ "180 146.0 86.0 18.0 22.0 46.0\n",
+ "181 71.0 50.0 40.0 NaN 140.0\n",
+ "182 4.0 100.0 147.0 116.0 110.0\n",
+ "183 55.0 87.0 93.0 NaN 34.0\n",
+ "184 NaN 109.0 124.0 87.0 82.0\n",
+ "185 10.0 118.0 139.0 50.0 51.0\n",
+ "186 32.0 12.0 71.0 36.0 NaN\n",
+ "187 94.0 NaN 138.0 13.0 149.0\n",
+ "188 65.0 101.0 123.0 128.0 86.0\n",
+ "189 43.0 94.0 NaN 29.0 132.0\n",
+ "190 68.0 135.0 94.0 28.0 125.0\n",
+ "191 30.0 60.0 98.0 NaN 15.0\n",
+ "192 89.0 16.0 10.0 135.0 4.0\n",
+ "193 104.0 139.0 97.0 29.0 17.0\n",
+ "194 5.0 29.0 41.0 99.0 NaN\n",
+ "195 19.0 102.0 135.0 41.0 40.0\n",
+ "196 58.0 NaN 70.0 82.0 64.0\n",
+ "197 NaN 97.0 129.0 76.0 13.0\n",
+ "198 131.0 15.0 NaN 44.0 114.0\n",
+ "199 79.0 NaN 95.0 128.0 NaN\n",
+ "\n",
+ "[100 rows x 5 columns]"
+ ]
+ },
+ "execution_count": 37,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "# 众数填充,数量最多的那个数\n",
+ "df2"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 42,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Python | \n",
+ " En | \n",
+ " Math | \n",
+ " Physic | \n",
+ " Chem | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " 100 | \n",
+ " 82 | \n",
+ " 89 | \n",
+ " 99 | \n",
+ " 101 | \n",
+ " 125 | \n",
+ "
\n",
+ " \n",
+ " 101 | \n",
+ " 4 | \n",
+ " 31 | \n",
+ " 109 | \n",
+ " 32 | \n",
+ " 5 | \n",
+ "
\n",
+ " \n",
+ " 102 | \n",
+ " 56 | \n",
+ " 103 | \n",
+ " 56 | \n",
+ " 61 | \n",
+ " 90 | \n",
+ "
\n",
+ " \n",
+ " 103 | \n",
+ " 47 | \n",
+ " 100 | \n",
+ " 147 | \n",
+ " 138 | \n",
+ " 99 | \n",
+ "
\n",
+ " \n",
+ " 104 | \n",
+ " 38 | \n",
+ " 46 | \n",
+ " 82 | \n",
+ " 75 | \n",
+ " 44 | \n",
+ "
\n",
+ " \n",
+ " 105 | \n",
+ " 18 | \n",
+ " 11 | \n",
+ " 122 | \n",
+ " 3 | \n",
+ " 126 | \n",
+ "
\n",
+ " \n",
+ " 106 | \n",
+ " 56 | \n",
+ " 26 | \n",
+ " 106 | \n",
+ " 14 | \n",
+ " 139 | \n",
+ "
\n",
+ " \n",
+ " 107 | \n",
+ " 3 | \n",
+ " 137 | \n",
+ " 75 | \n",
+ " 67 | \n",
+ " 144 | \n",
+ "
\n",
+ " \n",
+ " 108 | \n",
+ " 35 | \n",
+ " 47 | \n",
+ " 102 | \n",
+ " 60 | \n",
+ " 63 | \n",
+ "
\n",
+ " \n",
+ " 109 | \n",
+ " 86 | \n",
+ " 126 | \n",
+ " 57 | \n",
+ " 88 | \n",
+ " 149 | \n",
+ "
\n",
+ " \n",
+ " 110 | \n",
+ " 19 | \n",
+ " 140 | \n",
+ " 30 | \n",
+ " 35 | \n",
+ " 33 | \n",
+ "
\n",
+ " \n",
+ " 111 | \n",
+ " 76 | \n",
+ " 1 | \n",
+ " 5 | \n",
+ " 11 | \n",
+ " 33 | \n",
+ "
\n",
+ " \n",
+ " 112 | \n",
+ " 31 | \n",
+ " 54 | \n",
+ " 91 | \n",
+ " 119 | \n",
+ " 69 | \n",
+ "
\n",
+ " \n",
+ " 113 | \n",
+ " 64 | \n",
+ " 37 | \n",
+ " 50 | \n",
+ " 23 | \n",
+ " 21 | \n",
+ "
\n",
+ " \n",
+ " 114 | \n",
+ " 72 | \n",
+ " 57 | \n",
+ " 138 | \n",
+ " 15 | \n",
+ " 21 | \n",
+ "
\n",
+ " \n",
+ " 115 | \n",
+ " 55 | \n",
+ " 120 | \n",
+ " 104 | \n",
+ " 32 | \n",
+ " 25 | \n",
+ "
\n",
+ " \n",
+ " 116 | \n",
+ " 96 | \n",
+ " 24 | \n",
+ " 89 | \n",
+ " 22 | \n",
+ " 146 | \n",
+ "
\n",
+ " \n",
+ " 117 | \n",
+ " 63 | \n",
+ " 0 | \n",
+ " 8 | \n",
+ " 64 | \n",
+ " 89 | \n",
+ "
\n",
+ " \n",
+ " 118 | \n",
+ " 28 | \n",
+ " 46 | \n",
+ " 125 | \n",
+ " 82 | \n",
+ " 74 | \n",
+ "
\n",
+ " \n",
+ " 119 | \n",
+ " 85 | \n",
+ " 39 | \n",
+ " 70 | \n",
+ " 132 | \n",
+ " 111 | \n",
+ "
\n",
+ " \n",
+ " 120 | \n",
+ " 109 | \n",
+ " 90 | \n",
+ " 44 | \n",
+ " 74 | \n",
+ " 39 | \n",
+ "
\n",
+ " \n",
+ " 121 | \n",
+ " 2 | \n",
+ " 148 | \n",
+ " 103 | \n",
+ " 114 | \n",
+ " 65 | \n",
+ "
\n",
+ " \n",
+ " 122 | \n",
+ " 110 | \n",
+ " 29 | \n",
+ " 99 | \n",
+ " 80 | \n",
+ " 57 | \n",
+ "
\n",
+ " \n",
+ " 123 | \n",
+ " 109 | \n",
+ " 88 | \n",
+ " 81 | \n",
+ " 135 | \n",
+ " 71 | \n",
+ "
\n",
+ " \n",
+ " 124 | \n",
+ " 70 | \n",
+ " 103 | \n",
+ " 134 | \n",
+ " 121 | \n",
+ " 121 | \n",
+ "
\n",
+ " \n",
+ " 125 | \n",
+ " 51 | \n",
+ " 92 | \n",
+ " 117 | \n",
+ " 27 | \n",
+ " 43 | \n",
+ "
\n",
+ " \n",
+ " 126 | \n",
+ " 6 | \n",
+ " 92 | \n",
+ " 97 | \n",
+ " 59 | \n",
+ " 105 | \n",
+ "
\n",
+ " \n",
+ " 127 | \n",
+ " 65 | \n",
+ " 90 | \n",
+ " 52 | \n",
+ " 148 | \n",
+ " 22 | \n",
+ "
\n",
+ " \n",
+ " 128 | \n",
+ " 4 | \n",
+ " 129 | \n",
+ " 17 | \n",
+ " 119 | \n",
+ " 13 | \n",
+ "
\n",
+ " \n",
+ " 129 | \n",
+ " 24 | \n",
+ " 100 | \n",
+ " 107 | \n",
+ " 28 | \n",
+ " 139 | \n",
+ "
\n",
+ " \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ "
\n",
+ " \n",
+ " 2070 | \n",
+ " 127 | \n",
+ " 77 | \n",
+ " 24 | \n",
+ " 16 | \n",
+ " 31 | \n",
+ "
\n",
+ " \n",
+ " 2071 | \n",
+ " 93 | \n",
+ " 61 | \n",
+ " 9 | \n",
+ " 28 | \n",
+ " 22 | \n",
+ "
\n",
+ " \n",
+ " 2072 | \n",
+ " 116 | \n",
+ " 61 | \n",
+ " 54 | \n",
+ " 8 | \n",
+ " 61 | \n",
+ "
\n",
+ " \n",
+ " 2073 | \n",
+ " 4 | \n",
+ " 72 | \n",
+ " 140 | \n",
+ " 112 | \n",
+ " 34 | \n",
+ "
\n",
+ " \n",
+ " 2074 | \n",
+ " 26 | \n",
+ " 108 | \n",
+ " 123 | \n",
+ " 32 | \n",
+ " 33 | \n",
+ "
\n",
+ " \n",
+ " 2075 | \n",
+ " 46 | \n",
+ " 130 | \n",
+ " 135 | \n",
+ " 124 | \n",
+ " 113 | \n",
+ "
\n",
+ " \n",
+ " 2076 | \n",
+ " 33 | \n",
+ " 18 | \n",
+ " 136 | \n",
+ " 38 | \n",
+ " 20 | \n",
+ "
\n",
+ " \n",
+ " 2077 | \n",
+ " 107 | \n",
+ " 11 | \n",
+ " 129 | \n",
+ " 54 | \n",
+ " 119 | \n",
+ "
\n",
+ " \n",
+ " 2078 | \n",
+ " 84 | \n",
+ " 55 | \n",
+ " 129 | \n",
+ " 37 | \n",
+ " 87 | \n",
+ "
\n",
+ " \n",
+ " 2079 | \n",
+ " 95 | \n",
+ " 50 | \n",
+ " 45 | \n",
+ " 19 | \n",
+ " 84 | \n",
+ "
\n",
+ " \n",
+ " 2080 | \n",
+ " 124 | \n",
+ " 74 | \n",
+ " 65 | \n",
+ " 140 | \n",
+ " 53 | \n",
+ "
\n",
+ " \n",
+ " 2081 | \n",
+ " 26 | \n",
+ " 35 | \n",
+ " 149 | \n",
+ " 145 | \n",
+ " 127 | \n",
+ "
\n",
+ " \n",
+ " 2082 | \n",
+ " 19 | \n",
+ " 21 | \n",
+ " 101 | \n",
+ " 3 | \n",
+ " 89 | \n",
+ "
\n",
+ " \n",
+ " 2083 | \n",
+ " 84 | \n",
+ " 10 | \n",
+ " 131 | \n",
+ " 71 | \n",
+ " 4 | \n",
+ "
\n",
+ " \n",
+ " 2084 | \n",
+ " 28 | \n",
+ " 74 | \n",
+ " 105 | \n",
+ " 68 | \n",
+ " 89 | \n",
+ "
\n",
+ " \n",
+ " 2085 | \n",
+ " 23 | \n",
+ " 93 | \n",
+ " 84 | \n",
+ " 97 | \n",
+ " 88 | \n",
+ "
\n",
+ " \n",
+ " 2086 | \n",
+ " 86 | \n",
+ " 133 | \n",
+ " 26 | \n",
+ " 125 | \n",
+ " 13 | \n",
+ "
\n",
+ " \n",
+ " 2087 | \n",
+ " 21 | \n",
+ " 124 | \n",
+ " 40 | \n",
+ " 115 | \n",
+ " 5 | \n",
+ "
\n",
+ " \n",
+ " 2088 | \n",
+ " 20 | \n",
+ " 15 | \n",
+ " 35 | \n",
+ " 31 | \n",
+ " 37 | \n",
+ "
\n",
+ " \n",
+ " 2089 | \n",
+ " 96 | \n",
+ " 123 | \n",
+ " 123 | \n",
+ " 5 | \n",
+ " 64 | \n",
+ "
\n",
+ " \n",
+ " 2090 | \n",
+ " 22 | \n",
+ " 43 | \n",
+ " 92 | \n",
+ " 78 | \n",
+ " 60 | \n",
+ "
\n",
+ " \n",
+ " 2091 | \n",
+ " 16 | \n",
+ " 31 | \n",
+ " 17 | \n",
+ " 60 | \n",
+ " 58 | \n",
+ "
\n",
+ " \n",
+ " 2092 | \n",
+ " 65 | \n",
+ " 18 | \n",
+ " 13 | \n",
+ " 13 | \n",
+ " 34 | \n",
+ "
\n",
+ " \n",
+ " 2093 | \n",
+ " 69 | \n",
+ " 49 | \n",
+ " 109 | \n",
+ " 40 | \n",
+ " 58 | \n",
+ "
\n",
+ " \n",
+ " 2094 | \n",
+ " 128 | \n",
+ " 46 | \n",
+ " 10 | \n",
+ " 82 | \n",
+ " 111 | \n",
+ "
\n",
+ " \n",
+ " 2095 | \n",
+ " 26 | \n",
+ " 59 | \n",
+ " 8 | \n",
+ " 54 | \n",
+ " 149 | \n",
+ "
\n",
+ " \n",
+ " 2096 | \n",
+ " 111 | \n",
+ " 47 | \n",
+ " 90 | \n",
+ " 92 | \n",
+ " 66 | \n",
+ "
\n",
+ " \n",
+ " 2097 | \n",
+ " 5 | \n",
+ " 97 | \n",
+ " 73 | \n",
+ " 140 | \n",
+ " 104 | \n",
+ "
\n",
+ " \n",
+ " 2098 | \n",
+ " 102 | \n",
+ " 6 | \n",
+ " 7 | \n",
+ " 5 | \n",
+ " 119 | \n",
+ "
\n",
+ " \n",
+ " 2099 | \n",
+ " 97 | \n",
+ " 19 | \n",
+ " 77 | \n",
+ " 143 | \n",
+ " 48 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
2000 rows × 5 columns
\n",
+ "
"
+ ],
+ "text/plain": [
+ " Python En Math Physic Chem\n",
+ "100 82 89 99 101 125\n",
+ "101 4 31 109 32 5\n",
+ "102 56 103 56 61 90\n",
+ "103 47 100 147 138 99\n",
+ "104 38 46 82 75 44\n",
+ "105 18 11 122 3 126\n",
+ "106 56 26 106 14 139\n",
+ "107 3 137 75 67 144\n",
+ "108 35 47 102 60 63\n",
+ "109 86 126 57 88 149\n",
+ "110 19 140 30 35 33\n",
+ "111 76 1 5 11 33\n",
+ "112 31 54 91 119 69\n",
+ "113 64 37 50 23 21\n",
+ "114 72 57 138 15 21\n",
+ "115 55 120 104 32 25\n",
+ "116 96 24 89 22 146\n",
+ "117 63 0 8 64 89\n",
+ "118 28 46 125 82 74\n",
+ "119 85 39 70 132 111\n",
+ "120 109 90 44 74 39\n",
+ "121 2 148 103 114 65\n",
+ "122 110 29 99 80 57\n",
+ "123 109 88 81 135 71\n",
+ "124 70 103 134 121 121\n",
+ "125 51 92 117 27 43\n",
+ "126 6 92 97 59 105\n",
+ "127 65 90 52 148 22\n",
+ "128 4 129 17 119 13\n",
+ "129 24 100 107 28 139\n",
+ "... ... ... ... ... ...\n",
+ "2070 127 77 24 16 31\n",
+ "2071 93 61 9 28 22\n",
+ "2072 116 61 54 8 61\n",
+ "2073 4 72 140 112 34\n",
+ "2074 26 108 123 32 33\n",
+ "2075 46 130 135 124 113\n",
+ "2076 33 18 136 38 20\n",
+ "2077 107 11 129 54 119\n",
+ "2078 84 55 129 37 87\n",
+ "2079 95 50 45 19 84\n",
+ "2080 124 74 65 140 53\n",
+ "2081 26 35 149 145 127\n",
+ "2082 19 21 101 3 89\n",
+ "2083 84 10 131 71 4\n",
+ "2084 28 74 105 68 89\n",
+ "2085 23 93 84 97 88\n",
+ "2086 86 133 26 125 13\n",
+ "2087 21 124 40 115 5\n",
+ "2088 20 15 35 31 37\n",
+ "2089 96 123 123 5 64\n",
+ "2090 22 43 92 78 60\n",
+ "2091 16 31 17 60 58\n",
+ "2092 65 18 13 13 34\n",
+ "2093 69 49 109 40 58\n",
+ "2094 128 46 10 82 111\n",
+ "2095 26 59 8 54 149\n",
+ "2096 111 47 90 92 66\n",
+ "2097 5 97 73 140 104\n",
+ "2098 102 6 7 5 119\n",
+ "2099 97 19 77 143 48\n",
+ "\n",
+ "[2000 rows x 5 columns]"
+ ]
+ },
+ "execution_count": 42,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "df = DataFrame(np.random.randint(0,150,size = (2000,5)),index = np.arange(100,2100),columns=['Python','En','Math','Physic','Chem'])\n",
+ "df"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 43,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "for i in range(1000):\n",
+ " # 行索引\n",
+ " index = np.random.randint(100,2100,size =1)[0]\n",
+ "\n",
+ " cols = df.columns\n",
+ "\n",
+ " # 列索引\n",
+ " col = np.random.choice(cols)\n",
+ "\n",
+ " df.loc[index,col] = None"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 44,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "Python 190\n",
+ "En 200\n",
+ "Math 194\n",
+ "Physic 189\n",
+ "Chem 181\n",
+ "dtype: int64"
+ ]
+ },
+ "execution_count": 44,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "df.isnull().sum()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 45,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Python | \n",
+ " En | \n",
+ " Math | \n",
+ " Physic | \n",
+ " Chem | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " 100 | \n",
+ " 82.0 | \n",
+ " 89.0 | \n",
+ " 99.0 | \n",
+ " 101.0 | \n",
+ " 125.0 | \n",
+ "
\n",
+ " \n",
+ " 101 | \n",
+ " 4.0 | \n",
+ " 31.0 | \n",
+ " 109.0 | \n",
+ " 32.0 | \n",
+ " 5.0 | \n",
+ "
\n",
+ " \n",
+ " 102 | \n",
+ " 56.0 | \n",
+ " 103.0 | \n",
+ " 56.0 | \n",
+ " NaN | \n",
+ " 90.0 | \n",
+ "
\n",
+ " \n",
+ " 103 | \n",
+ " 47.0 | \n",
+ " 100.0 | \n",
+ " 147.0 | \n",
+ " 138.0 | \n",
+ " 99.0 | \n",
+ "
\n",
+ " \n",
+ " 104 | \n",
+ " 38.0 | \n",
+ " 46.0 | \n",
+ " NaN | \n",
+ " 75.0 | \n",
+ " 44.0 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " Python En Math Physic Chem\n",
+ "100 82.0 89.0 99.0 101.0 125.0\n",
+ "101 4.0 31.0 109.0 32.0 5.0\n",
+ "102 56.0 103.0 56.0 NaN 90.0\n",
+ "103 47.0 100.0 147.0 138.0 99.0\n",
+ "104 38.0 46.0 NaN 75.0 44.0"
+ ]
+ },
+ "execution_count": 45,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "df.head()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 46,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Python | \n",
+ " En | \n",
+ " Math | \n",
+ " Physic | \n",
+ " Chem | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " 2095 | \n",
+ " 26.0 | \n",
+ " 59.0 | \n",
+ " 8.0 | \n",
+ " 54.0 | \n",
+ " 149.0 | \n",
+ "
\n",
+ " \n",
+ " 2096 | \n",
+ " NaN | \n",
+ " 47.0 | \n",
+ " 90.0 | \n",
+ " 92.0 | \n",
+ " 66.0 | \n",
+ "
\n",
+ " \n",
+ " 2097 | \n",
+ " 5.0 | \n",
+ " 97.0 | \n",
+ " 73.0 | \n",
+ " 140.0 | \n",
+ " 104.0 | \n",
+ "
\n",
+ " \n",
+ " 2098 | \n",
+ " 102.0 | \n",
+ " 6.0 | \n",
+ " 7.0 | \n",
+ " 5.0 | \n",
+ " 119.0 | \n",
+ "
\n",
+ " \n",
+ " 2099 | \n",
+ " 97.0 | \n",
+ " 19.0 | \n",
+ " 77.0 | \n",
+ " NaN | \n",
+ " 48.0 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " Python En Math Physic Chem\n",
+ "2095 26.0 59.0 8.0 54.0 149.0\n",
+ "2096 NaN 47.0 90.0 92.0 66.0\n",
+ "2097 5.0 97.0 73.0 140.0 104.0\n",
+ "2098 102.0 6.0 7.0 5.0 119.0\n",
+ "2099 97.0 19.0 77.0 NaN 48.0"
+ ]
+ },
+ "execution_count": 46,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "df.tail()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 48,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "array([ 82., 4., 56., 47., 38., 18., 3., 35., 86., 19., 76.,\n",
+ " 31., 64., 72., 55., 96., 63., 28., 85., 109., 2., 110.,\n",
+ " 70., 51., 6., 65., 24., 48., 44., 11., 114., 129., 87.,\n",
+ " 108., 125., nan, 140., 132., 91., 34., 54., 30., 12., 98.,\n",
+ " 142., 79., 13., 77., 40., 139., 39., 81., 112., 36., 22.,\n",
+ " 5., 120., 17., 127., 119., 59., 146., 89., 103., 8., 97.,\n",
+ " 130., 73., 83., 122., 95., 100., 41., 21., 136., 80., 101.,\n",
+ " 50., 27., 71., 16., 141., 126., 102., 145., 15., 52., 94.,\n",
+ " 10., 33., 137., 9., 128., 88., 26., 84., 93., 1., 7.,\n",
+ " 131., 107., 148., 0., 105., 66., 32., 115., 118., 58., 53.,\n",
+ " 29., 42., 57., 62., 25., 60., 69., 133., 68., 20., 106.,\n",
+ " 147., 78., 90., 124., 149., 92., 75., 117., 143., 99., 37.,\n",
+ " 123., 45., 61., 121., 135., 138., 116., 14., 104., 74., 46.,\n",
+ " 111., 23., 43., 49., 144., 113., 67., 134.])"
+ ]
+ },
+ "execution_count": 48,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "# 去重之后的数据\n",
+ "df['Python'].unique()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 49,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "143.0 20\n",
+ "136.0 20\n",
+ "102.0 19\n",
+ "105.0 19\n",
+ "26.0 19\n",
+ "69.0 19\n",
+ "31.0 18\n",
+ "148.0 18\n",
+ "75.0 18\n",
+ "139.0 18\n",
+ "1.0 18\n",
+ "35.0 17\n",
+ "140.0 17\n",
+ "110.0 17\n",
+ "125.0 17\n",
+ "146.0 17\n",
+ "141.0 17\n",
+ "64.0 16\n",
+ "30.0 16\n",
+ "79.0 16\n",
+ "73.0 16\n",
+ "40.0 16\n",
+ "10.0 15\n",
+ "6.0 15\n",
+ "65.0 15\n",
+ "81.0 15\n",
+ "28.0 15\n",
+ "48.0 15\n",
+ "92.0 15\n",
+ "103.0 15\n",
+ " ..\n",
+ "104.0 9\n",
+ "12.0 9\n",
+ "116.0 9\n",
+ "13.0 9\n",
+ "59.0 9\n",
+ "93.0 9\n",
+ "124.0 9\n",
+ "85.0 8\n",
+ "135.0 8\n",
+ "131.0 8\n",
+ "68.0 8\n",
+ "66.0 8\n",
+ "62.0 8\n",
+ "120.0 8\n",
+ "17.0 8\n",
+ "25.0 8\n",
+ "145.0 7\n",
+ "58.0 7\n",
+ "134.0 7\n",
+ "113.0 7\n",
+ "123.0 7\n",
+ "39.0 7\n",
+ "34.0 7\n",
+ "43.0 7\n",
+ "74.0 6\n",
+ "144.0 6\n",
+ "132.0 6\n",
+ "142.0 5\n",
+ "67.0 5\n",
+ "49.0 5\n",
+ "Name: Python, Length: 150, dtype: int64"
+ ]
+ },
+ "execution_count": 49,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "df['Python'].value_counts()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 53,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "8.0 21\n",
+ "96.0 19\n",
+ "118.0 19\n",
+ "24.0 19\n",
+ "43.0 19\n",
+ "27.0 19\n",
+ "19.0 19\n",
+ "41.0 18\n",
+ "0.0 18\n",
+ "3.0 18\n",
+ "52.0 18\n",
+ "4.0 17\n",
+ "137.0 17\n",
+ "1.0 17\n",
+ "101.0 17\n",
+ "51.0 17\n",
+ "39.0 17\n",
+ "100.0 17\n",
+ "127.0 17\n",
+ "115.0 16\n",
+ "33.0 16\n",
+ "112.0 16\n",
+ "92.0 16\n",
+ "126.0 16\n",
+ "133.0 15\n",
+ "32.0 15\n",
+ "89.0 15\n",
+ "95.0 15\n",
+ "36.0 15\n",
+ "93.0 15\n",
+ " ..\n",
+ "12.0 9\n",
+ "28.0 9\n",
+ "106.0 9\n",
+ "45.0 9\n",
+ "80.0 9\n",
+ "84.0 9\n",
+ "58.0 9\n",
+ "79.0 9\n",
+ "71.0 9\n",
+ "83.0 9\n",
+ "142.0 9\n",
+ "7.0 9\n",
+ "6.0 8\n",
+ "61.0 8\n",
+ "149.0 8\n",
+ "34.0 8\n",
+ "20.0 8\n",
+ "38.0 8\n",
+ "130.0 8\n",
+ "104.0 7\n",
+ "120.0 7\n",
+ "56.0 7\n",
+ "146.0 7\n",
+ "98.0 7\n",
+ "134.0 6\n",
+ "123.0 6\n",
+ "35.0 6\n",
+ "87.0 5\n",
+ "42.0 5\n",
+ "119.0 4\n",
+ "Name: En, Length: 150, dtype: int64"
+ ]
+ },
+ "execution_count": 53,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "en = df['En'].value_counts()\n",
+ "en"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 54,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "8.0"
+ ]
+ },
+ "execution_count": 54,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "en.index[0]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 52,
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Python 75.0\n",
+ "En 74.0\n",
+ "Math 77.5\n",
+ "Physic 73.0\n",
+ "Chem 72.0\n",
+ "dtype: float64 \n"
+ ]
+ }
+ ],
+ "source": [
+ "s = df.median()\n",
+ "print(s,type(s))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 55,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "zhongshu = []\n",
+ "for col in df.columns:\n",
+ " zhongshu.append(df[col].value_counts().index[0])"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 57,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "Python 143.0\n",
+ "En 8.0\n",
+ "Math 80.0\n",
+ "Physic 31.0\n",
+ "Chem 125.0\n",
+ "dtype: float64"
+ ]
+ },
+ "execution_count": 57,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "s = Series(zhongshu,index = df.columns)\n",
+ "s"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 60,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Python | \n",
+ " En | \n",
+ " Math | \n",
+ " Physic | \n",
+ " Chem | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " 100 | \n",
+ " 82.0 | \n",
+ " 89.0 | \n",
+ " 99.0 | \n",
+ " 101.0 | \n",
+ " 125.0 | \n",
+ "
\n",
+ " \n",
+ " 101 | \n",
+ " 4.0 | \n",
+ " 31.0 | \n",
+ " 109.0 | \n",
+ " 32.0 | \n",
+ " 5.0 | \n",
+ "
\n",
+ " \n",
+ " 102 | \n",
+ " 56.0 | \n",
+ " 103.0 | \n",
+ " 56.0 | \n",
+ " 31.0 | \n",
+ " 90.0 | \n",
+ "
\n",
+ " \n",
+ " 103 | \n",
+ " 47.0 | \n",
+ " 100.0 | \n",
+ " 147.0 | \n",
+ " 138.0 | \n",
+ " 99.0 | \n",
+ "
\n",
+ " \n",
+ " 104 | \n",
+ " 38.0 | \n",
+ " 46.0 | \n",
+ " 80.0 | \n",
+ " 75.0 | \n",
+ " 44.0 | \n",
+ "
\n",
+ " \n",
+ " 105 | \n",
+ " 18.0 | \n",
+ " 11.0 | \n",
+ " 122.0 | \n",
+ " 3.0 | \n",
+ " 126.0 | \n",
+ "
\n",
+ " \n",
+ " 106 | \n",
+ " 56.0 | \n",
+ " 26.0 | \n",
+ " 106.0 | \n",
+ " 14.0 | \n",
+ " 139.0 | \n",
+ "
\n",
+ " \n",
+ " 107 | \n",
+ " 3.0 | \n",
+ " 137.0 | \n",
+ " 75.0 | \n",
+ " 67.0 | \n",
+ " 144.0 | \n",
+ "
\n",
+ " \n",
+ " 108 | \n",
+ " 35.0 | \n",
+ " 47.0 | \n",
+ " 102.0 | \n",
+ " 60.0 | \n",
+ " 63.0 | \n",
+ "
\n",
+ " \n",
+ " 109 | \n",
+ " 86.0 | \n",
+ " 126.0 | \n",
+ " 80.0 | \n",
+ " 88.0 | \n",
+ " 149.0 | \n",
+ "
\n",
+ " \n",
+ " 110 | \n",
+ " 19.0 | \n",
+ " 140.0 | \n",
+ " 80.0 | \n",
+ " 35.0 | \n",
+ " 33.0 | \n",
+ "
\n",
+ " \n",
+ " 111 | \n",
+ " 76.0 | \n",
+ " 8.0 | \n",
+ " 5.0 | \n",
+ " 11.0 | \n",
+ " 33.0 | \n",
+ "
\n",
+ " \n",
+ " 112 | \n",
+ " 31.0 | \n",
+ " 54.0 | \n",
+ " 91.0 | \n",
+ " 119.0 | \n",
+ " 69.0 | \n",
+ "
\n",
+ " \n",
+ " 113 | \n",
+ " 64.0 | \n",
+ " 37.0 | \n",
+ " 50.0 | \n",
+ " 23.0 | \n",
+ " 21.0 | \n",
+ "
\n",
+ " \n",
+ " 114 | \n",
+ " 72.0 | \n",
+ " 57.0 | \n",
+ " 138.0 | \n",
+ " 15.0 | \n",
+ " 21.0 | \n",
+ "
\n",
+ " \n",
+ " 115 | \n",
+ " 55.0 | \n",
+ " 120.0 | \n",
+ " 104.0 | \n",
+ " 32.0 | \n",
+ " 25.0 | \n",
+ "
\n",
+ " \n",
+ " 116 | \n",
+ " 96.0 | \n",
+ " 24.0 | \n",
+ " 89.0 | \n",
+ " 31.0 | \n",
+ " 146.0 | \n",
+ "
\n",
+ " \n",
+ " 117 | \n",
+ " 63.0 | \n",
+ " 8.0 | \n",
+ " 8.0 | \n",
+ " 64.0 | \n",
+ " 89.0 | \n",
+ "
\n",
+ " \n",
+ " 118 | \n",
+ " 28.0 | \n",
+ " 8.0 | \n",
+ " 125.0 | \n",
+ " 82.0 | \n",
+ " 74.0 | \n",
+ "
\n",
+ " \n",
+ " 119 | \n",
+ " 85.0 | \n",
+ " 39.0 | \n",
+ " 70.0 | \n",
+ " 132.0 | \n",
+ " 111.0 | \n",
+ "
\n",
+ " \n",
+ " 120 | \n",
+ " 109.0 | \n",
+ " 90.0 | \n",
+ " 80.0 | \n",
+ " 74.0 | \n",
+ " 39.0 | \n",
+ "
\n",
+ " \n",
+ " 121 | \n",
+ " 2.0 | \n",
+ " 8.0 | \n",
+ " 103.0 | \n",
+ " 114.0 | \n",
+ " 65.0 | \n",
+ "
\n",
+ " \n",
+ " 122 | \n",
+ " 110.0 | \n",
+ " 29.0 | \n",
+ " 99.0 | \n",
+ " 80.0 | \n",
+ " 57.0 | \n",
+ "
\n",
+ " \n",
+ " 123 | \n",
+ " 109.0 | \n",
+ " 88.0 | \n",
+ " 81.0 | \n",
+ " 135.0 | \n",
+ " 71.0 | \n",
+ "
\n",
+ " \n",
+ " 124 | \n",
+ " 70.0 | \n",
+ " 103.0 | \n",
+ " 134.0 | \n",
+ " 121.0 | \n",
+ " 121.0 | \n",
+ "
\n",
+ " \n",
+ " 125 | \n",
+ " 51.0 | \n",
+ " 92.0 | \n",
+ " 117.0 | \n",
+ " 31.0 | \n",
+ " 43.0 | \n",
+ "
\n",
+ " \n",
+ " 126 | \n",
+ " 6.0 | \n",
+ " 92.0 | \n",
+ " 97.0 | \n",
+ " 59.0 | \n",
+ " 105.0 | \n",
+ "
\n",
+ " \n",
+ " 127 | \n",
+ " 65.0 | \n",
+ " 90.0 | \n",
+ " 52.0 | \n",
+ " 148.0 | \n",
+ " 22.0 | \n",
+ "
\n",
+ " \n",
+ " 128 | \n",
+ " 4.0 | \n",
+ " 129.0 | \n",
+ " 17.0 | \n",
+ " 119.0 | \n",
+ " 13.0 | \n",
+ "
\n",
+ " \n",
+ " 129 | \n",
+ " 24.0 | \n",
+ " 100.0 | \n",
+ " 107.0 | \n",
+ " 28.0 | \n",
+ " 139.0 | \n",
+ "
\n",
+ " \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ "
\n",
+ " \n",
+ " 2070 | \n",
+ " 127.0 | \n",
+ " 77.0 | \n",
+ " 24.0 | \n",
+ " 16.0 | \n",
+ " 125.0 | \n",
+ "
\n",
+ " \n",
+ " 2071 | \n",
+ " 93.0 | \n",
+ " 61.0 | \n",
+ " 9.0 | \n",
+ " 28.0 | \n",
+ " 22.0 | \n",
+ "
\n",
+ " \n",
+ " 2072 | \n",
+ " 116.0 | \n",
+ " 61.0 | \n",
+ " 54.0 | \n",
+ " 8.0 | \n",
+ " 61.0 | \n",
+ "
\n",
+ " \n",
+ " 2073 | \n",
+ " 4.0 | \n",
+ " 72.0 | \n",
+ " 140.0 | \n",
+ " 31.0 | \n",
+ " 34.0 | \n",
+ "
\n",
+ " \n",
+ " 2074 | \n",
+ " 143.0 | \n",
+ " 108.0 | \n",
+ " 123.0 | \n",
+ " 32.0 | \n",
+ " 33.0 | \n",
+ "
\n",
+ " \n",
+ " 2075 | \n",
+ " 46.0 | \n",
+ " 8.0 | \n",
+ " 135.0 | \n",
+ " 124.0 | \n",
+ " 113.0 | \n",
+ "
\n",
+ " \n",
+ " 2076 | \n",
+ " 143.0 | \n",
+ " 18.0 | \n",
+ " 136.0 | \n",
+ " 38.0 | \n",
+ " 125.0 | \n",
+ "
\n",
+ " \n",
+ " 2077 | \n",
+ " 143.0 | \n",
+ " 11.0 | \n",
+ " 129.0 | \n",
+ " 54.0 | \n",
+ " 119.0 | \n",
+ "
\n",
+ " \n",
+ " 2078 | \n",
+ " 84.0 | \n",
+ " 55.0 | \n",
+ " 129.0 | \n",
+ " 37.0 | \n",
+ " 87.0 | \n",
+ "
\n",
+ " \n",
+ " 2079 | \n",
+ " 95.0 | \n",
+ " 50.0 | \n",
+ " 45.0 | \n",
+ " 19.0 | \n",
+ " 84.0 | \n",
+ "
\n",
+ " \n",
+ " 2080 | \n",
+ " 124.0 | \n",
+ " 74.0 | \n",
+ " 65.0 | \n",
+ " 31.0 | \n",
+ " 53.0 | \n",
+ "
\n",
+ " \n",
+ " 2081 | \n",
+ " 26.0 | \n",
+ " 35.0 | \n",
+ " 149.0 | \n",
+ " 145.0 | \n",
+ " 127.0 | \n",
+ "
\n",
+ " \n",
+ " 2082 | \n",
+ " 19.0 | \n",
+ " 21.0 | \n",
+ " 101.0 | \n",
+ " 3.0 | \n",
+ " 89.0 | \n",
+ "
\n",
+ " \n",
+ " 2083 | \n",
+ " 84.0 | \n",
+ " 8.0 | \n",
+ " 131.0 | \n",
+ " 71.0 | \n",
+ " 4.0 | \n",
+ "
\n",
+ " \n",
+ " 2084 | \n",
+ " 28.0 | \n",
+ " 74.0 | \n",
+ " 105.0 | \n",
+ " 68.0 | \n",
+ " 89.0 | \n",
+ "
\n",
+ " \n",
+ " 2085 | \n",
+ " 23.0 | \n",
+ " 93.0 | \n",
+ " 84.0 | \n",
+ " 97.0 | \n",
+ " 88.0 | \n",
+ "
\n",
+ " \n",
+ " 2086 | \n",
+ " 86.0 | \n",
+ " 133.0 | \n",
+ " 26.0 | \n",
+ " 125.0 | \n",
+ " 13.0 | \n",
+ "
\n",
+ " \n",
+ " 2087 | \n",
+ " 21.0 | \n",
+ " 124.0 | \n",
+ " 40.0 | \n",
+ " 31.0 | \n",
+ " 5.0 | \n",
+ "
\n",
+ " \n",
+ " 2088 | \n",
+ " 20.0 | \n",
+ " 15.0 | \n",
+ " 35.0 | \n",
+ " 31.0 | \n",
+ " 37.0 | \n",
+ "
\n",
+ " \n",
+ " 2089 | \n",
+ " 96.0 | \n",
+ " 123.0 | \n",
+ " 123.0 | \n",
+ " 5.0 | \n",
+ " 64.0 | \n",
+ "
\n",
+ " \n",
+ " 2090 | \n",
+ " 22.0 | \n",
+ " 43.0 | \n",
+ " 92.0 | \n",
+ " 78.0 | \n",
+ " 60.0 | \n",
+ "
\n",
+ " \n",
+ " 2091 | \n",
+ " 16.0 | \n",
+ " 31.0 | \n",
+ " 17.0 | \n",
+ " 60.0 | \n",
+ " 58.0 | \n",
+ "
\n",
+ " \n",
+ " 2092 | \n",
+ " 65.0 | \n",
+ " 18.0 | \n",
+ " 13.0 | \n",
+ " 13.0 | \n",
+ " 34.0 | \n",
+ "
\n",
+ " \n",
+ " 2093 | \n",
+ " 69.0 | \n",
+ " 49.0 | \n",
+ " 109.0 | \n",
+ " 40.0 | \n",
+ " 58.0 | \n",
+ "
\n",
+ " \n",
+ " 2094 | \n",
+ " 128.0 | \n",
+ " 46.0 | \n",
+ " 10.0 | \n",
+ " 82.0 | \n",
+ " 111.0 | \n",
+ "
\n",
+ " \n",
+ " 2095 | \n",
+ " 26.0 | \n",
+ " 59.0 | \n",
+ " 8.0 | \n",
+ " 54.0 | \n",
+ " 149.0 | \n",
+ "
\n",
+ " \n",
+ " 2096 | \n",
+ " 143.0 | \n",
+ " 47.0 | \n",
+ " 90.0 | \n",
+ " 92.0 | \n",
+ " 66.0 | \n",
+ "
\n",
+ " \n",
+ " 2097 | \n",
+ " 5.0 | \n",
+ " 97.0 | \n",
+ " 73.0 | \n",
+ " 140.0 | \n",
+ " 104.0 | \n",
+ "
\n",
+ " \n",
+ " 2098 | \n",
+ " 102.0 | \n",
+ " 6.0 | \n",
+ " 7.0 | \n",
+ " 5.0 | \n",
+ " 119.0 | \n",
+ "
\n",
+ " \n",
+ " 2099 | \n",
+ " 97.0 | \n",
+ " 19.0 | \n",
+ " 77.0 | \n",
+ " 31.0 | \n",
+ " 48.0 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
2000 rows × 5 columns
\n",
+ "
"
+ ],
+ "text/plain": [
+ " Python En Math Physic Chem\n",
+ "100 82.0 89.0 99.0 101.0 125.0\n",
+ "101 4.0 31.0 109.0 32.0 5.0\n",
+ "102 56.0 103.0 56.0 31.0 90.0\n",
+ "103 47.0 100.0 147.0 138.0 99.0\n",
+ "104 38.0 46.0 80.0 75.0 44.0\n",
+ "105 18.0 11.0 122.0 3.0 126.0\n",
+ "106 56.0 26.0 106.0 14.0 139.0\n",
+ "107 3.0 137.0 75.0 67.0 144.0\n",
+ "108 35.0 47.0 102.0 60.0 63.0\n",
+ "109 86.0 126.0 80.0 88.0 149.0\n",
+ "110 19.0 140.0 80.0 35.0 33.0\n",
+ "111 76.0 8.0 5.0 11.0 33.0\n",
+ "112 31.0 54.0 91.0 119.0 69.0\n",
+ "113 64.0 37.0 50.0 23.0 21.0\n",
+ "114 72.0 57.0 138.0 15.0 21.0\n",
+ "115 55.0 120.0 104.0 32.0 25.0\n",
+ "116 96.0 24.0 89.0 31.0 146.0\n",
+ "117 63.0 8.0 8.0 64.0 89.0\n",
+ "118 28.0 8.0 125.0 82.0 74.0\n",
+ "119 85.0 39.0 70.0 132.0 111.0\n",
+ "120 109.0 90.0 80.0 74.0 39.0\n",
+ "121 2.0 8.0 103.0 114.0 65.0\n",
+ "122 110.0 29.0 99.0 80.0 57.0\n",
+ "123 109.0 88.0 81.0 135.0 71.0\n",
+ "124 70.0 103.0 134.0 121.0 121.0\n",
+ "125 51.0 92.0 117.0 31.0 43.0\n",
+ "126 6.0 92.0 97.0 59.0 105.0\n",
+ "127 65.0 90.0 52.0 148.0 22.0\n",
+ "128 4.0 129.0 17.0 119.0 13.0\n",
+ "129 24.0 100.0 107.0 28.0 139.0\n",
+ "... ... ... ... ... ...\n",
+ "2070 127.0 77.0 24.0 16.0 125.0\n",
+ "2071 93.0 61.0 9.0 28.0 22.0\n",
+ "2072 116.0 61.0 54.0 8.0 61.0\n",
+ "2073 4.0 72.0 140.0 31.0 34.0\n",
+ "2074 143.0 108.0 123.0 32.0 33.0\n",
+ "2075 46.0 8.0 135.0 124.0 113.0\n",
+ "2076 143.0 18.0 136.0 38.0 125.0\n",
+ "2077 143.0 11.0 129.0 54.0 119.0\n",
+ "2078 84.0 55.0 129.0 37.0 87.0\n",
+ "2079 95.0 50.0 45.0 19.0 84.0\n",
+ "2080 124.0 74.0 65.0 31.0 53.0\n",
+ "2081 26.0 35.0 149.0 145.0 127.0\n",
+ "2082 19.0 21.0 101.0 3.0 89.0\n",
+ "2083 84.0 8.0 131.0 71.0 4.0\n",
+ "2084 28.0 74.0 105.0 68.0 89.0\n",
+ "2085 23.0 93.0 84.0 97.0 88.0\n",
+ "2086 86.0 133.0 26.0 125.0 13.0\n",
+ "2087 21.0 124.0 40.0 31.0 5.0\n",
+ "2088 20.0 15.0 35.0 31.0 37.0\n",
+ "2089 96.0 123.0 123.0 5.0 64.0\n",
+ "2090 22.0 43.0 92.0 78.0 60.0\n",
+ "2091 16.0 31.0 17.0 60.0 58.0\n",
+ "2092 65.0 18.0 13.0 13.0 34.0\n",
+ "2093 69.0 49.0 109.0 40.0 58.0\n",
+ "2094 128.0 46.0 10.0 82.0 111.0\n",
+ "2095 26.0 59.0 8.0 54.0 149.0\n",
+ "2096 143.0 47.0 90.0 92.0 66.0\n",
+ "2097 5.0 97.0 73.0 140.0 104.0\n",
+ "2098 102.0 6.0 7.0 5.0 119.0\n",
+ "2099 97.0 19.0 77.0 31.0 48.0\n",
+ "\n",
+ "[2000 rows x 5 columns]"
+ ]
+ },
+ "execution_count": 60,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "df2 = df.fillna(s)\n",
+ "df2"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 61,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "Python 0\n",
+ "En 0\n",
+ "Math 0\n",
+ "Physic 0\n",
+ "Chem 0\n",
+ "dtype: int64"
+ ]
+ },
+ "execution_count": 61,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "df2.isnull().sum()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 62,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "Python 190\n",
+ "En 200\n",
+ "Math 194\n",
+ "Physic 189\n",
+ "Chem 181\n",
+ "dtype: int64"
+ ]
+ },
+ "execution_count": 62,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "df.isnull().sum()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 65,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Python | \n",
+ " En | \n",
+ " Math | \n",
+ " Physic | \n",
+ " Chem | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " 100 | \n",
+ " 82.0 | \n",
+ " 89.0 | \n",
+ " 99.0 | \n",
+ " 101.0 | \n",
+ " 125.0 | \n",
+ "
\n",
+ " \n",
+ " 101 | \n",
+ " 4.0 | \n",
+ " 31.0 | \n",
+ " 109.0 | \n",
+ " 32.0 | \n",
+ " 5.0 | \n",
+ "
\n",
+ " \n",
+ " 102 | \n",
+ " 56.0 | \n",
+ " 103.0 | \n",
+ " 56.0 | \n",
+ " NaN | \n",
+ " 90.0 | \n",
+ "
\n",
+ " \n",
+ " 103 | \n",
+ " 47.0 | \n",
+ " 100.0 | \n",
+ " 147.0 | \n",
+ " 138.0 | \n",
+ " 99.0 | \n",
+ "
\n",
+ " \n",
+ " 104 | \n",
+ " 38.0 | \n",
+ " 46.0 | \n",
+ " NaN | \n",
+ " 75.0 | \n",
+ " 44.0 | \n",
+ "
\n",
+ " \n",
+ " 105 | \n",
+ " 18.0 | \n",
+ " 11.0 | \n",
+ " 122.0 | \n",
+ " 3.0 | \n",
+ " 126.0 | \n",
+ "
\n",
+ " \n",
+ " 106 | \n",
+ " 56.0 | \n",
+ " 26.0 | \n",
+ " 106.0 | \n",
+ " 14.0 | \n",
+ " 139.0 | \n",
+ "
\n",
+ " \n",
+ " 107 | \n",
+ " 3.0 | \n",
+ " 137.0 | \n",
+ " 75.0 | \n",
+ " 67.0 | \n",
+ " 144.0 | \n",
+ "
\n",
+ " \n",
+ " 108 | \n",
+ " 35.0 | \n",
+ " 47.0 | \n",
+ " 102.0 | \n",
+ " 60.0 | \n",
+ " 63.0 | \n",
+ "
\n",
+ " \n",
+ " 109 | \n",
+ " 86.0 | \n",
+ " 126.0 | \n",
+ " NaN | \n",
+ " 88.0 | \n",
+ " 149.0 | \n",
+ "
\n",
+ " \n",
+ " 110 | \n",
+ " 19.0 | \n",
+ " 140.0 | \n",
+ " NaN | \n",
+ " 35.0 | \n",
+ " 33.0 | \n",
+ "
\n",
+ " \n",
+ " 111 | \n",
+ " 76.0 | \n",
+ " NaN | \n",
+ " 5.0 | \n",
+ " 11.0 | \n",
+ " 33.0 | \n",
+ "
\n",
+ " \n",
+ " 112 | \n",
+ " 31.0 | \n",
+ " 54.0 | \n",
+ " 91.0 | \n",
+ " 119.0 | \n",
+ " 69.0 | \n",
+ "
\n",
+ " \n",
+ " 113 | \n",
+ " 64.0 | \n",
+ " 37.0 | \n",
+ " 50.0 | \n",
+ " 23.0 | \n",
+ " 21.0 | \n",
+ "
\n",
+ " \n",
+ " 114 | \n",
+ " 72.0 | \n",
+ " 57.0 | \n",
+ " 138.0 | \n",
+ " 15.0 | \n",
+ " 21.0 | \n",
+ "
\n",
+ " \n",
+ " 115 | \n",
+ " 55.0 | \n",
+ " 120.0 | \n",
+ " 104.0 | \n",
+ " 32.0 | \n",
+ " 25.0 | \n",
+ "
\n",
+ " \n",
+ " 116 | \n",
+ " 96.0 | \n",
+ " 24.0 | \n",
+ " 89.0 | \n",
+ " NaN | \n",
+ " 146.0 | \n",
+ "
\n",
+ " \n",
+ " 117 | \n",
+ " 63.0 | \n",
+ " NaN | \n",
+ " 8.0 | \n",
+ " 64.0 | \n",
+ " 89.0 | \n",
+ "
\n",
+ " \n",
+ " 118 | \n",
+ " 28.0 | \n",
+ " NaN | \n",
+ " 125.0 | \n",
+ " 82.0 | \n",
+ " 74.0 | \n",
+ "
\n",
+ " \n",
+ " 119 | \n",
+ " 85.0 | \n",
+ " 39.0 | \n",
+ " 70.0 | \n",
+ " 132.0 | \n",
+ " 111.0 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " Python En Math Physic Chem\n",
+ "100 82.0 89.0 99.0 101.0 125.0\n",
+ "101 4.0 31.0 109.0 32.0 5.0\n",
+ "102 56.0 103.0 56.0 NaN 90.0\n",
+ "103 47.0 100.0 147.0 138.0 99.0\n",
+ "104 38.0 46.0 NaN 75.0 44.0\n",
+ "105 18.0 11.0 122.0 3.0 126.0\n",
+ "106 56.0 26.0 106.0 14.0 139.0\n",
+ "107 3.0 137.0 75.0 67.0 144.0\n",
+ "108 35.0 47.0 102.0 60.0 63.0\n",
+ "109 86.0 126.0 NaN 88.0 149.0\n",
+ "110 19.0 140.0 NaN 35.0 33.0\n",
+ "111 76.0 NaN 5.0 11.0 33.0\n",
+ "112 31.0 54.0 91.0 119.0 69.0\n",
+ "113 64.0 37.0 50.0 23.0 21.0\n",
+ "114 72.0 57.0 138.0 15.0 21.0\n",
+ "115 55.0 120.0 104.0 32.0 25.0\n",
+ "116 96.0 24.0 89.0 NaN 146.0\n",
+ "117 63.0 NaN 8.0 64.0 89.0\n",
+ "118 28.0 NaN 125.0 82.0 74.0\n",
+ "119 85.0 39.0 70.0 132.0 111.0"
+ ]
+ },
+ "execution_count": 65,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "df3 = df.iloc[:20]\n",
+ "df3"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 70,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Python | \n",
+ " En | \n",
+ " Math | \n",
+ " Physic | \n",
+ " Chem | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " 100 | \n",
+ " 82.0 | \n",
+ " 89.0 | \n",
+ " 99.0 | \n",
+ " 101.0 | \n",
+ " 125.0 | \n",
+ "
\n",
+ " \n",
+ " 101 | \n",
+ " 4.0 | \n",
+ " 31.0 | \n",
+ " 109.0 | \n",
+ " 32.0 | \n",
+ " 5.0 | \n",
+ "
\n",
+ " \n",
+ " 102 | \n",
+ " 56.0 | \n",
+ " 103.0 | \n",
+ " 56.0 | \n",
+ " 90.0 | \n",
+ " 90.0 | \n",
+ "
\n",
+ " \n",
+ " 103 | \n",
+ " 47.0 | \n",
+ " 100.0 | \n",
+ " 147.0 | \n",
+ " 138.0 | \n",
+ " 99.0 | \n",
+ "
\n",
+ " \n",
+ " 104 | \n",
+ " 38.0 | \n",
+ " 46.0 | \n",
+ " 75.0 | \n",
+ " 75.0 | \n",
+ " 44.0 | \n",
+ "
\n",
+ " \n",
+ " 105 | \n",
+ " 18.0 | \n",
+ " 11.0 | \n",
+ " 122.0 | \n",
+ " 3.0 | \n",
+ " 126.0 | \n",
+ "
\n",
+ " \n",
+ " 106 | \n",
+ " 56.0 | \n",
+ " 26.0 | \n",
+ " 106.0 | \n",
+ " 14.0 | \n",
+ " 139.0 | \n",
+ "
\n",
+ " \n",
+ " 107 | \n",
+ " 3.0 | \n",
+ " 137.0 | \n",
+ " 75.0 | \n",
+ " 67.0 | \n",
+ " 144.0 | \n",
+ "
\n",
+ " \n",
+ " 108 | \n",
+ " 35.0 | \n",
+ " 47.0 | \n",
+ " 102.0 | \n",
+ " 60.0 | \n",
+ " 63.0 | \n",
+ "
\n",
+ " \n",
+ " 109 | \n",
+ " 86.0 | \n",
+ " 126.0 | \n",
+ " 88.0 | \n",
+ " 88.0 | \n",
+ " 149.0 | \n",
+ "
\n",
+ " \n",
+ " 110 | \n",
+ " 19.0 | \n",
+ " 140.0 | \n",
+ " 35.0 | \n",
+ " 35.0 | \n",
+ " 33.0 | \n",
+ "
\n",
+ " \n",
+ " 111 | \n",
+ " 76.0 | \n",
+ " 5.0 | \n",
+ " 5.0 | \n",
+ " 11.0 | \n",
+ " 33.0 | \n",
+ "
\n",
+ " \n",
+ " 112 | \n",
+ " 31.0 | \n",
+ " 54.0 | \n",
+ " 91.0 | \n",
+ " 119.0 | \n",
+ " 69.0 | \n",
+ "
\n",
+ " \n",
+ " 113 | \n",
+ " 64.0 | \n",
+ " 37.0 | \n",
+ " 50.0 | \n",
+ " 23.0 | \n",
+ " 21.0 | \n",
+ "
\n",
+ " \n",
+ " 114 | \n",
+ " 72.0 | \n",
+ " 57.0 | \n",
+ " 138.0 | \n",
+ " 15.0 | \n",
+ " 21.0 | \n",
+ "
\n",
+ " \n",
+ " 115 | \n",
+ " 55.0 | \n",
+ " 120.0 | \n",
+ " 104.0 | \n",
+ " 32.0 | \n",
+ " 25.0 | \n",
+ "
\n",
+ " \n",
+ " 116 | \n",
+ " 96.0 | \n",
+ " 24.0 | \n",
+ " 89.0 | \n",
+ " 146.0 | \n",
+ " 146.0 | \n",
+ "
\n",
+ " \n",
+ " 117 | \n",
+ " 63.0 | \n",
+ " 8.0 | \n",
+ " 8.0 | \n",
+ " 64.0 | \n",
+ " 89.0 | \n",
+ "
\n",
+ " \n",
+ " 118 | \n",
+ " 28.0 | \n",
+ " 125.0 | \n",
+ " 125.0 | \n",
+ " 82.0 | \n",
+ " 74.0 | \n",
+ "
\n",
+ " \n",
+ " 119 | \n",
+ " 85.0 | \n",
+ " 39.0 | \n",
+ " 70.0 | \n",
+ " 132.0 | \n",
+ " 111.0 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " Python En Math Physic Chem\n",
+ "100 82.0 89.0 99.0 101.0 125.0\n",
+ "101 4.0 31.0 109.0 32.0 5.0\n",
+ "102 56.0 103.0 56.0 90.0 90.0\n",
+ "103 47.0 100.0 147.0 138.0 99.0\n",
+ "104 38.0 46.0 75.0 75.0 44.0\n",
+ "105 18.0 11.0 122.0 3.0 126.0\n",
+ "106 56.0 26.0 106.0 14.0 139.0\n",
+ "107 3.0 137.0 75.0 67.0 144.0\n",
+ "108 35.0 47.0 102.0 60.0 63.0\n",
+ "109 86.0 126.0 88.0 88.0 149.0\n",
+ "110 19.0 140.0 35.0 35.0 33.0\n",
+ "111 76.0 5.0 5.0 11.0 33.0\n",
+ "112 31.0 54.0 91.0 119.0 69.0\n",
+ "113 64.0 37.0 50.0 23.0 21.0\n",
+ "114 72.0 57.0 138.0 15.0 21.0\n",
+ "115 55.0 120.0 104.0 32.0 25.0\n",
+ "116 96.0 24.0 89.0 146.0 146.0\n",
+ "117 63.0 8.0 8.0 64.0 89.0\n",
+ "118 28.0 125.0 125.0 82.0 74.0\n",
+ "119 85.0 39.0 70.0 132.0 111.0"
+ ]
+ },
+ "execution_count": 70,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "'''method : {'backfill', 'bfill', 'pad', 'ffill', None}, default None\n",
+ " Method to use for filling holes in reindexed Series\n",
+ " pad / ffill: propagate last valid observation forward to next valid\n",
+ " backfill / bfill: use NEXT valid observation to fill gap'''\n",
+ "df3.fillna(method='bfill',axis = 1)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 71,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "(2000, 5)"
+ ]
+ },
+ "execution_count": 71,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "#数据量足够大,空数据比较少,直接删除\n",
+ "df.shape"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "df.dro"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 3",
+ "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.7.7"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}
diff --git "a/Day76-90/code/.ipynb_checkpoints/4-pandas\345\244\232\345\261\202\347\264\242\345\274\225-checkpoint.ipynb" "b/Day76-90/code/.ipynb_checkpoints/4-pandas\345\244\232\345\261\202\347\264\242\345\274\225-checkpoint.ipynb"
new file mode 100644
index 000000000..d8e0d1ee9
--- /dev/null
+++ "b/Day76-90/code/.ipynb_checkpoints/4-pandas\345\244\232\345\261\202\347\264\242\345\274\225-checkpoint.ipynb"
@@ -0,0 +1,494 @@
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "import numpy as np\n",
+ "\n",
+ "import pandas as pd\n",
+ "# 数据分析BI-------->人工智能AI\n",
+ "# 数据分析和数据挖掘一个意思,\n",
+ "# 工具和软件:Excel 免费版\n",
+ "# SPSS(一人一年10000)、SAS(一人一年5000)、Matlab 收费\n",
+ "# R、Python(全方位语言,流行) 免费\n",
+ "# Python + numpy + scipy + pandas + matplotlib + seaborn + pyEcharts + sklearn + kereas(Tensorflow)+…… \n",
+ "# 代码,自动化(数据输入----输出结果)\n",
+ "from pandas import Series,DataFrame"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "a 63\n",
+ "b 107\n",
+ "c 16\n",
+ "d 35\n",
+ "e 140\n",
+ "f 83\n",
+ "dtype: int32"
+ ]
+ },
+ "execution_count": 2,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "# 多层索引,行列\n",
+ "# 单层索引\n",
+ "s = Series(np.random.randint(0,150,size = 6),index=list('abcdef'))\n",
+ "s"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "张三 期中 114\n",
+ " 期末 131\n",
+ "李四 期中 3\n",
+ " 期末 63\n",
+ "王五 期中 107\n",
+ " 期末 34\n",
+ "dtype: int32"
+ ]
+ },
+ "execution_count": 3,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "# 多层索引,两层,三层以上(规则一样)\n",
+ "s2 = Series(np.random.randint(0,150,size = 6),index = pd.MultiIndex.from_product([['张三','李四','王五'],['期中','期末']]))\n",
+ "s2"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [
+ {
+ "ename": "NameError",
+ "evalue": "name 'DataFrame' is not defined",
+ "output_type": "error",
+ "traceback": [
+ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
+ "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
+ "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mdf\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mDataFrame\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrandom\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrandint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m150\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0msize\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0;36m6\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m3\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mcolumns\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'Python'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m'En'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m'Math'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mindex\u001b[0m \u001b[0;34m=\u001b[0m\u001b[0mpd\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mMultiIndex\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfrom_product\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'张三'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m'李四'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m'王五'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'期中'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m'期末'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0mdf\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
+ "\u001b[0;31mNameError\u001b[0m: name 'DataFrame' is not defined"
+ ]
+ }
+ ],
+ "source": [
+ "df = DataFrame(np.random.randint(0,150,size = (6,3)),columns=['Python','En','Math'],index =pd.MultiIndex.from_product([['张三','李四','王五'],['期中','期末']]) )\n",
+ "\n",
+ "df"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " Python | \n",
+ " En | \n",
+ " Math | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " 张三 | \n",
+ " 期中 | \n",
+ " A | \n",
+ " 15 | \n",
+ " 31 | \n",
+ " 17 | \n",
+ "
\n",
+ " \n",
+ " B | \n",
+ " 82 | \n",
+ " 56 | \n",
+ " 123 | \n",
+ "
\n",
+ " \n",
+ " 期末 | \n",
+ " A | \n",
+ " 14 | \n",
+ " 2 | \n",
+ " 78 | \n",
+ "
\n",
+ " \n",
+ " B | \n",
+ " 69 | \n",
+ " 50 | \n",
+ " 17 | \n",
+ "
\n",
+ " \n",
+ " 李四 | \n",
+ " 期中 | \n",
+ " A | \n",
+ " 91 | \n",
+ " 87 | \n",
+ " 143 | \n",
+ "
\n",
+ " \n",
+ " B | \n",
+ " 120 | \n",
+ " 118 | \n",
+ " 39 | \n",
+ "
\n",
+ " \n",
+ " 期末 | \n",
+ " A | \n",
+ " 56 | \n",
+ " 76 | \n",
+ " 55 | \n",
+ "
\n",
+ " \n",
+ " B | \n",
+ " 11 | \n",
+ " 105 | \n",
+ " 121 | \n",
+ "
\n",
+ " \n",
+ " 王五 | \n",
+ " 期中 | \n",
+ " A | \n",
+ " 147 | \n",
+ " 78 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " B | \n",
+ " 128 | \n",
+ " 126 | \n",
+ " 146 | \n",
+ "
\n",
+ " \n",
+ " 期末 | \n",
+ " A | \n",
+ " 49 | \n",
+ " 45 | \n",
+ " 114 | \n",
+ "
\n",
+ " \n",
+ " B | \n",
+ " 121 | \n",
+ " 26 | \n",
+ " 77 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " Python En Math\n",
+ "张三 期中 A 15 31 17\n",
+ " B 82 56 123\n",
+ " 期末 A 14 2 78\n",
+ " B 69 50 17\n",
+ "李四 期中 A 91 87 143\n",
+ " B 120 118 39\n",
+ " 期末 A 56 76 55\n",
+ " B 11 105 121\n",
+ "王五 期中 A 147 78 1\n",
+ " B 128 126 146\n",
+ " 期末 A 49 45 114\n",
+ " B 121 26 77"
+ ]
+ },
+ "execution_count": 5,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "# 三层索引\n",
+ "df3 = DataFrame(np.random.randint(0,150,size = (12,3)),columns=['Python','En','Math'],index =pd.MultiIndex.from_product([['张三','李四','王五'],['期中','期末'],['A','B']]) )\n",
+ "\n",
+ "df3"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 9,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "73"
+ ]
+ },
+ "execution_count": 9,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "# 先获取列后获取行\n",
+ "df['Python']['张三']['期中']"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 14,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "df2 = df.copy()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 16,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " | \n",
+ " Python | \n",
+ " En | \n",
+ " Math | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " 张三 | \n",
+ " 期中 | \n",
+ " 73 | \n",
+ " 5 | \n",
+ " 25 | \n",
+ "
\n",
+ " \n",
+ " 期末 | \n",
+ " 37 | \n",
+ " 36 | \n",
+ " 56 | \n",
+ "
\n",
+ " \n",
+ " 李四 | \n",
+ " 期中 | \n",
+ " 149 | \n",
+ " 81 | \n",
+ " 142 | \n",
+ "
\n",
+ " \n",
+ " 期末 | \n",
+ " 71 | \n",
+ " 138 | \n",
+ " 0 | \n",
+ "
\n",
+ " \n",
+ " 王五 | \n",
+ " 期中 | \n",
+ " 11 | \n",
+ " 94 | \n",
+ " 103 | \n",
+ "
\n",
+ " \n",
+ " 期末 | \n",
+ " 25 | \n",
+ " 121 | \n",
+ " 83 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " Python En Math\n",
+ "张三 期中 73 5 25\n",
+ " 期末 37 36 56\n",
+ "李四 期中 149 81 142\n",
+ " 期末 71 138 0\n",
+ "王五 期中 11 94 103\n",
+ " 期末 25 121 83"
+ ]
+ },
+ "execution_count": 16,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "df2.sort_index()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 22,
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "73"
+ ]
+ },
+ "execution_count": 22,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "# 先获取行,后获取列\n",
+ "df.loc['张三'].loc['期中']['Python']"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 19,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " | \n",
+ " Python | \n",
+ " En | \n",
+ " Math | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " 张三 | \n",
+ " 期中 | \n",
+ " 73 | \n",
+ " 5 | \n",
+ " 25 | \n",
+ "
\n",
+ " \n",
+ " 期末 | \n",
+ " 37 | \n",
+ " 36 | \n",
+ " 56 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " Python En Math\n",
+ "张三 期中 73 5 25\n",
+ " 期末 37 36 56"
+ ]
+ },
+ "execution_count": 19,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "df.iloc[[0,1]]"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 3",
+ "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.7.7"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}
diff --git "a/Day76-90/code/.ipynb_checkpoints/5-pandas\345\244\232\345\261\202\347\264\242\345\274\225\350\256\241\347\256\227-checkpoint.ipynb" "b/Day76-90/code/.ipynb_checkpoints/5-pandas\345\244\232\345\261\202\347\264\242\345\274\225\350\256\241\347\256\227-checkpoint.ipynb"
new file mode 100644
index 000000000..4bcaad27c
--- /dev/null
+++ "b/Day76-90/code/.ipynb_checkpoints/5-pandas\345\244\232\345\261\202\347\264\242\345\274\225\350\256\241\347\256\227-checkpoint.ipynb"
@@ -0,0 +1,1000 @@
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "import numpy as np\n",
+ "\n",
+ "import pandas as pd\n",
+ "\n",
+ "from pandas import Series,DataFrame"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Python | \n",
+ " En | \n",
+ " Math | \n",
+ "
\n",
+ " \n",
+ " | \n",
+ " 期中 | \n",
+ " 期末 | \n",
+ " 期中 | \n",
+ " 期末 | \n",
+ " 期中 | \n",
+ " 期末 | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " A | \n",
+ " 131 | \n",
+ " 101 | \n",
+ " 1 | \n",
+ " 73 | \n",
+ " 15 | \n",
+ " 17 | \n",
+ "
\n",
+ " \n",
+ " B | \n",
+ " 62 | \n",
+ " 34 | \n",
+ " 53 | \n",
+ " 101 | \n",
+ " 24 | \n",
+ " 57 | \n",
+ "
\n",
+ " \n",
+ " C | \n",
+ " 24 | \n",
+ " 76 | \n",
+ " 36 | \n",
+ " 117 | \n",
+ " 123 | \n",
+ " 105 | \n",
+ "
\n",
+ " \n",
+ " D | \n",
+ " 112 | \n",
+ " 46 | \n",
+ " 79 | \n",
+ " 42 | \n",
+ " 46 | \n",
+ " 122 | \n",
+ "
\n",
+ " \n",
+ " E | \n",
+ " 66 | \n",
+ " 113 | \n",
+ " 104 | \n",
+ " 45 | \n",
+ " 10 | \n",
+ " 108 | \n",
+ "
\n",
+ " \n",
+ " F | \n",
+ " 111 | \n",
+ " 108 | \n",
+ " 4 | \n",
+ " 41 | \n",
+ " 132 | \n",
+ " 21 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " Python En Math \n",
+ " 期中 期末 期中 期末 期中 期末\n",
+ "A 131 101 1 73 15 17\n",
+ "B 62 34 53 101 24 57\n",
+ "C 24 76 36 117 123 105\n",
+ "D 112 46 79 42 46 122\n",
+ "E 66 113 104 45 10 108\n",
+ "F 111 108 4 41 132 21"
+ ]
+ },
+ "execution_count": 2,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "# 多层列索引\n",
+ "df = DataFrame(np.random.randint(0,150,size = (6,6)),index = list('ABCDEF'),\n",
+ " columns=pd.MultiIndex.from_product([['Python','En','Math'],['期中','期末']]))\n",
+ "df"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {
+ "scrolled": false
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "Python 期中 84.3\n",
+ " 期末 79.7\n",
+ "En 期中 46.2\n",
+ " 期末 69.8\n",
+ "Math 期中 58.3\n",
+ " 期末 71.7\n",
+ "dtype: float64"
+ ]
+ },
+ "execution_count": 5,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "# round保留2位小数\n",
+ "df.mean().round(1)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 10,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Python | \n",
+ " En | \n",
+ " Math | \n",
+ "
\n",
+ " \n",
+ " | \n",
+ " 期中 | \n",
+ " 期末 | \n",
+ " 期中 | \n",
+ " 期末 | \n",
+ " 期中 | \n",
+ " 期末 | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " A | \n",
+ " 131 | \n",
+ " 101 | \n",
+ " 1 | \n",
+ " 73 | \n",
+ " 15 | \n",
+ " 17 | \n",
+ "
\n",
+ " \n",
+ " B | \n",
+ " 62 | \n",
+ " 34 | \n",
+ " 53 | \n",
+ " 101 | \n",
+ " 24 | \n",
+ " 57 | \n",
+ "
\n",
+ " \n",
+ " C | \n",
+ " 24 | \n",
+ " 76 | \n",
+ " 36 | \n",
+ " 117 | \n",
+ " 123 | \n",
+ " 105 | \n",
+ "
\n",
+ " \n",
+ " D | \n",
+ " 112 | \n",
+ " 46 | \n",
+ " 79 | \n",
+ " 42 | \n",
+ " 46 | \n",
+ " 122 | \n",
+ "
\n",
+ " \n",
+ " E | \n",
+ " 66 | \n",
+ " 113 | \n",
+ " 104 | \n",
+ " 45 | \n",
+ " 10 | \n",
+ " 108 | \n",
+ "
\n",
+ " \n",
+ " F | \n",
+ " 111 | \n",
+ " 108 | \n",
+ " 4 | \n",
+ " 41 | \n",
+ " 132 | \n",
+ " 21 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " Python En Math \n",
+ " 期中 期末 期中 期末 期中 期末\n",
+ "A 131 101 1 73 15 17\n",
+ "B 62 34 53 101 24 57\n",
+ "C 24 76 36 117 123 105\n",
+ "D 112 46 79 42 46 122\n",
+ "E 66 113 104 45 10 108\n",
+ "F 111 108 4 41 132 21"
+ ]
+ },
+ "execution_count": 10,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "df"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 13,
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Python | \n",
+ " En | \n",
+ " Math | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " A | \n",
+ " 116.0 | \n",
+ " 37.0 | \n",
+ " 16.0 | \n",
+ "
\n",
+ " \n",
+ " B | \n",
+ " 48.0 | \n",
+ " 77.0 | \n",
+ " 40.5 | \n",
+ "
\n",
+ " \n",
+ " C | \n",
+ " 50.0 | \n",
+ " 76.5 | \n",
+ " 114.0 | \n",
+ "
\n",
+ " \n",
+ " D | \n",
+ " 79.0 | \n",
+ " 60.5 | \n",
+ " 84.0 | \n",
+ "
\n",
+ " \n",
+ " E | \n",
+ " 89.5 | \n",
+ " 74.5 | \n",
+ " 59.0 | \n",
+ "
\n",
+ " \n",
+ " F | \n",
+ " 109.5 | \n",
+ " 22.5 | \n",
+ " 76.5 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " Python En Math\n",
+ "A 116.0 37.0 16.0\n",
+ "B 48.0 77.0 40.5\n",
+ "C 50.0 76.5 114.0\n",
+ "D 79.0 60.5 84.0\n",
+ "E 89.5 74.5 59.0\n",
+ "F 109.5 22.5 76.5"
+ ]
+ },
+ "execution_count": 13,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "# axis = 0代表行\n",
+ "# axis = 1代表列\n",
+ "df.mean(axis = 1,level = 0)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": []
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 15,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " 期中 | \n",
+ " 期末 | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " A | \n",
+ " 49.0 | \n",
+ " 63.7 | \n",
+ "
\n",
+ " \n",
+ " B | \n",
+ " 46.3 | \n",
+ " 64.0 | \n",
+ "
\n",
+ " \n",
+ " C | \n",
+ " 61.0 | \n",
+ " 99.3 | \n",
+ "
\n",
+ " \n",
+ " D | \n",
+ " 79.0 | \n",
+ " 70.0 | \n",
+ "
\n",
+ " \n",
+ " E | \n",
+ " 60.0 | \n",
+ " 88.7 | \n",
+ "
\n",
+ " \n",
+ " F | \n",
+ " 82.3 | \n",
+ " 56.7 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " 期中 期末\n",
+ "A 49.0 63.7\n",
+ "B 46.3 64.0\n",
+ "C 61.0 99.3\n",
+ "D 79.0 70.0\n",
+ "E 60.0 88.7\n",
+ "F 82.3 56.7"
+ ]
+ },
+ "execution_count": 15,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "df.mean(axis = 1,level = 1).round(1)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 17,
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Python | \n",
+ " En | \n",
+ " Math | \n",
+ "
\n",
+ " \n",
+ " | \n",
+ " 期中 | \n",
+ " 期末 | \n",
+ " 期中 | \n",
+ " 期末 | \n",
+ " 期中 | \n",
+ " 期末 | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " A | \n",
+ " 131 | \n",
+ " 101 | \n",
+ " 1 | \n",
+ " 73 | \n",
+ " 15 | \n",
+ " 17 | \n",
+ "
\n",
+ " \n",
+ " B | \n",
+ " 62 | \n",
+ " 34 | \n",
+ " 53 | \n",
+ " 101 | \n",
+ " 24 | \n",
+ " 57 | \n",
+ "
\n",
+ " \n",
+ " C | \n",
+ " 24 | \n",
+ " 76 | \n",
+ " 36 | \n",
+ " 117 | \n",
+ " 123 | \n",
+ " 105 | \n",
+ "
\n",
+ " \n",
+ " D | \n",
+ " 112 | \n",
+ " 46 | \n",
+ " 79 | \n",
+ " 42 | \n",
+ " 46 | \n",
+ " 122 | \n",
+ "
\n",
+ " \n",
+ " E | \n",
+ " 66 | \n",
+ " 113 | \n",
+ " 104 | \n",
+ " 45 | \n",
+ " 10 | \n",
+ " 108 | \n",
+ "
\n",
+ " \n",
+ " F | \n",
+ " 111 | \n",
+ " 108 | \n",
+ " 4 | \n",
+ " 41 | \n",
+ " 132 | \n",
+ " 21 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " Python En Math \n",
+ " 期中 期末 期中 期末 期中 期末\n",
+ "A 131 101 1 73 15 17\n",
+ "B 62 34 53 101 24 57\n",
+ "C 24 76 36 117 123 105\n",
+ "D 112 46 79 42 46 122\n",
+ "E 66 113 104 45 10 108\n",
+ "F 111 108 4 41 132 21"
+ ]
+ },
+ "execution_count": 17,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "df"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 20,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " | \n",
+ " En | \n",
+ " Math | \n",
+ " Python | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " A | \n",
+ " 期中 | \n",
+ " 1 | \n",
+ " 15 | \n",
+ " 131 | \n",
+ "
\n",
+ " \n",
+ " 期末 | \n",
+ " 73 | \n",
+ " 17 | \n",
+ " 101 | \n",
+ "
\n",
+ " \n",
+ " B | \n",
+ " 期中 | \n",
+ " 53 | \n",
+ " 24 | \n",
+ " 62 | \n",
+ "
\n",
+ " \n",
+ " 期末 | \n",
+ " 101 | \n",
+ " 57 | \n",
+ " 34 | \n",
+ "
\n",
+ " \n",
+ " C | \n",
+ " 期中 | \n",
+ " 36 | \n",
+ " 123 | \n",
+ " 24 | \n",
+ "
\n",
+ " \n",
+ " 期末 | \n",
+ " 117 | \n",
+ " 105 | \n",
+ " 76 | \n",
+ "
\n",
+ " \n",
+ " D | \n",
+ " 期中 | \n",
+ " 79 | \n",
+ " 46 | \n",
+ " 112 | \n",
+ "
\n",
+ " \n",
+ " 期末 | \n",
+ " 42 | \n",
+ " 122 | \n",
+ " 46 | \n",
+ "
\n",
+ " \n",
+ " E | \n",
+ " 期中 | \n",
+ " 104 | \n",
+ " 10 | \n",
+ " 66 | \n",
+ "
\n",
+ " \n",
+ " 期末 | \n",
+ " 45 | \n",
+ " 108 | \n",
+ " 113 | \n",
+ "
\n",
+ " \n",
+ " F | \n",
+ " 期中 | \n",
+ " 4 | \n",
+ " 132 | \n",
+ " 111 | \n",
+ "
\n",
+ " \n",
+ " 期末 | \n",
+ " 41 | \n",
+ " 21 | \n",
+ " 108 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " En Math Python\n",
+ "A 期中 1 15 131\n",
+ " 期末 73 17 101\n",
+ "B 期中 53 24 62\n",
+ " 期末 101 57 34\n",
+ "C 期中 36 123 24\n",
+ " 期末 117 105 76\n",
+ "D 期中 79 46 112\n",
+ " 期末 42 122 46\n",
+ "E 期中 104 10 66\n",
+ " 期末 45 108 113\n",
+ "F 期中 4 132 111\n",
+ " 期末 41 21 108"
+ ]
+ },
+ "execution_count": 20,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "# 行和列的多层索引,进行转换\n",
+ "# Stack the prescribed level(s) from columns to index.\n",
+ "# 从列变成行\n",
+ "df2 = df.stack(level = 1)\n",
+ "df2"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 21,
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " En | \n",
+ " Math | \n",
+ " Python | \n",
+ "
\n",
+ " \n",
+ " | \n",
+ " A | \n",
+ " B | \n",
+ " C | \n",
+ " D | \n",
+ " E | \n",
+ " F | \n",
+ " A | \n",
+ " B | \n",
+ " C | \n",
+ " D | \n",
+ " E | \n",
+ " F | \n",
+ " A | \n",
+ " B | \n",
+ " C | \n",
+ " D | \n",
+ " E | \n",
+ " F | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " 期中 | \n",
+ " 1 | \n",
+ " 53 | \n",
+ " 36 | \n",
+ " 79 | \n",
+ " 104 | \n",
+ " 4 | \n",
+ " 15 | \n",
+ " 24 | \n",
+ " 123 | \n",
+ " 46 | \n",
+ " 10 | \n",
+ " 132 | \n",
+ " 131 | \n",
+ " 62 | \n",
+ " 24 | \n",
+ " 112 | \n",
+ " 66 | \n",
+ " 111 | \n",
+ "
\n",
+ " \n",
+ " 期末 | \n",
+ " 73 | \n",
+ " 101 | \n",
+ " 117 | \n",
+ " 42 | \n",
+ " 45 | \n",
+ " 41 | \n",
+ " 17 | \n",
+ " 57 | \n",
+ " 105 | \n",
+ " 122 | \n",
+ " 108 | \n",
+ " 21 | \n",
+ " 101 | \n",
+ " 34 | \n",
+ " 76 | \n",
+ " 46 | \n",
+ " 113 | \n",
+ " 108 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " En Math Python \n",
+ " A B C D E F A B C D E F A B C D E F\n",
+ "期中 1 53 36 79 104 4 15 24 123 46 10 132 131 62 24 112 66 111\n",
+ "期末 73 101 117 42 45 41 17 57 105 122 108 21 101 34 76 46 113 108"
+ ]
+ },
+ "execution_count": 21,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "# 从行变成列\n",
+ "df2.unstack(level= 0 )"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 22,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " En | \n",
+ " Math | \n",
+ " Python | \n",
+ "
\n",
+ " \n",
+ " | \n",
+ " 期中 | \n",
+ " 期末 | \n",
+ " 期中 | \n",
+ " 期末 | \n",
+ " 期中 | \n",
+ " 期末 | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " A | \n",
+ " 1 | \n",
+ " 73 | \n",
+ " 15 | \n",
+ " 17 | \n",
+ " 131 | \n",
+ " 101 | \n",
+ "
\n",
+ " \n",
+ " B | \n",
+ " 53 | \n",
+ " 101 | \n",
+ " 24 | \n",
+ " 57 | \n",
+ " 62 | \n",
+ " 34 | \n",
+ "
\n",
+ " \n",
+ " C | \n",
+ " 36 | \n",
+ " 117 | \n",
+ " 123 | \n",
+ " 105 | \n",
+ " 24 | \n",
+ " 76 | \n",
+ "
\n",
+ " \n",
+ " D | \n",
+ " 79 | \n",
+ " 42 | \n",
+ " 46 | \n",
+ " 122 | \n",
+ " 112 | \n",
+ " 46 | \n",
+ "
\n",
+ " \n",
+ " E | \n",
+ " 104 | \n",
+ " 45 | \n",
+ " 10 | \n",
+ " 108 | \n",
+ " 66 | \n",
+ " 113 | \n",
+ "
\n",
+ " \n",
+ " F | \n",
+ " 4 | \n",
+ " 41 | \n",
+ " 132 | \n",
+ " 21 | \n",
+ " 111 | \n",
+ " 108 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " En Math Python \n",
+ " 期中 期末 期中 期末 期中 期末\n",
+ "A 1 73 15 17 131 101\n",
+ "B 53 101 24 57 62 34\n",
+ "C 36 117 123 105 24 76\n",
+ "D 79 42 46 122 112 46\n",
+ "E 104 45 10 108 66 113\n",
+ "F 4 41 132 21 111 108"
+ ]
+ },
+ "execution_count": 22,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "df2.unstack(level = 1)"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 3",
+ "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.7.7"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}
diff --git "a/Day76-90/code/.ipynb_checkpoints/6-pandas\346\225\260\346\215\256\351\233\206\346\210\220-checkpoint.ipynb" "b/Day76-90/code/.ipynb_checkpoints/6-pandas\346\225\260\346\215\256\351\233\206\346\210\220-checkpoint.ipynb"
new file mode 100644
index 000000000..7df4f33a7
--- /dev/null
+++ "b/Day76-90/code/.ipynb_checkpoints/6-pandas\346\225\260\346\215\256\351\233\206\346\210\220-checkpoint.ipynb"
@@ -0,0 +1,1209 @@
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "import numpy as np\n",
+ "\n",
+ "import pandas as pd\n",
+ "from pandas import Series,DataFrame"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# 数据分析数据挖掘\n",
+ "# 有数据情况下:\n",
+ "# 数据预处理\n",
+ "# 数据清洗(空数据,异常值)\n",
+ "# 数据集成(多个数据合并到一起,级联)数据可能存放在多个表中\n",
+ "# 数据转化\n",
+ "# 数据规约(属性减少(不重要的属性删除),数据减少去重操作)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "array([[ 5, 12, 67, 29, 46, 103, 53, 53, 139, 87],\n",
+ " [126, 33, 55, 104, 45, 70, 96, 133, 116, 43],\n",
+ " [ 84, 45, 17, 42, 19, 11, 125, 43, 54, 39],\n",
+ " [ 97, 68, 99, 90, 28, 60, 135, 84, 111, 63],\n",
+ " [114, 56, 30, 81, 48, 73, 119, 65, 20, 22]])"
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ },
+ {
+ "data": {
+ "text/plain": [
+ "array([[115, 128, 122, 127, 4, 135, 26, 25, 131, 139],\n",
+ " [ 66, 119, 37, 136, 101, 40, 102, 127, 148, 127],\n",
+ " [ 89, 80, 140, 133, 51, 142, 47, 27, 54, 23],\n",
+ " [ 64, 127, 33, 128, 60, 106, 67, 94, 110, 76],\n",
+ " [ 6, 21, 23, 96, 10, 62, 26, 79, 149, 43],\n",
+ " [116, 143, 132, 118, 68, 21, 57, 133, 124, 124]])"
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "# 首先看numpy数组的集成\n",
+ "nd1 = np.random.randint(0,150,size = (5,10))\n",
+ "\n",
+ "nd2 = np.random.randint(0,150,size = (6,10))\n",
+ "display(nd1,nd2)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "array([[ 5, 12, 67, 29, 46, 103, 53, 53, 139, 87],\n",
+ " [126, 33, 55, 104, 45, 70, 96, 133, 116, 43],\n",
+ " [ 84, 45, 17, 42, 19, 11, 125, 43, 54, 39],\n",
+ " [ 97, 68, 99, 90, 28, 60, 135, 84, 111, 63],\n",
+ " [114, 56, 30, 81, 48, 73, 119, 65, 20, 22],\n",
+ " [115, 128, 122, 127, 4, 135, 26, 25, 131, 139],\n",
+ " [ 66, 119, 37, 136, 101, 40, 102, 127, 148, 127],\n",
+ " [ 89, 80, 140, 133, 51, 142, 47, 27, 54, 23],\n",
+ " [ 64, 127, 33, 128, 60, 106, 67, 94, 110, 76],\n",
+ " [ 6, 21, 23, 96, 10, 62, 26, 79, 149, 43],\n",
+ " [116, 143, 132, 118, 68, 21, 57, 133, 124, 124]])"
+ ]
+ },
+ "execution_count": 3,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "# 原来数据一个5行,一个是6行,级联之后变成了11行\n",
+ "nd3 = np.concatenate([nd1,nd2],axis = 0)\n",
+ "nd3"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "array([[110, 38, 144, 92, 38, 2, 67, 2, 103, 81],\n",
+ " [ 56, 61, 61, 22, 108, 145, 95, 44, 40, 100],\n",
+ " [ 65, 74, 85, 123, 47, 117, 35, 55, 120, 20],\n",
+ " [ 15, 9, 4, 84, 71, 133, 140, 13, 71, 91],\n",
+ " [ 94, 31, 41, 5, 7, 32, 50, 24, 18, 120]])"
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ },
+ {
+ "data": {
+ "text/plain": [
+ "array([[ 65, 149, 86, 138, 98],\n",
+ " [136, 49, 102, 45, 140],\n",
+ " [ 13, 124, 94, 81, 73],\n",
+ " [ 82, 38, 0, 75, 94],\n",
+ " [146, 28, 143, 61, 49]])"
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "nd1 = np.random.randint(0,150,size = (5,10))\n",
+ "\n",
+ "nd2 = np.random.randint(0,150,size = (5,5))\n",
+ "display(nd1,nd2)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "array([[110, 38, 144, 92, 38, 2, 67, 2, 103, 81, 65, 149, 86,\n",
+ " 138, 98],\n",
+ " [ 56, 61, 61, 22, 108, 145, 95, 44, 40, 100, 136, 49, 102,\n",
+ " 45, 140],\n",
+ " [ 65, 74, 85, 123, 47, 117, 35, 55, 120, 20, 13, 124, 94,\n",
+ " 81, 73],\n",
+ " [ 15, 9, 4, 84, 71, 133, 140, 13, 71, 91, 82, 38, 0,\n",
+ " 75, 94],\n",
+ " [ 94, 31, 41, 5, 7, 32, 50, 24, 18, 120, 146, 28, 143,\n",
+ " 61, 49]])"
+ ]
+ },
+ "execution_count": 6,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "# axis = 0行级联(第一维度的级联),axis = 1(第二个维度的级联,列的级联)\n",
+ "np.concatenate((nd1,nd2),axis = 1)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# pandas级联操作,pandas基于numpy\n",
+ "# pandas的级联类似"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 7,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Python | \n",
+ " Math | \n",
+ " En | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " A | \n",
+ " 113 | \n",
+ " 53 | \n",
+ " 80 | \n",
+ "
\n",
+ " \n",
+ " B | \n",
+ " 135 | \n",
+ " 40 | \n",
+ " 52 | \n",
+ "
\n",
+ " \n",
+ " C | \n",
+ " 144 | \n",
+ " 18 | \n",
+ " 64 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " Python Math En\n",
+ "A 113 53 80\n",
+ "B 135 40 52\n",
+ "C 144 18 64"
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ },
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Python | \n",
+ " Math | \n",
+ " En | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " D | \n",
+ " 126 | \n",
+ " 118 | \n",
+ " 146 | \n",
+ "
\n",
+ " \n",
+ " E | \n",
+ " 147 | \n",
+ " 81 | \n",
+ " 27 | \n",
+ "
\n",
+ " \n",
+ " F | \n",
+ " 87 | \n",
+ " 63 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " G | \n",
+ " 35 | \n",
+ " 95 | \n",
+ " 33 | \n",
+ "
\n",
+ " \n",
+ " H | \n",
+ " 130 | \n",
+ " 117 | \n",
+ " 91 | \n",
+ "
\n",
+ " \n",
+ " I | \n",
+ " 124 | \n",
+ " 98 | \n",
+ " 122 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " Python Math En\n",
+ "D 126 118 146\n",
+ "E 147 81 27\n",
+ "F 87 63 1\n",
+ "G 35 95 33\n",
+ "H 130 117 91\n",
+ "I 124 98 122"
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "df1 = DataFrame(np.random.randint(0,150,size = (3,3)),index = list('ABC'),columns=['Python','Math','En'])\n",
+ "\n",
+ "df2 = DataFrame(np.random.randint(0,150,size = (6,3)),index = list('DEFGHI'),columns=['Python','Math','En'])\n",
+ "\n",
+ "display(df1,df2)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 8,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Python | \n",
+ " Math | \n",
+ " En | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " A | \n",
+ " 113 | \n",
+ " 53 | \n",
+ " 80 | \n",
+ "
\n",
+ " \n",
+ " B | \n",
+ " 135 | \n",
+ " 40 | \n",
+ " 52 | \n",
+ "
\n",
+ " \n",
+ " C | \n",
+ " 144 | \n",
+ " 18 | \n",
+ " 64 | \n",
+ "
\n",
+ " \n",
+ " D | \n",
+ " 126 | \n",
+ " 118 | \n",
+ " 146 | \n",
+ "
\n",
+ " \n",
+ " E | \n",
+ " 147 | \n",
+ " 81 | \n",
+ " 27 | \n",
+ "
\n",
+ " \n",
+ " F | \n",
+ " 87 | \n",
+ " 63 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " G | \n",
+ " 35 | \n",
+ " 95 | \n",
+ " 33 | \n",
+ "
\n",
+ " \n",
+ " H | \n",
+ " 130 | \n",
+ " 117 | \n",
+ " 91 | \n",
+ "
\n",
+ " \n",
+ " I | \n",
+ " 124 | \n",
+ " 98 | \n",
+ " 122 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " Python Math En\n",
+ "A 113 53 80\n",
+ "B 135 40 52\n",
+ "C 144 18 64\n",
+ "D 126 118 146\n",
+ "E 147 81 27\n",
+ "F 87 63 1\n",
+ "G 35 95 33\n",
+ "H 130 117 91\n",
+ "I 124 98 122"
+ ]
+ },
+ "execution_count": 8,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "# pandas汇总数据,数据集成\n",
+ "df1.append(df2)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 9,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Python | \n",
+ " Math | \n",
+ " En | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " A | \n",
+ " 113 | \n",
+ " 53 | \n",
+ " 80 | \n",
+ "
\n",
+ " \n",
+ " B | \n",
+ " 135 | \n",
+ " 40 | \n",
+ " 52 | \n",
+ "
\n",
+ " \n",
+ " C | \n",
+ " 144 | \n",
+ " 18 | \n",
+ " 64 | \n",
+ "
\n",
+ " \n",
+ " D | \n",
+ " 126 | \n",
+ " 118 | \n",
+ " 146 | \n",
+ "
\n",
+ " \n",
+ " E | \n",
+ " 147 | \n",
+ " 81 | \n",
+ " 27 | \n",
+ "
\n",
+ " \n",
+ " F | \n",
+ " 87 | \n",
+ " 63 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " G | \n",
+ " 35 | \n",
+ " 95 | \n",
+ " 33 | \n",
+ "
\n",
+ " \n",
+ " H | \n",
+ " 130 | \n",
+ " 117 | \n",
+ " 91 | \n",
+ "
\n",
+ " \n",
+ " I | \n",
+ " 124 | \n",
+ " 98 | \n",
+ " 122 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " Python Math En\n",
+ "A 113 53 80\n",
+ "B 135 40 52\n",
+ "C 144 18 64\n",
+ "D 126 118 146\n",
+ "E 147 81 27\n",
+ "F 87 63 1\n",
+ "G 35 95 33\n",
+ "H 130 117 91\n",
+ "I 124 98 122"
+ ]
+ },
+ "execution_count": 9,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "pd.concat([df1,df2])"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 12,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [
+ {
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "d:\\python36\\lib\\site-packages\\ipykernel_launcher.py:1: FutureWarning: Sorting because non-concatenation axis is not aligned. A future version\n",
+ "of pandas will change to not sort by default.\n",
+ "\n",
+ "To accept the future behavior, pass 'sort=False'.\n",
+ "\n",
+ "To retain the current behavior and silence the warning, pass 'sort=True'.\n",
+ "\n",
+ " \"\"\"Entry point for launching an IPython kernel.\n"
+ ]
+ },
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Python | \n",
+ " Math | \n",
+ " En | \n",
+ " Python | \n",
+ " Math | \n",
+ " En | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " A | \n",
+ " 113.0 | \n",
+ " 53.0 | \n",
+ " 80.0 | \n",
+ " NaN | \n",
+ " NaN | \n",
+ " NaN | \n",
+ "
\n",
+ " \n",
+ " B | \n",
+ " 135.0 | \n",
+ " 40.0 | \n",
+ " 52.0 | \n",
+ " NaN | \n",
+ " NaN | \n",
+ " NaN | \n",
+ "
\n",
+ " \n",
+ " C | \n",
+ " 144.0 | \n",
+ " 18.0 | \n",
+ " 64.0 | \n",
+ " NaN | \n",
+ " NaN | \n",
+ " NaN | \n",
+ "
\n",
+ " \n",
+ " D | \n",
+ " NaN | \n",
+ " NaN | \n",
+ " NaN | \n",
+ " 126.0 | \n",
+ " 118.0 | \n",
+ " 146.0 | \n",
+ "
\n",
+ " \n",
+ " E | \n",
+ " NaN | \n",
+ " NaN | \n",
+ " NaN | \n",
+ " 147.0 | \n",
+ " 81.0 | \n",
+ " 27.0 | \n",
+ "
\n",
+ " \n",
+ " F | \n",
+ " NaN | \n",
+ " NaN | \n",
+ " NaN | \n",
+ " 87.0 | \n",
+ " 63.0 | \n",
+ " 1.0 | \n",
+ "
\n",
+ " \n",
+ " G | \n",
+ " NaN | \n",
+ " NaN | \n",
+ " NaN | \n",
+ " 35.0 | \n",
+ " 95.0 | \n",
+ " 33.0 | \n",
+ "
\n",
+ " \n",
+ " H | \n",
+ " NaN | \n",
+ " NaN | \n",
+ " NaN | \n",
+ " 130.0 | \n",
+ " 117.0 | \n",
+ " 91.0 | \n",
+ "
\n",
+ " \n",
+ " I | \n",
+ " NaN | \n",
+ " NaN | \n",
+ " NaN | \n",
+ " 124.0 | \n",
+ " 98.0 | \n",
+ " 122.0 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " Python Math En Python Math En\n",
+ "A 113.0 53.0 80.0 NaN NaN NaN\n",
+ "B 135.0 40.0 52.0 NaN NaN NaN\n",
+ "C 144.0 18.0 64.0 NaN NaN NaN\n",
+ "D NaN NaN NaN 126.0 118.0 146.0\n",
+ "E NaN NaN NaN 147.0 81.0 27.0\n",
+ "F NaN NaN NaN 87.0 63.0 1.0\n",
+ "G NaN NaN NaN 35.0 95.0 33.0\n",
+ "H NaN NaN NaN 130.0 117.0 91.0\n",
+ "I NaN NaN NaN 124.0 98.0 122.0"
+ ]
+ },
+ "execution_count": 12,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "pd.concat([df1,df2],axis = 1,ignore_index = False)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 13,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Python | \n",
+ " Math | \n",
+ " En | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " A | \n",
+ " 22 | \n",
+ " 58 | \n",
+ " 13 | \n",
+ "
\n",
+ " \n",
+ " B | \n",
+ " 99 | \n",
+ " 57 | \n",
+ " 35 | \n",
+ "
\n",
+ " \n",
+ " C | \n",
+ " 51 | \n",
+ " 28 | \n",
+ " 24 | \n",
+ "
\n",
+ " \n",
+ " E | \n",
+ " 5 | \n",
+ " 60 | \n",
+ " 111 | \n",
+ "
\n",
+ " \n",
+ " F | \n",
+ " 137 | \n",
+ " 23 | \n",
+ " 121 | \n",
+ "
\n",
+ " \n",
+ " G | \n",
+ " 49 | \n",
+ " 78 | \n",
+ " 115 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " Python Math En\n",
+ "A 22 58 13\n",
+ "B 99 57 35\n",
+ "C 51 28 24\n",
+ "E 5 60 111\n",
+ "F 137 23 121\n",
+ "G 49 78 115"
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ },
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Python | \n",
+ " Math | \n",
+ " En | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " A | \n",
+ " 118 | \n",
+ " 113 | \n",
+ " 81 | \n",
+ "
\n",
+ " \n",
+ " B | \n",
+ " 51 | \n",
+ " 22 | \n",
+ " 126 | \n",
+ "
\n",
+ " \n",
+ " C | \n",
+ " 0 | \n",
+ " 115 | \n",
+ " 128 | \n",
+ "
\n",
+ " \n",
+ " E | \n",
+ " 100 | \n",
+ " 130 | \n",
+ " 94 | \n",
+ "
\n",
+ " \n",
+ " F | \n",
+ " 49 | \n",
+ " 93 | \n",
+ " 140 | \n",
+ "
\n",
+ " \n",
+ " G | \n",
+ " 70 | \n",
+ " 59 | \n",
+ " 94 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " Python Math En\n",
+ "A 118 113 81\n",
+ "B 51 22 126\n",
+ "C 0 115 128\n",
+ "E 100 130 94\n",
+ "F 49 93 140\n",
+ "G 70 59 94"
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "# 期中\n",
+ "df1 = DataFrame(np.random.randint(0,150,size = (6,3)),index = list('ABCEFG'),columns=['Python','Math','En'])\n",
+ "\n",
+ "# 期末\n",
+ "df2 = DataFrame(np.random.randint(0,150,size = (6,3)),index = list('ABCEFG'),columns=['Python','Math','En'])\n",
+ "\n",
+ "display(df1,df2)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 16,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " | \n",
+ " Python | \n",
+ " Math | \n",
+ " En | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " 期中 | \n",
+ " A | \n",
+ " 22 | \n",
+ " 58 | \n",
+ " 13 | \n",
+ "
\n",
+ " \n",
+ " B | \n",
+ " 99 | \n",
+ " 57 | \n",
+ " 35 | \n",
+ "
\n",
+ " \n",
+ " C | \n",
+ " 51 | \n",
+ " 28 | \n",
+ " 24 | \n",
+ "
\n",
+ " \n",
+ " E | \n",
+ " 5 | \n",
+ " 60 | \n",
+ " 111 | \n",
+ "
\n",
+ " \n",
+ " F | \n",
+ " 137 | \n",
+ " 23 | \n",
+ " 121 | \n",
+ "
\n",
+ " \n",
+ " G | \n",
+ " 49 | \n",
+ " 78 | \n",
+ " 115 | \n",
+ "
\n",
+ " \n",
+ " 期末 | \n",
+ " A | \n",
+ " 118 | \n",
+ " 113 | \n",
+ " 81 | \n",
+ "
\n",
+ " \n",
+ " B | \n",
+ " 51 | \n",
+ " 22 | \n",
+ " 126 | \n",
+ "
\n",
+ " \n",
+ " C | \n",
+ " 0 | \n",
+ " 115 | \n",
+ " 128 | \n",
+ "
\n",
+ " \n",
+ " E | \n",
+ " 100 | \n",
+ " 130 | \n",
+ " 94 | \n",
+ "
\n",
+ " \n",
+ " F | \n",
+ " 49 | \n",
+ " 93 | \n",
+ " 140 | \n",
+ "
\n",
+ " \n",
+ " G | \n",
+ " 70 | \n",
+ " 59 | \n",
+ " 94 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " Python Math En\n",
+ "期中 A 22 58 13\n",
+ " B 99 57 35\n",
+ " C 51 28 24\n",
+ " E 5 60 111\n",
+ " F 137 23 121\n",
+ " G 49 78 115\n",
+ "期末 A 118 113 81\n",
+ " B 51 22 126\n",
+ " C 0 115 128\n",
+ " E 100 130 94\n",
+ " F 49 93 140\n",
+ " G 70 59 94"
+ ]
+ },
+ "execution_count": 16,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "df3 = pd.concat([df1,df2],axis = 0,keys = ['期中','期末'])\n",
+ "df3"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 19,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " | \n",
+ " Python | \n",
+ " Math | \n",
+ " En | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " A | \n",
+ " 期中 | \n",
+ " 22 | \n",
+ " 58 | \n",
+ " 13 | \n",
+ "
\n",
+ " \n",
+ " 期末 | \n",
+ " 118 | \n",
+ " 113 | \n",
+ " 81 | \n",
+ "
\n",
+ " \n",
+ " B | \n",
+ " 期中 | \n",
+ " 99 | \n",
+ " 57 | \n",
+ " 35 | \n",
+ "
\n",
+ " \n",
+ " 期末 | \n",
+ " 51 | \n",
+ " 22 | \n",
+ " 126 | \n",
+ "
\n",
+ " \n",
+ " C | \n",
+ " 期中 | \n",
+ " 51 | \n",
+ " 28 | \n",
+ " 24 | \n",
+ "
\n",
+ " \n",
+ " 期末 | \n",
+ " 0 | \n",
+ " 115 | \n",
+ " 128 | \n",
+ "
\n",
+ " \n",
+ " E | \n",
+ " 期中 | \n",
+ " 5 | \n",
+ " 60 | \n",
+ " 111 | \n",
+ "
\n",
+ " \n",
+ " 期末 | \n",
+ " 100 | \n",
+ " 130 | \n",
+ " 94 | \n",
+ "
\n",
+ " \n",
+ " F | \n",
+ " 期中 | \n",
+ " 137 | \n",
+ " 23 | \n",
+ " 121 | \n",
+ "
\n",
+ " \n",
+ " 期末 | \n",
+ " 49 | \n",
+ " 93 | \n",
+ " 140 | \n",
+ "
\n",
+ " \n",
+ " G | \n",
+ " 期中 | \n",
+ " 49 | \n",
+ " 78 | \n",
+ " 115 | \n",
+ "
\n",
+ " \n",
+ " 期末 | \n",
+ " 70 | \n",
+ " 59 | \n",
+ " 94 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " Python Math En\n",
+ "A 期中 22 58 13\n",
+ " 期末 118 113 81\n",
+ "B 期中 99 57 35\n",
+ " 期末 51 22 126\n",
+ "C 期中 51 28 24\n",
+ " 期末 0 115 128\n",
+ "E 期中 5 60 111\n",
+ " 期末 100 130 94\n",
+ "F 期中 137 23 121\n",
+ " 期末 49 93 140\n",
+ "G 期中 49 78 115\n",
+ " 期末 70 59 94"
+ ]
+ },
+ "execution_count": 19,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "df3.unstack(level = 0).stack()"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 3",
+ "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.7.7"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}
diff --git "a/Day76-90/code/.ipynb_checkpoints/7-pandas\346\225\260\346\215\256\351\233\206\346\210\220merge-checkpoint.ipynb" "b/Day76-90/code/.ipynb_checkpoints/7-pandas\346\225\260\346\215\256\351\233\206\346\210\220merge-checkpoint.ipynb"
new file mode 100644
index 000000000..06fd9f690
--- /dev/null
+++ "b/Day76-90/code/.ipynb_checkpoints/7-pandas\346\225\260\346\215\256\351\233\206\346\210\220merge-checkpoint.ipynb"
@@ -0,0 +1,1272 @@
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "import numpy as np\n",
+ "\n",
+ "import pandas as pd\n",
+ "from pandas import Series,DataFrame"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# 上一讲,append,concat数据集成方法\n",
+ "# merge融合,根据某一共同属性进行级联,高级用法"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " name | \n",
+ " sex | \n",
+ " id | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " 0 | \n",
+ " A | \n",
+ " 男 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " 1 | \n",
+ " B | \n",
+ " 女 | \n",
+ " 2 | \n",
+ "
\n",
+ " \n",
+ " 2 | \n",
+ " C | \n",
+ " 女 | \n",
+ " 3 | \n",
+ "
\n",
+ " \n",
+ " 3 | \n",
+ " D | \n",
+ " 女 | \n",
+ " 4 | \n",
+ "
\n",
+ " \n",
+ " 4 | \n",
+ " E | \n",
+ " 男 | \n",
+ " 5 | \n",
+ "
\n",
+ " \n",
+ " 5 | \n",
+ " F | \n",
+ " 男 | \n",
+ " 6 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " name sex id\n",
+ "0 A 男 1\n",
+ "1 B 女 2\n",
+ "2 C 女 3\n",
+ "3 D 女 4\n",
+ "4 E 男 5\n",
+ "5 F 男 6"
+ ]
+ },
+ "execution_count": 2,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "df1 = DataFrame({'name':['A','B','C','D','E','F'],\n",
+ " 'sex':['男','女','女','女','男','男'],\n",
+ " 'id':[1,2,3,4,5,6]})\n",
+ "df1"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " age | \n",
+ " salary | \n",
+ " id | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " 0 | \n",
+ " 22 | \n",
+ " 12000 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " 1 | \n",
+ " 25 | \n",
+ " 15000 | \n",
+ " 2 | \n",
+ "
\n",
+ " \n",
+ " 2 | \n",
+ " 27 | \n",
+ " 20000 | \n",
+ " 3 | \n",
+ "
\n",
+ " \n",
+ " 3 | \n",
+ " 21 | \n",
+ " 30000 | \n",
+ " 4 | \n",
+ "
\n",
+ " \n",
+ " 4 | \n",
+ " 18 | \n",
+ " 10000 | \n",
+ " 5 | \n",
+ "
\n",
+ " \n",
+ " 5 | \n",
+ " 29 | \n",
+ " 8000 | \n",
+ " 7 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " age salary id\n",
+ "0 22 12000 1\n",
+ "1 25 15000 2\n",
+ "2 27 20000 3\n",
+ "3 21 30000 4\n",
+ "4 18 10000 5\n",
+ "5 29 8000 7"
+ ]
+ },
+ "execution_count": 3,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "df2 = DataFrame({'age':[22,25,27,21,18,29],'salary':[12000,15000,20000,30000,10000,8000],'id':[1,2,3,4,5,7]})\n",
+ "df2"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [
+ {
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "d:\\python36\\lib\\site-packages\\pandas\\core\\frame.py:6692: FutureWarning: Sorting because non-concatenation axis is not aligned. A future version\n",
+ "of pandas will change to not sort by default.\n",
+ "\n",
+ "To accept the future behavior, pass 'sort=False'.\n",
+ "\n",
+ "To retain the current behavior and silence the warning, pass 'sort=True'.\n",
+ "\n",
+ " sort=sort)\n"
+ ]
+ },
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " age | \n",
+ " id | \n",
+ " name | \n",
+ " salary | \n",
+ " sex | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " 0 | \n",
+ " NaN | \n",
+ " 1 | \n",
+ " A | \n",
+ " NaN | \n",
+ " 男 | \n",
+ "
\n",
+ " \n",
+ " 1 | \n",
+ " NaN | \n",
+ " 2 | \n",
+ " B | \n",
+ " NaN | \n",
+ " 女 | \n",
+ "
\n",
+ " \n",
+ " 2 | \n",
+ " NaN | \n",
+ " 3 | \n",
+ " C | \n",
+ " NaN | \n",
+ " 女 | \n",
+ "
\n",
+ " \n",
+ " 3 | \n",
+ " NaN | \n",
+ " 4 | \n",
+ " D | \n",
+ " NaN | \n",
+ " 女 | \n",
+ "
\n",
+ " \n",
+ " 4 | \n",
+ " NaN | \n",
+ " 5 | \n",
+ " E | \n",
+ " NaN | \n",
+ " 男 | \n",
+ "
\n",
+ " \n",
+ " 5 | \n",
+ " NaN | \n",
+ " 6 | \n",
+ " F | \n",
+ " NaN | \n",
+ " 男 | \n",
+ "
\n",
+ " \n",
+ " 0 | \n",
+ " 22.0 | \n",
+ " 1 | \n",
+ " NaN | \n",
+ " 12000.0 | \n",
+ " NaN | \n",
+ "
\n",
+ " \n",
+ " 1 | \n",
+ " 25.0 | \n",
+ " 2 | \n",
+ " NaN | \n",
+ " 15000.0 | \n",
+ " NaN | \n",
+ "
\n",
+ " \n",
+ " 2 | \n",
+ " 27.0 | \n",
+ " 3 | \n",
+ " NaN | \n",
+ " 20000.0 | \n",
+ " NaN | \n",
+ "
\n",
+ " \n",
+ " 3 | \n",
+ " 21.0 | \n",
+ " 4 | \n",
+ " NaN | \n",
+ " 30000.0 | \n",
+ " NaN | \n",
+ "
\n",
+ " \n",
+ " 4 | \n",
+ " 18.0 | \n",
+ " 5 | \n",
+ " NaN | \n",
+ " 10000.0 | \n",
+ " NaN | \n",
+ "
\n",
+ " \n",
+ " 5 | \n",
+ " 29.0 | \n",
+ " 7 | \n",
+ " NaN | \n",
+ " 8000.0 | \n",
+ " NaN | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " age id name salary sex\n",
+ "0 NaN 1 A NaN 男\n",
+ "1 NaN 2 B NaN 女\n",
+ "2 NaN 3 C NaN 女\n",
+ "3 NaN 4 D NaN 女\n",
+ "4 NaN 5 E NaN 男\n",
+ "5 NaN 6 F NaN 男\n",
+ "0 22.0 1 NaN 12000.0 NaN\n",
+ "1 25.0 2 NaN 15000.0 NaN\n",
+ "2 27.0 3 NaN 20000.0 NaN\n",
+ "3 21.0 4 NaN 30000.0 NaN\n",
+ "4 18.0 5 NaN 10000.0 NaN\n",
+ "5 29.0 7 NaN 8000.0 NaN"
+ ]
+ },
+ "execution_count": 4,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "df1.append(df2)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " name | \n",
+ " sex | \n",
+ " id | \n",
+ " age | \n",
+ " salary | \n",
+ " id | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " 0 | \n",
+ " A | \n",
+ " 男 | \n",
+ " 1 | \n",
+ " 22 | \n",
+ " 12000 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " 1 | \n",
+ " B | \n",
+ " 女 | \n",
+ " 2 | \n",
+ " 25 | \n",
+ " 15000 | \n",
+ " 2 | \n",
+ "
\n",
+ " \n",
+ " 2 | \n",
+ " C | \n",
+ " 女 | \n",
+ " 3 | \n",
+ " 27 | \n",
+ " 20000 | \n",
+ " 3 | \n",
+ "
\n",
+ " \n",
+ " 3 | \n",
+ " D | \n",
+ " 女 | \n",
+ " 4 | \n",
+ " 21 | \n",
+ " 30000 | \n",
+ " 4 | \n",
+ "
\n",
+ " \n",
+ " 4 | \n",
+ " E | \n",
+ " 男 | \n",
+ " 5 | \n",
+ " 18 | \n",
+ " 10000 | \n",
+ " 5 | \n",
+ "
\n",
+ " \n",
+ " 5 | \n",
+ " F | \n",
+ " 男 | \n",
+ " 6 | \n",
+ " 29 | \n",
+ " 8000 | \n",
+ " 7 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " name sex id age salary id\n",
+ "0 A 男 1 22 12000 1\n",
+ "1 B 女 2 25 15000 2\n",
+ "2 C 女 3 27 20000 3\n",
+ "3 D 女 4 21 30000 4\n",
+ "4 E 男 5 18 10000 5\n",
+ "5 F 男 6 29 8000 7"
+ ]
+ },
+ "execution_count": 5,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "pd.concat([df1,df2],axis = 1)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " name | \n",
+ " sex | \n",
+ " id | \n",
+ " age | \n",
+ " salary | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " 0 | \n",
+ " A | \n",
+ " 男 | \n",
+ " 1 | \n",
+ " 22 | \n",
+ " 12000 | \n",
+ "
\n",
+ " \n",
+ " 1 | \n",
+ " B | \n",
+ " 女 | \n",
+ " 2 | \n",
+ " 25 | \n",
+ " 15000 | \n",
+ "
\n",
+ " \n",
+ " 2 | \n",
+ " C | \n",
+ " 女 | \n",
+ " 3 | \n",
+ " 27 | \n",
+ " 20000 | \n",
+ "
\n",
+ " \n",
+ " 3 | \n",
+ " D | \n",
+ " 女 | \n",
+ " 4 | \n",
+ " 21 | \n",
+ " 30000 | \n",
+ "
\n",
+ " \n",
+ " 4 | \n",
+ " E | \n",
+ " 男 | \n",
+ " 5 | \n",
+ " 18 | \n",
+ " 10000 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " name sex id age salary\n",
+ "0 A 男 1 22 12000\n",
+ "1 B 女 2 25 15000\n",
+ "2 C 女 3 27 20000\n",
+ "3 D 女 4 21 30000\n",
+ "4 E 男 5 18 10000"
+ ]
+ },
+ "execution_count": 6,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "df1.merge(df2)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 7,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " name | \n",
+ " sex | \n",
+ " id | \n",
+ " age | \n",
+ " salary | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " 0 | \n",
+ " A | \n",
+ " 男 | \n",
+ " 1 | \n",
+ " 22.0 | \n",
+ " 12000.0 | \n",
+ "
\n",
+ " \n",
+ " 1 | \n",
+ " B | \n",
+ " 女 | \n",
+ " 2 | \n",
+ " 25.0 | \n",
+ " 15000.0 | \n",
+ "
\n",
+ " \n",
+ " 2 | \n",
+ " C | \n",
+ " 女 | \n",
+ " 3 | \n",
+ " 27.0 | \n",
+ " 20000.0 | \n",
+ "
\n",
+ " \n",
+ " 3 | \n",
+ " D | \n",
+ " 女 | \n",
+ " 4 | \n",
+ " 21.0 | \n",
+ " 30000.0 | \n",
+ "
\n",
+ " \n",
+ " 4 | \n",
+ " E | \n",
+ " 男 | \n",
+ " 5 | \n",
+ " 18.0 | \n",
+ " 10000.0 | \n",
+ "
\n",
+ " \n",
+ " 5 | \n",
+ " F | \n",
+ " 男 | \n",
+ " 6 | \n",
+ " NaN | \n",
+ " NaN | \n",
+ "
\n",
+ " \n",
+ " 6 | \n",
+ " NaN | \n",
+ " NaN | \n",
+ " 7 | \n",
+ " 29.0 | \n",
+ " 8000.0 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " name sex id age salary\n",
+ "0 A 男 1 22.0 12000.0\n",
+ "1 B 女 2 25.0 15000.0\n",
+ "2 C 女 3 27.0 20000.0\n",
+ "3 D 女 4 21.0 30000.0\n",
+ "4 E 男 5 18.0 10000.0\n",
+ "5 F 男 6 NaN NaN\n",
+ "6 NaN NaN 7 29.0 8000.0"
+ ]
+ },
+ "execution_count": 7,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "df1.merge(df2,how = 'outer')"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 8,
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Python | \n",
+ " Math | \n",
+ " En | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " A | \n",
+ " 40 | \n",
+ " 15 | \n",
+ " 90 | \n",
+ "
\n",
+ " \n",
+ " B | \n",
+ " 59 | \n",
+ " 52 | \n",
+ " 83 | \n",
+ "
\n",
+ " \n",
+ " C | \n",
+ " 14 | \n",
+ " 138 | \n",
+ " 137 | \n",
+ "
\n",
+ " \n",
+ " D | \n",
+ " 89 | \n",
+ " 78 | \n",
+ " 53 | \n",
+ "
\n",
+ " \n",
+ " E | \n",
+ " 81 | \n",
+ " 101 | \n",
+ " 3 | \n",
+ "
\n",
+ " \n",
+ " F | \n",
+ " 75 | \n",
+ " 79 | \n",
+ " 86 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " Python Math En\n",
+ "A 40 15 90\n",
+ "B 59 52 83\n",
+ "C 14 138 137\n",
+ "D 89 78 53\n",
+ "E 81 101 3\n",
+ "F 75 79 86"
+ ]
+ },
+ "execution_count": 8,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "df = DataFrame(np.random.randint(0,150,size = (6,3)),index = list('ABCDEF'),columns=['Python','Math','En'])\n",
+ "df"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 11,
+ "metadata": {
+ "scrolled": false
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "Python 59.7\n",
+ "Math 77.2\n",
+ "En 75.3\n",
+ "dtype: float64"
+ ]
+ },
+ "execution_count": 11,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "s = df.mean().round(1)\n",
+ "s"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 20,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " score_mean | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " Python | \n",
+ " 59.7 | \n",
+ "
\n",
+ " \n",
+ " Math | \n",
+ " 77.2 | \n",
+ "
\n",
+ " \n",
+ " En | \n",
+ " 75.3 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " score_mean\n",
+ "Python 59.7\n",
+ "Math 77.2\n",
+ "En 75.3"
+ ]
+ },
+ "execution_count": 20,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "df2 = DataFrame(s)\n",
+ "df2.columns = ['score_mean']\n",
+ "df2"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 30,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Python | \n",
+ " Math | \n",
+ " En | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " score_mean | \n",
+ " 59.7 | \n",
+ " 77.2 | \n",
+ " 75.3 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " Python Math En\n",
+ "score_mean 59.7 77.2 75.3"
+ ]
+ },
+ "execution_count": 30,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "df3 = df2.T\n",
+ "df3"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 32,
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Python | \n",
+ " Math | \n",
+ " En | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " A | \n",
+ " 40.0 | \n",
+ " 15.0 | \n",
+ " 90.0 | \n",
+ "
\n",
+ " \n",
+ " B | \n",
+ " 59.0 | \n",
+ " 52.0 | \n",
+ " 83.0 | \n",
+ "
\n",
+ " \n",
+ " C | \n",
+ " 14.0 | \n",
+ " 138.0 | \n",
+ " 137.0 | \n",
+ "
\n",
+ " \n",
+ " D | \n",
+ " 89.0 | \n",
+ " 78.0 | \n",
+ " 53.0 | \n",
+ "
\n",
+ " \n",
+ " E | \n",
+ " 81.0 | \n",
+ " 101.0 | \n",
+ " 3.0 | \n",
+ "
\n",
+ " \n",
+ " F | \n",
+ " 75.0 | \n",
+ " 79.0 | \n",
+ " 86.0 | \n",
+ "
\n",
+ " \n",
+ " score_mean | \n",
+ " 59.7 | \n",
+ " 77.2 | \n",
+ " 75.3 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " Python Math En\n",
+ "A 40.0 15.0 90.0\n",
+ "B 59.0 52.0 83.0\n",
+ "C 14.0 138.0 137.0\n",
+ "D 89.0 78.0 53.0\n",
+ "E 81.0 101.0 3.0\n",
+ "F 75.0 79.0 86.0\n",
+ "score_mean 59.7 77.2 75.3"
+ ]
+ },
+ "execution_count": 32,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "df4 = df.append(df3)\n",
+ "df4"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 38,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " score_mean | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " A | \n",
+ " 48.3 | \n",
+ "
\n",
+ " \n",
+ " B | \n",
+ " 64.7 | \n",
+ "
\n",
+ " \n",
+ " C | \n",
+ " 96.3 | \n",
+ "
\n",
+ " \n",
+ " D | \n",
+ " 73.3 | \n",
+ "
\n",
+ " \n",
+ " E | \n",
+ " 61.7 | \n",
+ "
\n",
+ " \n",
+ " F | \n",
+ " 80.0 | \n",
+ "
\n",
+ " \n",
+ " score_mean | \n",
+ " 70.7 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " score_mean\n",
+ "A 48.3\n",
+ "B 64.7\n",
+ "C 96.3\n",
+ "D 73.3\n",
+ "E 61.7\n",
+ "F 80.0\n",
+ "score_mean 70.7"
+ ]
+ },
+ "execution_count": 38,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "df5 = DataFrame(df4.mean(axis = 1).round(1))\n",
+ "df5.columns = ['score_mean']\n",
+ "df5"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 40,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Python | \n",
+ " Math | \n",
+ " En | \n",
+ " score_mean | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " A | \n",
+ " 40.0 | \n",
+ " 15.0 | \n",
+ " 90.0 | \n",
+ " 48.3 | \n",
+ "
\n",
+ " \n",
+ " B | \n",
+ " 59.0 | \n",
+ " 52.0 | \n",
+ " 83.0 | \n",
+ " 64.7 | \n",
+ "
\n",
+ " \n",
+ " C | \n",
+ " 14.0 | \n",
+ " 138.0 | \n",
+ " 137.0 | \n",
+ " 96.3 | \n",
+ "
\n",
+ " \n",
+ " D | \n",
+ " 89.0 | \n",
+ " 78.0 | \n",
+ " 53.0 | \n",
+ " 73.3 | \n",
+ "
\n",
+ " \n",
+ " E | \n",
+ " 81.0 | \n",
+ " 101.0 | \n",
+ " 3.0 | \n",
+ " 61.7 | \n",
+ "
\n",
+ " \n",
+ " F | \n",
+ " 75.0 | \n",
+ " 79.0 | \n",
+ " 86.0 | \n",
+ " 80.0 | \n",
+ "
\n",
+ " \n",
+ " score_mean | \n",
+ " 59.7 | \n",
+ " 77.2 | \n",
+ " 75.3 | \n",
+ " 70.7 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " Python Math En score_mean\n",
+ "A 40.0 15.0 90.0 48.3\n",
+ "B 59.0 52.0 83.0 64.7\n",
+ "C 14.0 138.0 137.0 96.3\n",
+ "D 89.0 78.0 53.0 73.3\n",
+ "E 81.0 101.0 3.0 61.7\n",
+ "F 75.0 79.0 86.0 80.0\n",
+ "score_mean 59.7 77.2 75.3 70.7"
+ ]
+ },
+ "execution_count": 40,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "df4.merge(df5,left_index=True,right_index=True)"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 3",
+ "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.7.7"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}
diff --git "a/Day76-90/code/.ipynb_checkpoints/8-pandas\345\210\206\347\273\204\350\201\232\345\220\210\346\223\215\344\275\234-checkpoint.ipynb" "b/Day76-90/code/.ipynb_checkpoints/8-pandas\345\210\206\347\273\204\350\201\232\345\220\210\346\223\215\344\275\234-checkpoint.ipynb"
new file mode 100644
index 000000000..e9dddcc7e
--- /dev/null
+++ "b/Day76-90/code/.ipynb_checkpoints/8-pandas\345\210\206\347\273\204\350\201\232\345\220\210\346\223\215\344\275\234-checkpoint.ipynb"
@@ -0,0 +1,877 @@
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# 分组聚合透视\n",
+ "# 很多时候属性是相似的\n",
+ "\n",
+ "import numpy as np\n",
+ "\n",
+ "import pandas as pd\n",
+ "\n",
+ "from pandas import Series,DataFrame"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Hand | \n",
+ " Smoke | \n",
+ " sex | \n",
+ " weight | \n",
+ " IQ | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " 0 | \n",
+ " right | \n",
+ " yes | \n",
+ " male | \n",
+ " 80 | \n",
+ " 100 | \n",
+ "
\n",
+ " \n",
+ " 1 | \n",
+ " left | \n",
+ " yes | \n",
+ " female | \n",
+ " 50 | \n",
+ " 120 | \n",
+ "
\n",
+ " \n",
+ " 2 | \n",
+ " left | \n",
+ " no | \n",
+ " female | \n",
+ " 48 | \n",
+ " 90 | \n",
+ "
\n",
+ " \n",
+ " 3 | \n",
+ " right | \n",
+ " no | \n",
+ " male | \n",
+ " 75 | \n",
+ " 130 | \n",
+ "
\n",
+ " \n",
+ " 4 | \n",
+ " right | \n",
+ " yes | \n",
+ " male | \n",
+ " 68 | \n",
+ " 140 | \n",
+ "
\n",
+ " \n",
+ " 5 | \n",
+ " right | \n",
+ " no | \n",
+ " male | \n",
+ " 100 | \n",
+ " 80 | \n",
+ "
\n",
+ " \n",
+ " 6 | \n",
+ " right | \n",
+ " no | \n",
+ " female | \n",
+ " 40 | \n",
+ " 94 | \n",
+ "
\n",
+ " \n",
+ " 7 | \n",
+ " right | \n",
+ " no | \n",
+ " female | \n",
+ " 90 | \n",
+ " 110 | \n",
+ "
\n",
+ " \n",
+ " 8 | \n",
+ " left | \n",
+ " no | \n",
+ " male | \n",
+ " 88 | \n",
+ " 100 | \n",
+ "
\n",
+ " \n",
+ " 9 | \n",
+ " right | \n",
+ " yes | \n",
+ " female | \n",
+ " 76 | \n",
+ " 160 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " Hand Smoke sex weight IQ\n",
+ "0 right yes male 80 100\n",
+ "1 left yes female 50 120\n",
+ "2 left no female 48 90\n",
+ "3 right no male 75 130\n",
+ "4 right yes male 68 140\n",
+ "5 right no male 100 80\n",
+ "6 right no female 40 94\n",
+ "7 right no female 90 110\n",
+ "8 left no male 88 100\n",
+ "9 right yes female 76 160"
+ ]
+ },
+ "execution_count": 2,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "# 走右手习惯,是否抽烟,性别,对体重,智商,有一定影响\n",
+ "\n",
+ "df = DataFrame({'Hand':['right','left','left','right','right','right','right','right','left','right'],\n",
+ " 'Smoke':['yes','yes','no','no','yes','no','no','no','no','yes'],\n",
+ " 'sex':['male','female','female','male','male','male','female','female','male','female'],\n",
+ " 'weight':[80,50,48,75,68,100,40,90,88,76],\n",
+ " 'IQ':[100,120,90,130,140,80,94,110,100,160]})\n",
+ "df"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# 分组聚合查看规律,某一条件下规律"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 7,
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " weight | \n",
+ " IQ | \n",
+ "
\n",
+ " \n",
+ " Hand | \n",
+ " | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " left | \n",
+ " 62.0 | \n",
+ " 103.3 | \n",
+ "
\n",
+ " \n",
+ " right | \n",
+ " 75.6 | \n",
+ " 116.3 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " weight IQ\n",
+ "Hand \n",
+ "left 62.0 103.3\n",
+ "right 75.6 116.3"
+ ]
+ },
+ "execution_count": 7,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "data = df.groupby(by = ['Hand'])[['weight','IQ']].mean().round(1)\n",
+ "data"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 11,
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " weight | \n",
+ "
\n",
+ " \n",
+ " Hand | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " left | \n",
+ " 62.0 | \n",
+ "
\n",
+ " \n",
+ " right | \n",
+ " 75.6 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " weight\n",
+ "Hand \n",
+ "left 62.0\n",
+ "right 75.6"
+ ]
+ },
+ "execution_count": 11,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "df.groupby(by = ['Hand'])[['weight']].apply(np.mean).round(1)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 14,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "df2 = df.groupby(by = ['Hand'])[['weight']].transform(np.mean).round(1)\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 17,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " weight_mean | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " 0 | \n",
+ " 75.6 | \n",
+ "
\n",
+ " \n",
+ " 1 | \n",
+ " 62.0 | \n",
+ "
\n",
+ " \n",
+ " 2 | \n",
+ " 62.0 | \n",
+ "
\n",
+ " \n",
+ " 3 | \n",
+ " 75.6 | \n",
+ "
\n",
+ " \n",
+ " 4 | \n",
+ " 75.6 | \n",
+ "
\n",
+ " \n",
+ " 5 | \n",
+ " 75.6 | \n",
+ "
\n",
+ " \n",
+ " 6 | \n",
+ " 75.6 | \n",
+ "
\n",
+ " \n",
+ " 7 | \n",
+ " 75.6 | \n",
+ "
\n",
+ " \n",
+ " 8 | \n",
+ " 62.0 | \n",
+ "
\n",
+ " \n",
+ " 9 | \n",
+ " 75.6 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " weight_mean\n",
+ "0 75.6\n",
+ "1 62.0\n",
+ "2 62.0\n",
+ "3 75.6\n",
+ "4 75.6\n",
+ "5 75.6\n",
+ "6 75.6\n",
+ "7 75.6\n",
+ "8 62.0\n",
+ "9 75.6"
+ ]
+ },
+ "execution_count": 17,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "df2 = df2.add_suffix('_mean')\n",
+ "df2"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 19,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Hand | \n",
+ " Smoke | \n",
+ " sex | \n",
+ " weight | \n",
+ " IQ | \n",
+ " weight_mean | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " 0 | \n",
+ " right | \n",
+ " yes | \n",
+ " male | \n",
+ " 80 | \n",
+ " 100 | \n",
+ " 75.6 | \n",
+ "
\n",
+ " \n",
+ " 1 | \n",
+ " left | \n",
+ " yes | \n",
+ " female | \n",
+ " 50 | \n",
+ " 120 | \n",
+ " 62.0 | \n",
+ "
\n",
+ " \n",
+ " 2 | \n",
+ " left | \n",
+ " no | \n",
+ " female | \n",
+ " 48 | \n",
+ " 90 | \n",
+ " 62.0 | \n",
+ "
\n",
+ " \n",
+ " 3 | \n",
+ " right | \n",
+ " no | \n",
+ " male | \n",
+ " 75 | \n",
+ " 130 | \n",
+ " 75.6 | \n",
+ "
\n",
+ " \n",
+ " 4 | \n",
+ " right | \n",
+ " yes | \n",
+ " male | \n",
+ " 68 | \n",
+ " 140 | \n",
+ " 75.6 | \n",
+ "
\n",
+ " \n",
+ " 5 | \n",
+ " right | \n",
+ " no | \n",
+ " male | \n",
+ " 100 | \n",
+ " 80 | \n",
+ " 75.6 | \n",
+ "
\n",
+ " \n",
+ " 6 | \n",
+ " right | \n",
+ " no | \n",
+ " female | \n",
+ " 40 | \n",
+ " 94 | \n",
+ " 75.6 | \n",
+ "
\n",
+ " \n",
+ " 7 | \n",
+ " right | \n",
+ " no | \n",
+ " female | \n",
+ " 90 | \n",
+ " 110 | \n",
+ " 75.6 | \n",
+ "
\n",
+ " \n",
+ " 8 | \n",
+ " left | \n",
+ " no | \n",
+ " male | \n",
+ " 88 | \n",
+ " 100 | \n",
+ " 62.0 | \n",
+ "
\n",
+ " \n",
+ " 9 | \n",
+ " right | \n",
+ " yes | \n",
+ " female | \n",
+ " 76 | \n",
+ " 160 | \n",
+ " 75.6 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " Hand Smoke sex weight IQ weight_mean\n",
+ "0 right yes male 80 100 75.6\n",
+ "1 left yes female 50 120 62.0\n",
+ "2 left no female 48 90 62.0\n",
+ "3 right no male 75 130 75.6\n",
+ "4 right yes male 68 140 75.6\n",
+ "5 right no male 100 80 75.6\n",
+ "6 right no female 40 94 75.6\n",
+ "7 right no female 90 110 75.6\n",
+ "8 left no male 88 100 62.0\n",
+ "9 right yes female 76 160 75.6"
+ ]
+ },
+ "execution_count": 19,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "df3 = df.merge(df2,left_index=True,right_index=True)\n",
+ "df3"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 26,
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "Hand\n",
+ "left ([3, 3], [62.0, 103.3])\n",
+ "right ([7, 7], [75.6, 116.3])\n",
+ "dtype: object"
+ ]
+ },
+ "execution_count": 26,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "def count(x):\n",
+ " \n",
+ " return (x.count(),x.mean().round(1))\n",
+ "\n",
+ "df.groupby(by = ['Hand'])[['weight','IQ']].apply(count)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 28,
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " | \n",
+ " IQ | \n",
+ "
\n",
+ " \n",
+ " Hand | \n",
+ " sex | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " left | \n",
+ " female | \n",
+ " 120 | \n",
+ "
\n",
+ " \n",
+ " male | \n",
+ " 100 | \n",
+ "
\n",
+ " \n",
+ " right | \n",
+ " female | \n",
+ " 160 | \n",
+ "
\n",
+ " \n",
+ " male | \n",
+ " 140 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " IQ\n",
+ "Hand sex \n",
+ "left female 120\n",
+ " male 100\n",
+ "right female 160\n",
+ " male 140"
+ ]
+ },
+ "execution_count": 28,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "df.groupby(by = ['Hand','sex'])[['IQ']].max()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 29,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ ""
+ ]
+ },
+ "execution_count": 29,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "data = df.groupby(by = ['Hand'])['IQ','weight']\n",
+ "data"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 31,
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " IQ | \n",
+ " weight | \n",
+ "
\n",
+ " \n",
+ " | \n",
+ " max | \n",
+ " mean | \n",
+ " max | \n",
+ " mean | \n",
+ "
\n",
+ " \n",
+ " Hand | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " left | \n",
+ " 120 | \n",
+ " 103.3 | \n",
+ " 88 | \n",
+ " 62.0 | \n",
+ "
\n",
+ " \n",
+ " right | \n",
+ " 160 | \n",
+ " 116.3 | \n",
+ " 100 | \n",
+ " 75.6 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " IQ weight \n",
+ " max mean max mean\n",
+ "Hand \n",
+ "left 120 103.3 88 62.0\n",
+ "right 160 116.3 100 75.6"
+ ]
+ },
+ "execution_count": 31,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "data.agg(['max','mean']).round(1)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 35,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " IQ | \n",
+ " weight | \n",
+ "
\n",
+ " \n",
+ " Hand | \n",
+ " | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " left | \n",
+ " 120 | \n",
+ " 62.0 | \n",
+ "
\n",
+ " \n",
+ " right | \n",
+ " 160 | \n",
+ " 75.6 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " IQ weight\n",
+ "Hand \n",
+ "left 120 62.0\n",
+ "right 160 75.6"
+ ]
+ },
+ "execution_count": 35,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "data.agg({'IQ':'max','weight':'mean'}).round(1)"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 3",
+ "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.7.7"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}
diff --git "a/Day76-90/code/1-pandas\345\205\245\351\227\250.ipynb" "b/Day76-90/code/1-pandas\345\205\245\351\227\250.ipynb"
index b5b3acc8b..d10293f1e 100644
--- "a/Day76-90/code/1-pandas\345\205\245\351\227\250.ipynb"
+++ "b/Day76-90/code/1-pandas\345\205\245\351\227\250.ipynb"
@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
- "execution_count": 2,
+ "execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
@@ -13,7 +13,7 @@
},
{
"cell_type": "code",
- "execution_count": 3,
+ "execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
@@ -22,14 +22,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": []
- },
- {
- "cell_type": "code",
- "execution_count": 4,
+ "execution_count": 5,
"metadata": {
"scrolled": false
},
@@ -44,7 +37,7 @@
"dtype: int64"
]
},
- "execution_count": 4,
+ "execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
@@ -52,13 +45,13 @@
"source": [
"# 创建\n",
"# Series是一维的数据\n",
- "s = Series(data = [120,136,128,99],index = ['Math','Python','En','Chinese'])\n",
+ "s = Series(data=[120,136,128,99], index=['Math','Python','En','Chinese'])\n",
"s"
]
},
{
"cell_type": "code",
- "execution_count": 5,
+ "execution_count": 6,
"metadata": {},
"outputs": [
{
@@ -67,7 +60,7 @@
"(4,)"
]
},
- "execution_count": 5,
+ "execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
@@ -78,16 +71,16 @@
},
{
"cell_type": "code",
- "execution_count": 6,
+ "execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
- "array([120, 136, 128, 99], dtype=int64)"
+ "array([120, 136, 128, 99])"
]
},
- "execution_count": 6,
+ "execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
@@ -99,7 +92,7 @@
},
{
"cell_type": "code",
- "execution_count": 7,
+ "execution_count": 8,
"metadata": {},
"outputs": [
{
@@ -108,7 +101,7 @@
"numpy.ndarray"
]
},
- "execution_count": 7,
+ "execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
@@ -119,7 +112,7 @@
},
{
"cell_type": "code",
- "execution_count": 8,
+ "execution_count": 9,
"metadata": {},
"outputs": [
{
@@ -128,7 +121,7 @@
"120.75"
]
},
- "execution_count": 8,
+ "execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
@@ -139,7 +132,7 @@
},
{
"cell_type": "code",
- "execution_count": 9,
+ "execution_count": 10,
"metadata": {},
"outputs": [
{
@@ -148,7 +141,7 @@
"136"
]
},
- "execution_count": 9,
+ "execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
@@ -159,7 +152,7 @@
},
{
"cell_type": "code",
- "execution_count": 10,
+ "execution_count": 11,
"metadata": {},
"outputs": [
{
@@ -168,7 +161,7 @@
"15.903353943953666"
]
},
- "execution_count": 10,
+ "execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
@@ -179,36 +172,33 @@
},
{
"cell_type": "code",
- "execution_count": 11,
- "metadata": {
- "collapsed": true
- },
+ "execution_count": 20,
+ "metadata": {},
"outputs": [
{
"data": {
"text/plain": [
- "Math 14400\n",
- "Python 18496\n",
- "En 16384\n",
- "Chinese 9801\n",
+ "Math 122\n",
+ "Python 138\n",
+ "En 130\n",
+ "Chinese 101\n",
"dtype: int64"
]
},
- "execution_count": 11,
+ "execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
- "s.pow(2)"
+ "s.add(1)\n",
+ "s"
]
},
{
"cell_type": "code",
- "execution_count": 12,
- "metadata": {
- "collapsed": true
- },
+ "execution_count": 21,
+ "metadata": {},
"outputs": [
{
"data": {
@@ -238,64 +228,64 @@
" \n",
" \n",
" \n",
- " a | \n",
- " 113 | \n",
- " 116 | \n",
- " 75 | \n",
+ " a | \n",
+ " 109 | \n",
+ " 120 | \n",
+ " 23 | \n",
"
\n",
" \n",
- " b | \n",
- " 19 | \n",
- " 145 | \n",
- " 23 | \n",
+ " b | \n",
+ " 54 | \n",
+ " 39 | \n",
+ " 54 | \n",
"
\n",
" \n",
- " c | \n",
- " 57 | \n",
- " 107 | \n",
- " 113 | \n",
+ " c | \n",
+ " 97 | \n",
+ " 22 | \n",
+ " 106 | \n",
"
\n",
" \n",
- " d | \n",
- " 95 | \n",
+ " d | \n",
+ " 21 | \n",
+ " 96 | \n",
" 3 | \n",
- " 66 | \n",
"
\n",
" \n",
- " e | \n",
- " 28 | \n",
- " 121 | \n",
- " 120 | \n",
+ " e | \n",
+ " 23 | \n",
+ " 145 | \n",
+ " 147 | \n",
"
\n",
" \n",
- " f | \n",
- " 141 | \n",
- " 85 | \n",
- " 132 | \n",
+ " f | \n",
+ " 80 | \n",
+ " 62 | \n",
+ " 83 | \n",
"
\n",
" \n",
- " h | \n",
- " 124 | \n",
- " 39 | \n",
- " 10 | \n",
+ " h | \n",
+ " 70 | \n",
+ " 31 | \n",
+ " 134 | \n",
"
\n",
" \n",
- " i | \n",
- " 80 | \n",
- " 35 | \n",
- " 17 | \n",
+ " i | \n",
+ " 132 | \n",
+ " 51 | \n",
+ " 115 | \n",
"
\n",
" \n",
- " j | \n",
- " 68 | \n",
- " 99 | \n",
- " 31 | \n",
+ " j | \n",
+ " 95 | \n",
+ " 143 | \n",
+ " 111 | \n",
"
\n",
" \n",
- " k | \n",
- " 74 | \n",
- " 12 | \n",
- " 11 | \n",
+ " k | \n",
+ " 66 | \n",
+ " 94 | \n",
+ " 7 | \n",
"
\n",
" \n",
"\n",
@@ -303,19 +293,19 @@
],
"text/plain": [
" Python En Math\n",
- "a 113 116 75\n",
- "b 19 145 23\n",
- "c 57 107 113\n",
- "d 95 3 66\n",
- "e 28 121 120\n",
- "f 141 85 132\n",
- "h 124 39 10\n",
- "i 80 35 17\n",
- "j 68 99 31\n",
- "k 74 12 11"
+ "a 109 120 23\n",
+ "b 54 39 54\n",
+ "c 97 22 106\n",
+ "d 21 96 3\n",
+ "e 23 145 147\n",
+ "f 80 62 83\n",
+ "h 70 31 134\n",
+ "i 132 51 115\n",
+ "j 95 143 111\n",
+ "k 66 94 7"
]
},
- "execution_count": 12,
+ "execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
@@ -324,7 +314,7 @@
"# DataFrame是二维的数据\n",
"# excel就非常相似\n",
"# 所有进行数据分析,数据挖掘的工具最基础的结果:行和列,行表示样本,列表示的是属性\n",
- "df = DataFrame(data = np.random.randint(0,150,size = (10,3)),index = list('abcdefhijk'),columns=['Python','En','Math'])\n",
+ "df = DataFrame(data=np.random.randint(0, 150, size=(10, 3)), index=list('abcdefhijk'), columns=['Python', 'En', 'Math'])\n",
"df"
]
},
@@ -553,7 +543,7 @@
},
{
"cell_type": "code",
- "execution_count": 19,
+ "execution_count": 22,
"metadata": {
"scrolled": true
},
@@ -561,50 +551,57 @@
{
"data": {
"text/plain": [
- "Python 79.9\n",
- "En 76.2\n",
- "Math 59.8\n",
+ "Python 74.7\n",
+ "En 80.3\n",
+ "Math 78.3\n",
"dtype: float64"
]
},
- "execution_count": 19,
+ "execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
- "df.mean(axis = 0)"
+ "df.mean(axis=0)"
]
},
{
"cell_type": "code",
- "execution_count": 20,
+ "execution_count": 23,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
- "a 101.333333\n",
- "b 62.333333\n",
- "c 92.333333\n",
- "d 54.666667\n",
- "e 89.666667\n",
- "f 119.333333\n",
- "h 57.666667\n",
- "i 44.000000\n",
- "j 66.000000\n",
- "k 32.333333\n",
+ "a 84.000000\n",
+ "b 49.000000\n",
+ "c 75.000000\n",
+ "d 40.000000\n",
+ "e 105.000000\n",
+ "f 75.000000\n",
+ "h 78.333333\n",
+ "i 99.333333\n",
+ "j 116.333333\n",
+ "k 55.666667\n",
"dtype: float64"
]
},
- "execution_count": 20,
+ "execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
- "df.mean(axis = 1)"
+ "df.mean(axis=1)"
]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": []
}
],
"metadata": {
@@ -623,7 +620,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.7.3"
+ "version": "3.7.7"
}
},
"nbformat": 4,
diff --git "a/Day76-90/code/2-pandas-\347\264\242\345\274\225.ipynb" "b/Day76-90/code/2-pandas-\347\264\242\345\274\225.ipynb"
index ddbde0ae5..98c1704a5 100644
--- "a/Day76-90/code/2-pandas-\347\264\242\345\274\225.ipynb"
+++ "b/Day76-90/code/2-pandas-\347\264\242\345\274\225.ipynb"
@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
- "execution_count": 1,
+ "execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@@ -10,88 +10,14 @@
"\n",
"import pandas as pd\n",
"\n",
- "from pandas import Series,DataFrame"
+ "from pandas import Series, DataFrame"
]
},
{
"cell_type": "code",
- "execution_count": 3,
- "metadata": {
- "collapsed": true
- },
- "outputs": [
- {
- "data": {
- "text/plain": [
- "10 34\n",
- "11 111\n",
- "12 113\n",
- "13 103\n",
- "14 147\n",
- "15 63\n",
- "16 11\n",
- "17 130\n",
- "18 38\n",
- "19 17\n",
- "20 32\n",
- "21 112\n",
- "22 75\n",
- "23 68\n",
- "24 124\n",
- "25 138\n",
- "26 56\n",
- "27 1\n",
- "28 88\n",
- "29 113\n",
- "30 63\n",
- "31 42\n",
- "32 65\n",
- "33 104\n",
- "34 105\n",
- "35 0\n",
- "36 95\n",
- "37 119\n",
- "38 86\n",
- "39 124\n",
- " ... \n",
- "80 127\n",
- "81 139\n",
- "82 110\n",
- "83 65\n",
- "84 127\n",
- "85 108\n",
- "86 33\n",
- "87 91\n",
- "88 134\n",
- "89 65\n",
- "90 110\n",
- "91 144\n",
- "92 40\n",
- "93 3\n",
- "94 3\n",
- "95 59\n",
- "96 97\n",
- "97 64\n",
- "98 126\n",
- "99 94\n",
- "100 20\n",
- "101 107\n",
- "102 59\n",
- "103 146\n",
- "104 83\n",
- "105 59\n",
- "106 25\n",
- "107 0\n",
- "108 78\n",
- "109 93\n",
- "Name: Python, Length: 100, dtype: int16"
- ]
- },
- "execution_count": 3,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
"source": [
"s = Series(np.random.randint(0,150,size = 100),index = np.arange(10,110),dtype=np.int16,name = 'Python')\n",
"s"
@@ -99,107 +25,27 @@
},
{
"cell_type": "code",
- "execution_count": 4,
- "metadata": {
- "collapsed": true
- },
- "outputs": [
- {
- "ename": "KeyError",
- "evalue": "0",
- "output_type": "error",
- "traceback": [
- "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
- "\u001b[1;31mKeyError\u001b[0m Traceback (most recent call last)",
- "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[1;31m# 索引操作\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0ms\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
- "\u001b[1;32md:\\python36\\lib\\site-packages\\pandas\\core\\series.py\u001b[0m in \u001b[0;36m__getitem__\u001b[1;34m(self, key)\u001b[0m\n\u001b[0;32m 866\u001b[0m \u001b[0mkey\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mcom\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mapply_if_callable\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 867\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 868\u001b[1;33m \u001b[0mresult\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mindex\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget_value\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mkey\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 869\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 870\u001b[0m \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0mis_scalar\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mresult\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
- "\u001b[1;32md:\\python36\\lib\\site-packages\\pandas\\core\\indexes\\base.py\u001b[0m in \u001b[0;36mget_value\u001b[1;34m(self, series, key)\u001b[0m\n\u001b[0;32m 4373\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 4374\u001b[0m return self._engine.get_value(s, k,\n\u001b[1;32m-> 4375\u001b[1;33m tz=getattr(series.dtype, 'tz', None))\n\u001b[0m\u001b[0;32m 4376\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mKeyError\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0me1\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 4377\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mlen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m>\u001b[0m \u001b[1;36m0\u001b[0m \u001b[1;32mand\u001b[0m \u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mholds_integer\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mor\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mis_boolean\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
- "\u001b[1;32mpandas\\_libs\\index.pyx\u001b[0m in \u001b[0;36mpandas._libs.index.IndexEngine.get_value\u001b[1;34m()\u001b[0m\n",
- "\u001b[1;32mpandas\\_libs\\index.pyx\u001b[0m in \u001b[0;36mpandas._libs.index.IndexEngine.get_value\u001b[1;34m()\u001b[0m\n",
- "\u001b[1;32mpandas\\_libs\\index.pyx\u001b[0m in \u001b[0;36mpandas._libs.index.IndexEngine.get_loc\u001b[1;34m()\u001b[0m\n",
- "\u001b[1;32mpandas\\_libs\\hashtable_class_helper.pxi\u001b[0m in \u001b[0;36mpandas._libs.hashtable.Int64HashTable.get_item\u001b[1;34m()\u001b[0m\n",
- "\u001b[1;32mpandas\\_libs\\hashtable_class_helper.pxi\u001b[0m in \u001b[0;36mpandas._libs.hashtable.Int64HashTable.get_item\u001b[1;34m()\u001b[0m\n",
- "\u001b[1;31mKeyError\u001b[0m: 0"
- ]
- }
- ],
- "source": [
- "# 索引操作\n",
- "s[0]"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 5,
+ "execution_count": null,
"metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "34"
- ]
- },
- "execution_count": 5,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "outputs": [],
"source": [
"s[10]"
]
},
{
"cell_type": "code",
- "execution_count": 6,
- "metadata": {
- "collapsed": true
- },
- "outputs": [
- {
- "data": {
- "text/plain": [
- "10 34\n",
- "20 32\n",
- "Name: Python, dtype: int16"
- ]
- },
- "execution_count": 6,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
"source": [
"s[[10,20]]"
]
},
{
"cell_type": "code",
- "execution_count": 7,
- "metadata": {
- "collapsed": true
- },
- "outputs": [
- {
- "data": {
- "text/plain": [
- "20 32\n",
- "21 112\n",
- "22 75\n",
- "23 68\n",
- "24 124\n",
- "25 138\n",
- "26 56\n",
- "27 1\n",
- "28 88\n",
- "29 113\n",
- "Name: Python, dtype: int16"
- ]
- },
- "execution_count": 7,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
"source": [
"# 切片操作\n",
"s[10:20]"
@@ -207,164 +53,27 @@
},
{
"cell_type": "code",
- "execution_count": 8,
- "metadata": {
- "collapsed": true
- },
- "outputs": [
- {
- "data": {
- "text/plain": [
- "10 34\n",
- "12 113\n",
- "14 147\n",
- "16 11\n",
- "18 38\n",
- "20 32\n",
- "22 75\n",
- "24 124\n",
- "26 56\n",
- "28 88\n",
- "30 63\n",
- "32 65\n",
- "34 105\n",
- "36 95\n",
- "38 86\n",
- "40 6\n",
- "42 57\n",
- "44 72\n",
- "46 43\n",
- "48 87\n",
- "50 83\n",
- "52 99\n",
- "54 132\n",
- "56 17\n",
- "58 116\n",
- "60 33\n",
- "62 51\n",
- "64 80\n",
- "66 121\n",
- "68 81\n",
- "70 0\n",
- "72 50\n",
- "74 31\n",
- "76 114\n",
- "78 60\n",
- "80 127\n",
- "82 110\n",
- "84 127\n",
- "86 33\n",
- "88 134\n",
- "90 110\n",
- "92 40\n",
- "94 3\n",
- "96 97\n",
- "98 126\n",
- "100 20\n",
- "102 59\n",
- "104 83\n",
- "106 25\n",
- "108 78\n",
- "Name: Python, dtype: int16"
- ]
- },
- "execution_count": 8,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
"source": [
"s[::2]"
]
},
{
"cell_type": "code",
- "execution_count": 9,
- "metadata": {
- "collapsed": true
- },
- "outputs": [
- {
- "data": {
- "text/plain": [
- "109 93\n",
- "107 0\n",
- "105 59\n",
- "103 146\n",
- "101 107\n",
- "99 94\n",
- "97 64\n",
- "95 59\n",
- "93 3\n",
- "91 144\n",
- "89 65\n",
- "87 91\n",
- "85 108\n",
- "83 65\n",
- "81 139\n",
- "79 14\n",
- "77 96\n",
- "75 76\n",
- "73 29\n",
- "71 68\n",
- "69 4\n",
- "67 57\n",
- "65 58\n",
- "63 106\n",
- "61 42\n",
- "59 135\n",
- "57 56\n",
- "55 12\n",
- "53 135\n",
- "51 74\n",
- "49 129\n",
- "47 110\n",
- "45 1\n",
- "43 90\n",
- "41 120\n",
- "39 124\n",
- "37 119\n",
- "35 0\n",
- "33 104\n",
- "31 42\n",
- "29 113\n",
- "27 1\n",
- "25 138\n",
- "23 68\n",
- "21 112\n",
- "19 17\n",
- "17 130\n",
- "15 63\n",
- "13 103\n",
- "11 111\n",
- "Name: Python, dtype: int16"
- ]
- },
- "execution_count": 9,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
"source": [
"s[::-2]"
]
},
{
"cell_type": "code",
- "execution_count": 10,
+ "execution_count": null,
"metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "34"
- ]
- },
- "execution_count": 10,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "outputs": [],
"source": [
"# 可以使用pandas为开发者提供方法,去进行检索\n",
"s.loc[10]"
@@ -372,249 +81,56 @@
},
{
"cell_type": "code",
- "execution_count": 11,
+ "execution_count": null,
"metadata": {
"scrolled": true
},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "10 34\n",
- "20 32\n",
- "Name: Python, dtype: int16"
- ]
- },
- "execution_count": 11,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "outputs": [],
"source": [
"s.loc[[10,20]]"
]
},
{
"cell_type": "code",
- "execution_count": 12,
- "metadata": {
- "collapsed": true
- },
- "outputs": [
- {
- "data": {
- "text/plain": [
- "10 34\n",
- "11 111\n",
- "12 113\n",
- "13 103\n",
- "14 147\n",
- "15 63\n",
- "16 11\n",
- "17 130\n",
- "18 38\n",
- "19 17\n",
- "20 32\n",
- "Name: Python, dtype: int16"
- ]
- },
- "execution_count": 12,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
"source": [
"s.loc[10:20]"
]
},
{
"cell_type": "code",
- "execution_count": 13,
- "metadata": {
- "collapsed": true
- },
- "outputs": [
- {
- "data": {
- "text/plain": [
- "10 34\n",
- "12 113\n",
- "14 147\n",
- "16 11\n",
- "18 38\n",
- "20 32\n",
- "22 75\n",
- "24 124\n",
- "26 56\n",
- "28 88\n",
- "30 63\n",
- "32 65\n",
- "34 105\n",
- "36 95\n",
- "38 86\n",
- "40 6\n",
- "42 57\n",
- "44 72\n",
- "46 43\n",
- "48 87\n",
- "50 83\n",
- "52 99\n",
- "54 132\n",
- "56 17\n",
- "58 116\n",
- "60 33\n",
- "62 51\n",
- "64 80\n",
- "66 121\n",
- "68 81\n",
- "70 0\n",
- "72 50\n",
- "74 31\n",
- "76 114\n",
- "78 60\n",
- "80 127\n",
- "82 110\n",
- "84 127\n",
- "86 33\n",
- "88 134\n",
- "90 110\n",
- "92 40\n",
- "94 3\n",
- "96 97\n",
- "98 126\n",
- "100 20\n",
- "102 59\n",
- "104 83\n",
- "106 25\n",
- "108 78\n",
- "Name: Python, dtype: int16"
- ]
- },
- "execution_count": 13,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
"source": [
"s.loc[::2]"
]
},
{
"cell_type": "code",
- "execution_count": 14,
- "metadata": {
- "collapsed": true
- },
- "outputs": [
- {
- "data": {
- "text/plain": [
- "109 93\n",
- "107 0\n",
- "105 59\n",
- "103 146\n",
- "101 107\n",
- "99 94\n",
- "97 64\n",
- "95 59\n",
- "93 3\n",
- "91 144\n",
- "89 65\n",
- "87 91\n",
- "85 108\n",
- "83 65\n",
- "81 139\n",
- "79 14\n",
- "77 96\n",
- "75 76\n",
- "73 29\n",
- "71 68\n",
- "69 4\n",
- "67 57\n",
- "65 58\n",
- "63 106\n",
- "61 42\n",
- "59 135\n",
- "57 56\n",
- "55 12\n",
- "53 135\n",
- "51 74\n",
- "49 129\n",
- "47 110\n",
- "45 1\n",
- "43 90\n",
- "41 120\n",
- "39 124\n",
- "37 119\n",
- "35 0\n",
- "33 104\n",
- "31 42\n",
- "29 113\n",
- "27 1\n",
- "25 138\n",
- "23 68\n",
- "21 112\n",
- "19 17\n",
- "17 130\n",
- "15 63\n",
- "13 103\n",
- "11 111\n",
- "Name: Python, dtype: int16"
- ]
- },
- "execution_count": 14,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
"source": [
"s.loc[::-2]"
]
},
{
"cell_type": "code",
- "execution_count": 16,
+ "execution_count": null,
"metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "Int64Index([ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,\n",
- " 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,\n",
- " 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,\n",
- " 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,\n",
- " 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74,\n",
- " 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87,\n",
- " 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100,\n",
- " 101, 102, 103, 104, 105, 106, 107, 108, 109],\n",
- " dtype='int64')"
- ]
- },
- "execution_count": 16,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "outputs": [],
"source": [
"s.index"
]
},
{
"cell_type": "code",
- "execution_count": 15,
+ "execution_count": null,
"metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "34"
- ]
- },
- "execution_count": 15,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "outputs": [],
"source": [
"# iloc 索引从0开始,数字化自然索引\n",
"s.iloc[0]"
@@ -622,257 +138,36 @@
},
{
"cell_type": "code",
- "execution_count": 17,
+ "execution_count": null,
"metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "10 34\n",
- "20 32\n",
- "Name: Python, dtype: int16"
- ]
- },
- "execution_count": 17,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "outputs": [],
"source": [
"s.iloc[[0,10]]"
]
},
{
"cell_type": "code",
- "execution_count": 18,
- "metadata": {
- "collapsed": true
- },
- "outputs": [
- {
- "data": {
- "text/plain": [
- "10 34\n",
- "11 111\n",
- "12 113\n",
- "13 103\n",
- "14 147\n",
- "15 63\n",
- "16 11\n",
- "17 130\n",
- "18 38\n",
- "19 17\n",
- "20 32\n",
- "21 112\n",
- "22 75\n",
- "23 68\n",
- "24 124\n",
- "25 138\n",
- "26 56\n",
- "27 1\n",
- "28 88\n",
- "29 113\n",
- "Name: Python, dtype: int16"
- ]
- },
- "execution_count": 18,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
"source": [
"s.iloc[0:20]"
]
},
{
"cell_type": "code",
- "execution_count": 20,
- "metadata": {
- "collapsed": true
- },
- "outputs": [
- {
- "data": {
- "text/plain": [
- "109 93\n",
- "107 0\n",
- "105 59\n",
- "103 146\n",
- "101 107\n",
- "99 94\n",
- "97 64\n",
- "95 59\n",
- "93 3\n",
- "91 144\n",
- "89 65\n",
- "87 91\n",
- "85 108\n",
- "83 65\n",
- "81 139\n",
- "79 14\n",
- "77 96\n",
- "75 76\n",
- "73 29\n",
- "71 68\n",
- "69 4\n",
- "67 57\n",
- "65 58\n",
- "63 106\n",
- "61 42\n",
- "59 135\n",
- "57 56\n",
- "55 12\n",
- "53 135\n",
- "51 74\n",
- "49 129\n",
- "47 110\n",
- "45 1\n",
- "43 90\n",
- "41 120\n",
- "39 124\n",
- "37 119\n",
- "35 0\n",
- "33 104\n",
- "31 42\n",
- "29 113\n",
- "27 1\n",
- "25 138\n",
- "23 68\n",
- "21 112\n",
- "19 17\n",
- "17 130\n",
- "15 63\n",
- "13 103\n",
- "11 111\n",
- "Name: Python, dtype: int16"
- ]
- },
- "execution_count": 20,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
"source": [
"s.iloc[::-2]"
]
},
{
"cell_type": "code",
- "execution_count": 21,
- "metadata": {
- "collapsed": true
- },
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " Python | \n",
- " En | \n",
- " Math | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " A | \n",
- " 103 | \n",
- " 56 | \n",
- " 98 | \n",
- "
\n",
- " \n",
- " B | \n",
- " 135 | \n",
- " 65 | \n",
- " 135 | \n",
- "
\n",
- " \n",
- " C | \n",
- " 13 | \n",
- " 79 | \n",
- " 146 | \n",
- "
\n",
- " \n",
- " D | \n",
- " 47 | \n",
- " 24 | \n",
- " 145 | \n",
- "
\n",
- " \n",
- " E | \n",
- " 89 | \n",
- " 97 | \n",
- " 16 | \n",
- "
\n",
- " \n",
- " F | \n",
- " 64 | \n",
- " 26 | \n",
- " 109 | \n",
- "
\n",
- " \n",
- " H | \n",
- " 48 | \n",
- " 46 | \n",
- " 111 | \n",
- "
\n",
- " \n",
- " I | \n",
- " 16 | \n",
- " 49 | \n",
- " 97 | \n",
- "
\n",
- " \n",
- " J | \n",
- " 122 | \n",
- " 126 | \n",
- " 100 | \n",
- "
\n",
- " \n",
- " K | \n",
- " 60 | \n",
- " 136 | \n",
- " 62 | \n",
- "
\n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- " Python En Math\n",
- "A 103 56 98\n",
- "B 135 65 135\n",
- "C 13 79 146\n",
- "D 47 24 145\n",
- "E 89 97 16\n",
- "F 64 26 109\n",
- "H 48 46 111\n",
- "I 16 49 97\n",
- "J 122 126 100\n",
- "K 60 136 62"
- ]
- },
- "execution_count": 21,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
"source": [
"# DataFrame是二维,索引大同小异,\n",
"df = DataFrame(data = np.random.randint(0,150,size= (10,3)),index=list('ABCDEFHIJK'),columns=['Python','En','Math'])\n",
@@ -882,1177 +177,172 @@
},
{
"cell_type": "code",
- "execution_count": 22,
- "metadata": {
- "collapsed": true
- },
- "outputs": [
- {
- "ename": "KeyError",
- "evalue": "'A'",
- "output_type": "error",
- "traceback": [
- "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
- "\u001b[1;31mKeyError\u001b[0m Traceback (most recent call last)",
- "\u001b[1;32md:\\python36\\lib\\site-packages\\pandas\\core\\indexes\\base.py\u001b[0m in \u001b[0;36mget_loc\u001b[1;34m(self, key, method, tolerance)\u001b[0m\n\u001b[0;32m 2656\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 2657\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_engine\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget_loc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 2658\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mKeyError\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
- "\u001b[1;32mpandas\\_libs\\index.pyx\u001b[0m in \u001b[0;36mpandas._libs.index.IndexEngine.get_loc\u001b[1;34m()\u001b[0m\n",
- "\u001b[1;32mpandas\\_libs\\index.pyx\u001b[0m in \u001b[0;36mpandas._libs.index.IndexEngine.get_loc\u001b[1;34m()\u001b[0m\n",
- "\u001b[1;32mpandas\\_libs\\hashtable_class_helper.pxi\u001b[0m in \u001b[0;36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001b[1;34m()\u001b[0m\n",
- "\u001b[1;32mpandas\\_libs\\hashtable_class_helper.pxi\u001b[0m in \u001b[0;36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001b[1;34m()\u001b[0m\n",
- "\u001b[1;31mKeyError\u001b[0m: 'A'",
- "\nDuring handling of the above exception, another exception occurred:\n",
- "\u001b[1;31mKeyError\u001b[0m Traceback (most recent call last)",
- "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mdf\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'A'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
- "\u001b[1;32md:\\python36\\lib\\site-packages\\pandas\\core\\frame.py\u001b[0m in \u001b[0;36m__getitem__\u001b[1;34m(self, key)\u001b[0m\n\u001b[0;32m 2925\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcolumns\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mnlevels\u001b[0m \u001b[1;33m>\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 2926\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_getitem_multilevel\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 2927\u001b[1;33m \u001b[0mindexer\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcolumns\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget_loc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 2928\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mis_integer\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mindexer\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 2929\u001b[0m \u001b[0mindexer\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m\u001b[0mindexer\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
- "\u001b[1;32md:\\python36\\lib\\site-packages\\pandas\\core\\indexes\\base.py\u001b[0m in \u001b[0;36mget_loc\u001b[1;34m(self, key, method, tolerance)\u001b[0m\n\u001b[0;32m 2657\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_engine\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget_loc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 2658\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mKeyError\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 2659\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_engine\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget_loc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_maybe_cast_indexer\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 2660\u001b[0m \u001b[0mindexer\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget_indexer\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mmethod\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mmethod\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mtolerance\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mtolerance\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 2661\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mindexer\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mndim\u001b[0m \u001b[1;33m>\u001b[0m \u001b[1;36m1\u001b[0m \u001b[1;32mor\u001b[0m \u001b[0mindexer\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msize\u001b[0m \u001b[1;33m>\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
- "\u001b[1;32mpandas\\_libs\\index.pyx\u001b[0m in \u001b[0;36mpandas._libs.index.IndexEngine.get_loc\u001b[1;34m()\u001b[0m\n",
- "\u001b[1;32mpandas\\_libs\\index.pyx\u001b[0m in \u001b[0;36mpandas._libs.index.IndexEngine.get_loc\u001b[1;34m()\u001b[0m\n",
- "\u001b[1;32mpandas\\_libs\\hashtable_class_helper.pxi\u001b[0m in \u001b[0;36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001b[1;34m()\u001b[0m\n",
- "\u001b[1;32mpandas\\_libs\\hashtable_class_helper.pxi\u001b[0m in \u001b[0;36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001b[1;34m()\u001b[0m\n",
- "\u001b[1;31mKeyError\u001b[0m: 'A'"
- ]
- }
- ],
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
"source": [
"df['A']"
]
},
{
"cell_type": "code",
- "execution_count": 23,
- "metadata": {
- "collapsed": true
- },
- "outputs": [
- {
- "data": {
- "text/plain": [
- "A 103\n",
- "B 135\n",
- "C 13\n",
- "D 47\n",
- "E 89\n",
- "F 64\n",
- "H 48\n",
- "I 16\n",
- "J 122\n",
- "K 60\n",
- "Name: Python, dtype: int32"
- ]
- },
- "execution_count": 23,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
"source": [
"df['Python']"
]
},
{
"cell_type": "code",
- "execution_count": 24,
- "metadata": {
- "collapsed": true
- },
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " Python | \n",
- " En | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " A | \n",
- " 103 | \n",
- " 56 | \n",
- "
\n",
- " \n",
- " B | \n",
- " 135 | \n",
- " 65 | \n",
- "
\n",
- " \n",
- " C | \n",
- " 13 | \n",
- " 79 | \n",
- "
\n",
- " \n",
- " D | \n",
- " 47 | \n",
- " 24 | \n",
- "
\n",
- " \n",
- " E | \n",
- " 89 | \n",
- " 97 | \n",
- "
\n",
- " \n",
- " F | \n",
- " 64 | \n",
- " 26 | \n",
- "
\n",
- " \n",
- " H | \n",
- " 48 | \n",
- " 46 | \n",
- "
\n",
- " \n",
- " I | \n",
- " 16 | \n",
- " 49 | \n",
- "
\n",
- " \n",
- " J | \n",
- " 122 | \n",
- " 126 | \n",
- "
\n",
- " \n",
- " K | \n",
- " 60 | \n",
- " 136 | \n",
- "
\n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- " Python En\n",
- "A 103 56\n",
- "B 135 65\n",
- "C 13 79\n",
- "D 47 24\n",
- "E 89 97\n",
- "F 64 26\n",
- "H 48 46\n",
- "I 16 49\n",
- "J 122 126\n",
- "K 60 136"
- ]
- },
- "execution_count": 24,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
"source": [
"df[['Python','En']]"
]
},
{
"cell_type": "code",
- "execution_count": 25,
+ "execution_count": null,
"metadata": {
"scrolled": true
},
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " Python | \n",
- " En | \n",
- " Math | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- "Empty DataFrame\n",
- "Columns: [Python, En, Math]\n",
- "Index: []"
- ]
- },
- "execution_count": 25,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "outputs": [],
"source": [
"df['Python':'Math']"
]
},
{
"cell_type": "code",
- "execution_count": 26,
- "metadata": {
- "collapsed": true
- },
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " Python | \n",
- " En | \n",
- " Math | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " A | \n",
- " 103 | \n",
- " 56 | \n",
- " 98 | \n",
- "
\n",
- " \n",
- " B | \n",
- " 135 | \n",
- " 65 | \n",
- " 135 | \n",
- "
\n",
- " \n",
- " C | \n",
- " 13 | \n",
- " 79 | \n",
- " 146 | \n",
- "
\n",
- " \n",
- " D | \n",
- " 47 | \n",
- " 24 | \n",
- " 145 | \n",
- "
\n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- " Python En Math\n",
- "A 103 56 98\n",
- "B 135 65 135\n",
- "C 13 79 146\n",
- "D 47 24 145"
- ]
- },
- "execution_count": 26,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
"source": [
"df['A':'D']"
]
},
{
"cell_type": "code",
- "execution_count": 27,
- "metadata": {
- "collapsed": true
- },
- "outputs": [
- {
- "ename": "KeyError",
- "evalue": "'Python'",
- "output_type": "error",
- "traceback": [
- "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
- "\u001b[1;31mKeyError\u001b[0m Traceback (most recent call last)",
- "\u001b[1;32md:\\python36\\lib\\site-packages\\pandas\\core\\indexes\\base.py\u001b[0m in \u001b[0;36mget_loc\u001b[1;34m(self, key, method, tolerance)\u001b[0m\n\u001b[0;32m 2656\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 2657\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_engine\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget_loc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 2658\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mKeyError\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
- "\u001b[1;32mpandas\\_libs\\index.pyx\u001b[0m in \u001b[0;36mpandas._libs.index.IndexEngine.get_loc\u001b[1;34m()\u001b[0m\n",
- "\u001b[1;32mpandas\\_libs\\index.pyx\u001b[0m in \u001b[0;36mpandas._libs.index.IndexEngine.get_loc\u001b[1;34m()\u001b[0m\n",
- "\u001b[1;32mpandas\\_libs\\hashtable_class_helper.pxi\u001b[0m in \u001b[0;36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001b[1;34m()\u001b[0m\n",
- "\u001b[1;32mpandas\\_libs\\hashtable_class_helper.pxi\u001b[0m in \u001b[0;36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001b[1;34m()\u001b[0m\n",
- "\u001b[1;31mKeyError\u001b[0m: 'Python'",
- "\nDuring handling of the above exception, another exception occurred:\n",
- "\u001b[1;31mKeyError\u001b[0m Traceback (most recent call last)",
- "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mdf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mloc\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'Python'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
- "\u001b[1;32md:\\python36\\lib\\site-packages\\pandas\\core\\indexing.py\u001b[0m in \u001b[0;36m__getitem__\u001b[1;34m(self, key)\u001b[0m\n\u001b[0;32m 1498\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1499\u001b[0m \u001b[0mmaybe_callable\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mcom\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mapply_if_callable\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mobj\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1500\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_getitem_axis\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmaybe_callable\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0maxis\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 1501\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1502\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m_is_scalar_access\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mkey\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
- "\u001b[1;32md:\\python36\\lib\\site-packages\\pandas\\core\\indexing.py\u001b[0m in \u001b[0;36m_getitem_axis\u001b[1;34m(self, key, axis)\u001b[0m\n\u001b[0;32m 1911\u001b[0m \u001b[1;31m# fall thru to straight lookup\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1912\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_validate_key\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1913\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_get_label\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0maxis\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 1914\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1915\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
- "\u001b[1;32md:\\python36\\lib\\site-packages\\pandas\\core\\indexing.py\u001b[0m in \u001b[0;36m_get_label\u001b[1;34m(self, label, axis)\u001b[0m\n\u001b[0;32m 139\u001b[0m \u001b[1;32mraise\u001b[0m \u001b[0mIndexingError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'no slices here, handle elsewhere'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 140\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 141\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mobj\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_xs\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlabel\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0maxis\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 142\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 143\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m_get_loc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mkey\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mNone\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
- "\u001b[1;32md:\\python36\\lib\\site-packages\\pandas\\core\\generic.py\u001b[0m in \u001b[0;36mxs\u001b[1;34m(self, key, axis, level, drop_level)\u001b[0m\n\u001b[0;32m 3583\u001b[0m drop_level=drop_level)\n\u001b[0;32m 3584\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 3585\u001b[1;33m \u001b[0mloc\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mindex\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget_loc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 3586\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 3587\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mloc\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mndarray\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
- "\u001b[1;32md:\\python36\\lib\\site-packages\\pandas\\core\\indexes\\base.py\u001b[0m in \u001b[0;36mget_loc\u001b[1;34m(self, key, method, tolerance)\u001b[0m\n\u001b[0;32m 2657\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_engine\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget_loc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 2658\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mKeyError\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 2659\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_engine\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget_loc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_maybe_cast_indexer\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 2660\u001b[0m \u001b[0mindexer\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget_indexer\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mmethod\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mmethod\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mtolerance\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mtolerance\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 2661\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mindexer\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mndim\u001b[0m \u001b[1;33m>\u001b[0m \u001b[1;36m1\u001b[0m \u001b[1;32mor\u001b[0m \u001b[0mindexer\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msize\u001b[0m \u001b[1;33m>\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
- "\u001b[1;32mpandas\\_libs\\index.pyx\u001b[0m in \u001b[0;36mpandas._libs.index.IndexEngine.get_loc\u001b[1;34m()\u001b[0m\n",
- "\u001b[1;32mpandas\\_libs\\index.pyx\u001b[0m in \u001b[0;36mpandas._libs.index.IndexEngine.get_loc\u001b[1;34m()\u001b[0m\n",
- "\u001b[1;32mpandas\\_libs\\hashtable_class_helper.pxi\u001b[0m in \u001b[0;36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001b[1;34m()\u001b[0m\n",
- "\u001b[1;32mpandas\\_libs\\hashtable_class_helper.pxi\u001b[0m in \u001b[0;36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001b[1;34m()\u001b[0m\n",
- "\u001b[1;31mKeyError\u001b[0m: 'Python'"
- ]
- }
- ],
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
"source": [
"df.loc['Python']"
]
},
{
"cell_type": "code",
- "execution_count": 28,
+ "execution_count": null,
"metadata": {
"scrolled": true
},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "Python 103\n",
- "En 56\n",
- "Math 98\n",
- "Name: A, dtype: int32"
- ]
- },
- "execution_count": 28,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "outputs": [],
"source": [
"df.loc['A']"
]
},
{
"cell_type": "code",
- "execution_count": 29,
+ "execution_count": null,
"metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " Python | \n",
- " En | \n",
- " Math | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " A | \n",
- " 103 | \n",
- " 56 | \n",
- " 98 | \n",
- "
\n",
- " \n",
- " H | \n",
- " 48 | \n",
- " 46 | \n",
- " 111 | \n",
- "
\n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- " Python En Math\n",
- "A 103 56 98\n",
- "H 48 46 111"
- ]
- },
- "execution_count": 29,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "outputs": [],
"source": [
"df.loc[['A','H']]"
]
},
{
"cell_type": "code",
- "execution_count": 30,
+ "execution_count": null,
"metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " Python | \n",
- " En | \n",
- " Math | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " A | \n",
- " 103 | \n",
- " 56 | \n",
- " 98 | \n",
- "
\n",
- " \n",
- " B | \n",
- " 135 | \n",
- " 65 | \n",
- " 135 | \n",
- "
\n",
- " \n",
- " C | \n",
- " 13 | \n",
- " 79 | \n",
- " 146 | \n",
- "
\n",
- " \n",
- " D | \n",
- " 47 | \n",
- " 24 | \n",
- " 145 | \n",
- "
\n",
- " \n",
- " E | \n",
- " 89 | \n",
- " 97 | \n",
- " 16 | \n",
- "
\n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- " Python En Math\n",
- "A 103 56 98\n",
- "B 135 65 135\n",
- "C 13 79 146\n",
- "D 47 24 145\n",
- "E 89 97 16"
- ]
- },
- "execution_count": 30,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "outputs": [],
"source": [
"df.loc['A':'E']"
]
},
{
"cell_type": "code",
- "execution_count": 31,
+ "execution_count": null,
"metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " Python | \n",
- " En | \n",
- " Math | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " A | \n",
- " 103 | \n",
- " 56 | \n",
- " 98 | \n",
- "
\n",
- " \n",
- " C | \n",
- " 13 | \n",
- " 79 | \n",
- " 146 | \n",
- "
\n",
- " \n",
- " E | \n",
- " 89 | \n",
- " 97 | \n",
- " 16 | \n",
- "
\n",
- " \n",
- " H | \n",
- " 48 | \n",
- " 46 | \n",
- " 111 | \n",
- "
\n",
- " \n",
- " J | \n",
- " 122 | \n",
- " 126 | \n",
- " 100 | \n",
- "
\n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- " Python En Math\n",
- "A 103 56 98\n",
- "C 13 79 146\n",
- "E 89 97 16\n",
- "H 48 46 111\n",
- "J 122 126 100"
- ]
- },
- "execution_count": 31,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "outputs": [],
"source": [
"df.loc[::2]"
]
},
{
"cell_type": "code",
- "execution_count": 32,
- "metadata": {
- "collapsed": true
- },
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " Python | \n",
- " En | \n",
- " Math | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " K | \n",
- " 60 | \n",
- " 136 | \n",
- " 62 | \n",
- "
\n",
- " \n",
- " I | \n",
- " 16 | \n",
- " 49 | \n",
- " 97 | \n",
- "
\n",
- " \n",
- " F | \n",
- " 64 | \n",
- " 26 | \n",
- " 109 | \n",
- "
\n",
- " \n",
- " D | \n",
- " 47 | \n",
- " 24 | \n",
- " 145 | \n",
- "
\n",
- " \n",
- " B | \n",
- " 135 | \n",
- " 65 | \n",
- " 135 | \n",
- "
\n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- " Python En Math\n",
- "K 60 136 62\n",
- "I 16 49 97\n",
- "F 64 26 109\n",
- "D 47 24 145\n",
- "B 135 65 135"
- ]
- },
- "execution_count": 32,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
"source": [
"df.loc[::-2]"
]
},
{
"cell_type": "code",
- "execution_count": 33,
- "metadata": {
- "collapsed": true
- },
- "outputs": [
- {
- "ename": "TypeError",
- "evalue": "Cannot index by location index with a non-integer key",
- "output_type": "error",
- "traceback": [
- "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
- "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)",
- "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mdf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0miloc\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'A'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
- "\u001b[1;32md:\\python36\\lib\\site-packages\\pandas\\core\\indexing.py\u001b[0m in \u001b[0;36m__getitem__\u001b[1;34m(self, key)\u001b[0m\n\u001b[0;32m 1498\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1499\u001b[0m \u001b[0mmaybe_callable\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mcom\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mapply_if_callable\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mobj\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1500\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_getitem_axis\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmaybe_callable\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0maxis\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 1501\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1502\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m_is_scalar_access\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mkey\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
- "\u001b[1;32md:\\python36\\lib\\site-packages\\pandas\\core\\indexing.py\u001b[0m in \u001b[0;36m_getitem_axis\u001b[1;34m(self, key, axis)\u001b[0m\n\u001b[0;32m 2224\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 2225\u001b[0m \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0mis_integer\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 2226\u001b[1;33m raise TypeError(\"Cannot index by location index with a \"\n\u001b[0m\u001b[0;32m 2227\u001b[0m \"non-integer key\")\n\u001b[0;32m 2228\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
- "\u001b[1;31mTypeError\u001b[0m: Cannot index by location index with a non-integer key"
- ]
- }
- ],
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
"source": [
"df.iloc['A']"
]
},
{
"cell_type": "code",
- "execution_count": 34,
+ "execution_count": null,
"metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "Python 103\n",
- "En 56\n",
- "Math 98\n",
- "Name: A, dtype: int32"
- ]
- },
- "execution_count": 34,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "outputs": [],
"source": [
"df.iloc[0]"
]
},
{
"cell_type": "code",
- "execution_count": 35,
+ "execution_count": null,
"metadata": {
"scrolled": true
},
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " Python | \n",
- " En | \n",
- " Math | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " A | \n",
- " 103 | \n",
- " 56 | \n",
- " 98 | \n",
- "
\n",
- " \n",
- " F | \n",
- " 64 | \n",
- " 26 | \n",
- " 109 | \n",
- "
\n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- " Python En Math\n",
- "A 103 56 98\n",
- "F 64 26 109"
- ]
- },
- "execution_count": 35,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "outputs": [],
"source": [
"df.iloc[[0,5]]"
]
},
{
"cell_type": "code",
- "execution_count": 36,
- "metadata": {
- "collapsed": true
- },
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " Python | \n",
- " En | \n",
- " Math | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " A | \n",
- " 103 | \n",
- " 56 | \n",
- " 98 | \n",
- "
\n",
- " \n",
- " B | \n",
- " 135 | \n",
- " 65 | \n",
- " 135 | \n",
- "
\n",
- " \n",
- " C | \n",
- " 13 | \n",
- " 79 | \n",
- " 146 | \n",
- "
\n",
- " \n",
- " D | \n",
- " 47 | \n",
- " 24 | \n",
- " 145 | \n",
- "
\n",
- " \n",
- " E | \n",
- " 89 | \n",
- " 97 | \n",
- " 16 | \n",
- "
\n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- " Python En Math\n",
- "A 103 56 98\n",
- "B 135 65 135\n",
- "C 13 79 146\n",
- "D 47 24 145\n",
- "E 89 97 16"
- ]
- },
- "execution_count": 36,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
"source": [
"df.iloc[0:5]"
]
},
{
"cell_type": "code",
- "execution_count": 38,
+ "execution_count": null,
"metadata": {
"scrolled": true
},
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " Python | \n",
- " En | \n",
- " Math | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " K | \n",
- " 60 | \n",
- " 136 | \n",
- " 62 | \n",
- "
\n",
- " \n",
- " I | \n",
- " 16 | \n",
- " 49 | \n",
- " 97 | \n",
- "
\n",
- " \n",
- " F | \n",
- " 64 | \n",
- " 26 | \n",
- " 109 | \n",
- "
\n",
- " \n",
- " D | \n",
- " 47 | \n",
- " 24 | \n",
- " 145 | \n",
- "
\n",
- " \n",
- " B | \n",
- " 135 | \n",
- " 65 | \n",
- " 135 | \n",
- "
\n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- " Python En Math\n",
- "K 60 136 62\n",
- "I 16 49 97\n",
- "F 64 26 109\n",
- "D 47 24 145\n",
- "B 135 65 135"
- ]
- },
- "execution_count": 38,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "outputs": [],
"source": [
"df.iloc[::-2]"
]
},
{
"cell_type": "code",
- "execution_count": 39,
+ "execution_count": null,
"metadata": {
"scrolled": true
},
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " Python | \n",
- " En | \n",
- " Math | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " A | \n",
- " 103 | \n",
- " 56 | \n",
- " 98 | \n",
- "
\n",
- " \n",
- " B | \n",
- " 135 | \n",
- " 65 | \n",
- " 135 | \n",
- "
\n",
- " \n",
- " C | \n",
- " 13 | \n",
- " 79 | \n",
- " 146 | \n",
- "
\n",
- " \n",
- " D | \n",
- " 47 | \n",
- " 24 | \n",
- " 145 | \n",
- "
\n",
- " \n",
- " E | \n",
- " 89 | \n",
- " 97 | \n",
- " 16 | \n",
- "
\n",
- " \n",
- " F | \n",
- " 64 | \n",
- " 26 | \n",
- " 109 | \n",
- "
\n",
- " \n",
- " H | \n",
- " 48 | \n",
- " 46 | \n",
- " 111 | \n",
- "
\n",
- " \n",
- " I | \n",
- " 16 | \n",
- " 49 | \n",
- " 97 | \n",
- "
\n",
- " \n",
- " J | \n",
- " 122 | \n",
- " 126 | \n",
- " 100 | \n",
- "
\n",
- " \n",
- " K | \n",
- " 60 | \n",
- " 136 | \n",
- " 62 | \n",
- "
\n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- " Python En Math\n",
- "A 103 56 98\n",
- "B 135 65 135\n",
- "C 13 79 146\n",
- "D 47 24 145\n",
- "E 89 97 16\n",
- "F 64 26 109\n",
- "H 48 46 111\n",
- "I 16 49 97\n",
- "J 122 126 100\n",
- "K 60 136 62"
- ]
- },
- "execution_count": 39,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "outputs": [],
"source": [
"df"
]
},
{
"cell_type": "code",
- "execution_count": 40,
+ "execution_count": null,
"metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " En | \n",
- " Math | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " A | \n",
- " 56 | \n",
- " 98 | \n",
- "
\n",
- " \n",
- " C | \n",
- " 79 | \n",
- " 146 | \n",
- "
\n",
- " \n",
- " E | \n",
- " 97 | \n",
- " 16 | \n",
- "
\n",
- " \n",
- " H | \n",
- " 46 | \n",
- " 111 | \n",
- "
\n",
- " \n",
- " J | \n",
- " 126 | \n",
- " 100 | \n",
- "
\n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- " En Math\n",
- "A 56 98\n",
- "C 79 146\n",
- "E 97 16\n",
- "H 46 111\n",
- "J 126 100"
- ]
- },
- "execution_count": 40,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "outputs": [],
"source": [
"df.iloc[::2,1:]"
]
@@ -2074,7 +364,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.6.5"
+ "version": "3.7.7"
}
},
"nbformat": 4,
diff --git "a/Day76-90/code/3-pandas\346\225\260\346\215\256\346\270\205\346\264\227\344\271\213\347\251\272\346\225\260\346\215\256.ipynb" "b/Day76-90/code/3-pandas\346\225\260\346\215\256\346\270\205\346\264\227\344\271\213\347\251\272\346\225\260\346\215\256.ipynb"
index dde9ec651..2c6fb4018 100644
--- "a/Day76-90/code/3-pandas\346\225\260\346\215\256\346\270\205\346\264\227\344\271\213\347\251\272\346\225\260\346\215\256.ipynb"
+++ "b/Day76-90/code/3-pandas\346\225\260\346\215\256\346\270\205\346\264\227\344\271\213\347\251\272\346\225\260\346\215\256.ipynb"
@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
- "execution_count": 1,
+ "execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@@ -15,633 +15,21 @@
},
{
"cell_type": "code",
- "execution_count": 2,
- "metadata": {
- "collapsed": true
- },
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " Python | \n",
- " En | \n",
- " Math | \n",
- " Physic | \n",
- " Chem | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " 100 | \n",
- " 122 | \n",
- " 10 | \n",
- " 5 | \n",
- " 28 | \n",
- " 57 | \n",
- "
\n",
- " \n",
- " 101 | \n",
- " 74 | \n",
- " 129 | \n",
- " 16 | \n",
- " 114 | \n",
- " 26 | \n",
- "
\n",
- " \n",
- " 102 | \n",
- " 97 | \n",
- " 121 | \n",
- " 122 | \n",
- " 29 | \n",
- " 65 | \n",
- "
\n",
- " \n",
- " 103 | \n",
- " 141 | \n",
- " 73 | \n",
- " 120 | \n",
- " 147 | \n",
- " 1 | \n",
- "
\n",
- " \n",
- " 104 | \n",
- " 126 | \n",
- " 132 | \n",
- " 86 | \n",
- " 116 | \n",
- " 17 | \n",
- "
\n",
- " \n",
- " 105 | \n",
- " 85 | \n",
- " 3 | \n",
- " 42 | \n",
- " 121 | \n",
- " 66 | \n",
- "
\n",
- " \n",
- " 106 | \n",
- " 142 | \n",
- " 65 | \n",
- " 1 | \n",
- " 124 | \n",
- " 83 | \n",
- "
\n",
- " \n",
- " 107 | \n",
- " 136 | \n",
- " 141 | \n",
- " 122 | \n",
- " 86 | \n",
- " 113 | \n",
- "
\n",
- " \n",
- " 108 | \n",
- " 15 | \n",
- " 37 | \n",
- " 124 | \n",
- " 110 | \n",
- " 102 | \n",
- "
\n",
- " \n",
- " 109 | \n",
- " 63 | \n",
- " 30 | \n",
- " 44 | \n",
- " 69 | \n",
- " 58 | \n",
- "
\n",
- " \n",
- " 110 | \n",
- " 59 | \n",
- " 38 | \n",
- " 113 | \n",
- " 109 | \n",
- " 16 | \n",
- "
\n",
- " \n",
- " 111 | \n",
- " 5 | \n",
- " 51 | \n",
- " 87 | \n",
- " 58 | \n",
- " 126 | \n",
- "
\n",
- " \n",
- " 112 | \n",
- " 53 | \n",
- " 97 | \n",
- " 76 | \n",
- " 37 | \n",
- " 45 | \n",
- "
\n",
- " \n",
- " 113 | \n",
- " 42 | \n",
- " 148 | \n",
- " 107 | \n",
- " 97 | \n",
- " 143 | \n",
- "
\n",
- " \n",
- " 114 | \n",
- " 70 | \n",
- " 138 | \n",
- " 69 | \n",
- " 68 | \n",
- " 134 | \n",
- "
\n",
- " \n",
- " 115 | \n",
- " 47 | \n",
- " 136 | \n",
- " 113 | \n",
- " 22 | \n",
- " 94 | \n",
- "
\n",
- " \n",
- " 116 | \n",
- " 31 | \n",
- " 137 | \n",
- " 6 | \n",
- " 20 | \n",
- " 28 | \n",
- "
\n",
- " \n",
- " 117 | \n",
- " 148 | \n",
- " 74 | \n",
- " 134 | \n",
- " 4 | \n",
- " 124 | \n",
- "
\n",
- " \n",
- " 118 | \n",
- " 102 | \n",
- " 81 | \n",
- " 138 | \n",
- " 128 | \n",
- " 32 | \n",
- "
\n",
- " \n",
- " 119 | \n",
- " 27 | \n",
- " 111 | \n",
- " 13 | \n",
- " 70 | \n",
- " 22 | \n",
- "
\n",
- " \n",
- " 120 | \n",
- " 28 | \n",
- " 93 | \n",
- " 121 | \n",
- " 68 | \n",
- " 4 | \n",
- "
\n",
- " \n",
- " 121 | \n",
- " 136 | \n",
- " 43 | \n",
- " 25 | \n",
- " 97 | \n",
- " 19 | \n",
- "
\n",
- " \n",
- " 122 | \n",
- " 111 | \n",
- " 70 | \n",
- " 12 | \n",
- " 38 | \n",
- " 58 | \n",
- "
\n",
- " \n",
- " 123 | \n",
- " 96 | \n",
- " 103 | \n",
- " 147 | \n",
- " 86 | \n",
- " 8 | \n",
- "
\n",
- " \n",
- " 124 | \n",
- " 10 | \n",
- " 10 | \n",
- " 46 | \n",
- " 63 | \n",
- " 149 | \n",
- "
\n",
- " \n",
- " 125 | \n",
- " 7 | \n",
- " 75 | \n",
- " 97 | \n",
- " 108 | \n",
- " 31 | \n",
- "
\n",
- " \n",
- " 126 | \n",
- " 88 | \n",
- " 6 | \n",
- " 145 | \n",
- " 116 | \n",
- " 55 | \n",
- "
\n",
- " \n",
- " 127 | \n",
- " 33 | \n",
- " 74 | \n",
- " 106 | \n",
- " 50 | \n",
- " 46 | \n",
- "
\n",
- " \n",
- " 128 | \n",
- " 74 | \n",
- " 28 | \n",
- " 26 | \n",
- " 100 | \n",
- " 76 | \n",
- "
\n",
- " \n",
- " 129 | \n",
- " 76 | \n",
- " 18 | \n",
- " 101 | \n",
- " 126 | \n",
- " 133 | \n",
- "
\n",
- " \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- "
\n",
- " \n",
- " 170 | \n",
- " 144 | \n",
- " 124 | \n",
- " 77 | \n",
- " 92 | \n",
- " 82 | \n",
- "
\n",
- " \n",
- " 171 | \n",
- " 36 | \n",
- " 98 | \n",
- " 48 | \n",
- " 43 | \n",
- " 80 | \n",
- "
\n",
- " \n",
- " 172 | \n",
- " 51 | \n",
- " 143 | \n",
- " 68 | \n",
- " 34 | \n",
- " 74 | \n",
- "
\n",
- " \n",
- " 173 | \n",
- " 149 | \n",
- " 117 | \n",
- " 18 | \n",
- " 141 | \n",
- " 120 | \n",
- "
\n",
- " \n",
- " 174 | \n",
- " 8 | \n",
- " 139 | \n",
- " 146 | \n",
- " 112 | \n",
- " 122 | \n",
- "
\n",
- " \n",
- " 175 | \n",
- " 115 | \n",
- " 101 | \n",
- " 64 | \n",
- " 62 | \n",
- " 9 | \n",
- "
\n",
- " \n",
- " 176 | \n",
- " 10 | \n",
- " 7 | \n",
- " 140 | \n",
- " 45 | \n",
- " 148 | \n",
- "
\n",
- " \n",
- " 177 | \n",
- " 65 | \n",
- " 43 | \n",
- " 68 | \n",
- " 109 | \n",
- " 18 | \n",
- "
\n",
- " \n",
- " 178 | \n",
- " 31 | \n",
- " 100 | \n",
- " 110 | \n",
- " 49 | \n",
- " 123 | \n",
- "
\n",
- " \n",
- " 179 | \n",
- " 29 | \n",
- " 46 | \n",
- " 69 | \n",
- " 57 | \n",
- " 90 | \n",
- "
\n",
- " \n",
- " 180 | \n",
- " 146 | \n",
- " 86 | \n",
- " 18 | \n",
- " 22 | \n",
- " 46 | \n",
- "
\n",
- " \n",
- " 181 | \n",
- " 71 | \n",
- " 50 | \n",
- " 40 | \n",
- " 90 | \n",
- " 140 | \n",
- "
\n",
- " \n",
- " 182 | \n",
- " 4 | \n",
- " 100 | \n",
- " 147 | \n",
- " 116 | \n",
- " 110 | \n",
- "
\n",
- " \n",
- " 183 | \n",
- " 55 | \n",
- " 87 | \n",
- " 93 | \n",
- " 78 | \n",
- " 34 | \n",
- "
\n",
- " \n",
- " 184 | \n",
- " 5 | \n",
- " 109 | \n",
- " 124 | \n",
- " 87 | \n",
- " 82 | \n",
- "
\n",
- " \n",
- " 185 | \n",
- " 10 | \n",
- " 118 | \n",
- " 139 | \n",
- " 50 | \n",
- " 51 | \n",
- "
\n",
- " \n",
- " 186 | \n",
- " 32 | \n",
- " 12 | \n",
- " 71 | \n",
- " 36 | \n",
- " 124 | \n",
- "
\n",
- " \n",
- " 187 | \n",
- " 94 | \n",
- " 16 | \n",
- " 138 | \n",
- " 13 | \n",
- " 149 | \n",
- "
\n",
- " \n",
- " 188 | \n",
- " 65 | \n",
- " 101 | \n",
- " 123 | \n",
- " 128 | \n",
- " 86 | \n",
- "
\n",
- " \n",
- " 189 | \n",
- " 43 | \n",
- " 94 | \n",
- " 10 | \n",
- " 29 | \n",
- " 132 | \n",
- "
\n",
- " \n",
- " 190 | \n",
- " 68 | \n",
- " 135 | \n",
- " 94 | \n",
- " 28 | \n",
- " 125 | \n",
- "
\n",
- " \n",
- " 191 | \n",
- " 30 | \n",
- " 60 | \n",
- " 98 | \n",
- " 27 | \n",
- " 15 | \n",
- "
\n",
- " \n",
- " 192 | \n",
- " 89 | \n",
- " 16 | \n",
- " 10 | \n",
- " 135 | \n",
- " 4 | \n",
- "
\n",
- " \n",
- " 193 | \n",
- " 104 | \n",
- " 139 | \n",
- " 97 | \n",
- " 29 | \n",
- " 17 | \n",
- "
\n",
- " \n",
- " 194 | \n",
- " 5 | \n",
- " 29 | \n",
- " 41 | \n",
- " 99 | \n",
- " 91 | \n",
- "
\n",
- " \n",
- " 195 | \n",
- " 19 | \n",
- " 102 | \n",
- " 135 | \n",
- " 41 | \n",
- " 40 | \n",
- "
\n",
- " \n",
- " 196 | \n",
- " 58 | \n",
- " 100 | \n",
- " 70 | \n",
- " 82 | \n",
- " 64 | \n",
- "
\n",
- " \n",
- " 197 | \n",
- " 84 | \n",
- " 97 | \n",
- " 129 | \n",
- " 76 | \n",
- " 13 | \n",
- "
\n",
- " \n",
- " 198 | \n",
- " 131 | \n",
- " 15 | \n",
- " 7 | \n",
- " 44 | \n",
- " 114 | \n",
- "
\n",
- " \n",
- " 199 | \n",
- " 79 | \n",
- " 37 | \n",
- " 95 | \n",
- " 128 | \n",
- " 116 | \n",
- "
\n",
- " \n",
- "
\n",
- "
100 rows × 5 columns
\n",
- "
"
- ],
- "text/plain": [
- " Python En Math Physic Chem\n",
- "100 122 10 5 28 57\n",
- "101 74 129 16 114 26\n",
- "102 97 121 122 29 65\n",
- "103 141 73 120 147 1\n",
- "104 126 132 86 116 17\n",
- "105 85 3 42 121 66\n",
- "106 142 65 1 124 83\n",
- "107 136 141 122 86 113\n",
- "108 15 37 124 110 102\n",
- "109 63 30 44 69 58\n",
- "110 59 38 113 109 16\n",
- "111 5 51 87 58 126\n",
- "112 53 97 76 37 45\n",
- "113 42 148 107 97 143\n",
- "114 70 138 69 68 134\n",
- "115 47 136 113 22 94\n",
- "116 31 137 6 20 28\n",
- "117 148 74 134 4 124\n",
- "118 102 81 138 128 32\n",
- "119 27 111 13 70 22\n",
- "120 28 93 121 68 4\n",
- "121 136 43 25 97 19\n",
- "122 111 70 12 38 58\n",
- "123 96 103 147 86 8\n",
- "124 10 10 46 63 149\n",
- "125 7 75 97 108 31\n",
- "126 88 6 145 116 55\n",
- "127 33 74 106 50 46\n",
- "128 74 28 26 100 76\n",
- "129 76 18 101 126 133\n",
- ".. ... ... ... ... ...\n",
- "170 144 124 77 92 82\n",
- "171 36 98 48 43 80\n",
- "172 51 143 68 34 74\n",
- "173 149 117 18 141 120\n",
- "174 8 139 146 112 122\n",
- "175 115 101 64 62 9\n",
- "176 10 7 140 45 148\n",
- "177 65 43 68 109 18\n",
- "178 31 100 110 49 123\n",
- "179 29 46 69 57 90\n",
- "180 146 86 18 22 46\n",
- "181 71 50 40 90 140\n",
- "182 4 100 147 116 110\n",
- "183 55 87 93 78 34\n",
- "184 5 109 124 87 82\n",
- "185 10 118 139 50 51\n",
- "186 32 12 71 36 124\n",
- "187 94 16 138 13 149\n",
- "188 65 101 123 128 86\n",
- "189 43 94 10 29 132\n",
- "190 68 135 94 28 125\n",
- "191 30 60 98 27 15\n",
- "192 89 16 10 135 4\n",
- "193 104 139 97 29 17\n",
- "194 5 29 41 99 91\n",
- "195 19 102 135 41 40\n",
- "196 58 100 70 82 64\n",
- "197 84 97 129 76 13\n",
- "198 131 15 7 44 114\n",
- "199 79 37 95 128 116\n",
- "\n",
- "[100 rows x 5 columns]"
- ]
- },
- "execution_count": 2,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
"source": [
"df = DataFrame(np.random.randint(0,150,size = (100,5)),index = np.arange(100,200),columns=['Python','En','Math','Physic','Chem'])\n",
- "df"
+ "df.loc[100, 'En'] = None"
]
},
{
"cell_type": "code",
- "execution_count": 4,
+ "execution_count": null,
"metadata": {
"scrolled": true
},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "Python False\n",
- "En False\n",
- "Math False\n",
- "Physic False\n",
- "Chem False\n",
- "dtype: bool"
- ]
- },
- "execution_count": 4,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "outputs": [],
"source": [
"# 判断DataFrame是否存在空数据\n",
"df.isnull().any()"
@@ -649,54 +37,18 @@
},
{
"cell_type": "code",
- "execution_count": 6,
+ "execution_count": null,
"metadata": {
"scrolled": true
},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "Python True\n",
- "En True\n",
- "Math True\n",
- "Physic True\n",
- "Chem True\n",
- "dtype: bool"
- ]
- },
- "execution_count": 6,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "outputs": [],
"source": [
"df.notnull().all()"
]
},
{
"cell_type": "code",
- "execution_count": 12,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "500"
- ]
- },
- "execution_count": 12,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "100*5"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 13,
+ "execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@@ -714,7 +66,7 @@
},
{
"cell_type": "code",
- "execution_count": 15,
+ "execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@@ -733,666 +85,38 @@
},
{
"cell_type": "code",
- "execution_count": 16,
- "metadata": {
- "collapsed": true
- },
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " Python | \n",
- " En | \n",
- " Math | \n",
- " Physic | \n",
- " Chem | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " 100 | \n",
- " 122.0 | \n",
- " 10.0 | \n",
- " 5.0 | \n",
- " 28.0 | \n",
- " 57.0 | \n",
- "
\n",
- " \n",
- " 101 | \n",
- " NaN | \n",
- " 129.0 | \n",
- " 16.0 | \n",
- " 114.0 | \n",
- " 26.0 | \n",
- "
\n",
- " \n",
- " 102 | \n",
- " 97.0 | \n",
- " 121.0 | \n",
- " 122.0 | \n",
- " 29.0 | \n",
- " 65.0 | \n",
- "
\n",
- " \n",
- " 103 | \n",
- " 141.0 | \n",
- " 73.0 | \n",
- " 120.0 | \n",
- " 147.0 | \n",
- " 1.0 | \n",
- "
\n",
- " \n",
- " 104 | \n",
- " 126.0 | \n",
- " NaN | \n",
- " 86.0 | \n",
- " 116.0 | \n",
- " 17.0 | \n",
- "
\n",
- " \n",
- " 105 | \n",
- " 85.0 | \n",
- " NaN | \n",
- " 42.0 | \n",
- " 121.0 | \n",
- " 66.0 | \n",
- "
\n",
- " \n",
- " 106 | \n",
- " 142.0 | \n",
- " 65.0 | \n",
- " 1.0 | \n",
- " 124.0 | \n",
- " 83.0 | \n",
- "
\n",
- " \n",
- " 107 | \n",
- " 136.0 | \n",
- " 141.0 | \n",
- " NaN | \n",
- " 86.0 | \n",
- " 113.0 | \n",
- "
\n",
- " \n",
- " 108 | \n",
- " 15.0 | \n",
- " 37.0 | \n",
- " 124.0 | \n",
- " 110.0 | \n",
- " 102.0 | \n",
- "
\n",
- " \n",
- " 109 | \n",
- " 63.0 | \n",
- " 30.0 | \n",
- " NaN | \n",
- " 69.0 | \n",
- " 58.0 | \n",
- "
\n",
- " \n",
- " 110 | \n",
- " NaN | \n",
- " NaN | \n",
- " 113.0 | \n",
- " 109.0 | \n",
- " 16.0 | \n",
- "
\n",
- " \n",
- " 111 | \n",
- " 5.0 | \n",
- " 51.0 | \n",
- " 87.0 | \n",
- " 58.0 | \n",
- " 126.0 | \n",
- "
\n",
- " \n",
- " 112 | \n",
- " 53.0 | \n",
- " 97.0 | \n",
- " 76.0 | \n",
- " 37.0 | \n",
- " 45.0 | \n",
- "
\n",
- " \n",
- " 113 | \n",
- " 42.0 | \n",
- " 148.0 | \n",
- " NaN | \n",
- " 97.0 | \n",
- " NaN | \n",
- "
\n",
- " \n",
- " 114 | \n",
- " 70.0 | \n",
- " 138.0 | \n",
- " 69.0 | \n",
- " 68.0 | \n",
- " 134.0 | \n",
- "
\n",
- " \n",
- " 115 | \n",
- " NaN | \n",
- " 136.0 | \n",
- " 113.0 | \n",
- " 22.0 | \n",
- " 94.0 | \n",
- "
\n",
- " \n",
- " 116 | \n",
- " 31.0 | \n",
- " 137.0 | \n",
- " 6.0 | \n",
- " 20.0 | \n",
- " 28.0 | \n",
- "
\n",
- " \n",
- " 117 | \n",
- " 148.0 | \n",
- " 74.0 | \n",
- " 134.0 | \n",
- " 4.0 | \n",
- " 124.0 | \n",
- "
\n",
- " \n",
- " 118 | \n",
- " 102.0 | \n",
- " 81.0 | \n",
- " 138.0 | \n",
- " 128.0 | \n",
- " 32.0 | \n",
- "
\n",
- " \n",
- " 119 | \n",
- " 27.0 | \n",
- " 111.0 | \n",
- " 13.0 | \n",
- " NaN | \n",
- " 22.0 | \n",
- "
\n",
- " \n",
- " 120 | \n",
- " 28.0 | \n",
- " 93.0 | \n",
- " 121.0 | \n",
- " NaN | \n",
- " 4.0 | \n",
- "
\n",
- " \n",
- " 121 | \n",
- " 136.0 | \n",
- " NaN | \n",
- " 25.0 | \n",
- " 97.0 | \n",
- " 19.0 | \n",
- "
\n",
- " \n",
- " 122 | \n",
- " 111.0 | \n",
- " 70.0 | \n",
- " 12.0 | \n",
- " 38.0 | \n",
- " 58.0 | \n",
- "
\n",
- " \n",
- " 123 | \n",
- " NaN | \n",
- " 103.0 | \n",
- " 147.0 | \n",
- " 86.0 | \n",
- " 8.0 | \n",
- "
\n",
- " \n",
- " 124 | \n",
- " 10.0 | \n",
- " 10.0 | \n",
- " 46.0 | \n",
- " 63.0 | \n",
- " 149.0 | \n",
- "
\n",
- " \n",
- " 125 | \n",
- " 7.0 | \n",
- " 75.0 | \n",
- " 97.0 | \n",
- " 108.0 | \n",
- " 31.0 | \n",
- "
\n",
- " \n",
- " 126 | \n",
- " 88.0 | \n",
- " 6.0 | \n",
- " NaN | \n",
- " NaN | \n",
- " 55.0 | \n",
- "
\n",
- " \n",
- " 127 | \n",
- " 33.0 | \n",
- " 74.0 | \n",
- " 106.0 | \n",
- " 50.0 | \n",
- " 46.0 | \n",
- "
\n",
- " \n",
- " 128 | \n",
- " 74.0 | \n",
- " 28.0 | \n",
- " 26.0 | \n",
- " 100.0 | \n",
- " 76.0 | \n",
- "
\n",
- " \n",
- " 129 | \n",
- " 76.0 | \n",
- " 18.0 | \n",
- " 101.0 | \n",
- " NaN | \n",
- " NaN | \n",
- "
\n",
- " \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- "
\n",
- " \n",
- " 170 | \n",
- " 144.0 | \n",
- " 124.0 | \n",
- " 77.0 | \n",
- " 92.0 | \n",
- " 82.0 | \n",
- "
\n",
- " \n",
- " 171 | \n",
- " 36.0 | \n",
- " 98.0 | \n",
- " NaN | \n",
- " 43.0 | \n",
- " 80.0 | \n",
- "
\n",
- " \n",
- " 172 | \n",
- " 51.0 | \n",
- " NaN | \n",
- " 68.0 | \n",
- " 34.0 | \n",
- " 74.0 | \n",
- "
\n",
- " \n",
- " 173 | \n",
- " 149.0 | \n",
- " NaN | \n",
- " 18.0 | \n",
- " 141.0 | \n",
- " NaN | \n",
- "
\n",
- " \n",
- " 174 | \n",
- " 8.0 | \n",
- " 139.0 | \n",
- " 146.0 | \n",
- " 112.0 | \n",
- " NaN | \n",
- "
\n",
- " \n",
- " 175 | \n",
- " 115.0 | \n",
- " NaN | \n",
- " 64.0 | \n",
- " 62.0 | \n",
- " 9.0 | \n",
- "
\n",
- " \n",
- " 176 | \n",
- " NaN | \n",
- " 7.0 | \n",
- " 140.0 | \n",
- " 45.0 | \n",
- " 148.0 | \n",
- "
\n",
- " \n",
- " 177 | \n",
- " NaN | \n",
- " 43.0 | \n",
- " 68.0 | \n",
- " 109.0 | \n",
- " 18.0 | \n",
- "
\n",
- " \n",
- " 178 | \n",
- " 31.0 | \n",
- " 100.0 | \n",
- " NaN | \n",
- " 49.0 | \n",
- " 123.0 | \n",
- "
\n",
- " \n",
- " 179 | \n",
- " 29.0 | \n",
- " 46.0 | \n",
- " 69.0 | \n",
- " 57.0 | \n",
- " 90.0 | \n",
- "
\n",
- " \n",
- " 180 | \n",
- " 146.0 | \n",
- " 86.0 | \n",
- " 18.0 | \n",
- " 22.0 | \n",
- " 46.0 | \n",
- "
\n",
- " \n",
- " 181 | \n",
- " 71.0 | \n",
- " 50.0 | \n",
- " 40.0 | \n",
- " NaN | \n",
- " 140.0 | \n",
- "
\n",
- " \n",
- " 182 | \n",
- " 4.0 | \n",
- " 100.0 | \n",
- " 147.0 | \n",
- " 116.0 | \n",
- " 110.0 | \n",
- "
\n",
- " \n",
- " 183 | \n",
- " 55.0 | \n",
- " 87.0 | \n",
- " 93.0 | \n",
- " NaN | \n",
- " 34.0 | \n",
- "
\n",
- " \n",
- " 184 | \n",
- " NaN | \n",
- " 109.0 | \n",
- " 124.0 | \n",
- " 87.0 | \n",
- " 82.0 | \n",
- "
\n",
- " \n",
- " 185 | \n",
- " 10.0 | \n",
- " 118.0 | \n",
- " 139.0 | \n",
- " 50.0 | \n",
- " 51.0 | \n",
- "
\n",
- " \n",
- " 186 | \n",
- " 32.0 | \n",
- " 12.0 | \n",
- " 71.0 | \n",
- " 36.0 | \n",
- " NaN | \n",
- "
\n",
- " \n",
- " 187 | \n",
- " 94.0 | \n",
- " NaN | \n",
- " 138.0 | \n",
- " 13.0 | \n",
- " 149.0 | \n",
- "
\n",
- " \n",
- " 188 | \n",
- " 65.0 | \n",
- " 101.0 | \n",
- " 123.0 | \n",
- " 128.0 | \n",
- " 86.0 | \n",
- "
\n",
- " \n",
- " 189 | \n",
- " 43.0 | \n",
- " 94.0 | \n",
- " NaN | \n",
- " 29.0 | \n",
- " 132.0 | \n",
- "
\n",
- " \n",
- " 190 | \n",
- " 68.0 | \n",
- " 135.0 | \n",
- " 94.0 | \n",
- " 28.0 | \n",
- " 125.0 | \n",
- "
\n",
- " \n",
- " 191 | \n",
- " 30.0 | \n",
- " 60.0 | \n",
- " 98.0 | \n",
- " NaN | \n",
- " 15.0 | \n",
- "
\n",
- " \n",
- " 192 | \n",
- " 89.0 | \n",
- " 16.0 | \n",
- " 10.0 | \n",
- " 135.0 | \n",
- " 4.0 | \n",
- "
\n",
- " \n",
- " 193 | \n",
- " 104.0 | \n",
- " 139.0 | \n",
- " 97.0 | \n",
- " 29.0 | \n",
- " 17.0 | \n",
- "
\n",
- " \n",
- " 194 | \n",
- " 5.0 | \n",
- " 29.0 | \n",
- " 41.0 | \n",
- " 99.0 | \n",
- " NaN | \n",
- "
\n",
- " \n",
- " 195 | \n",
- " 19.0 | \n",
- " 102.0 | \n",
- " 135.0 | \n",
- " 41.0 | \n",
- " 40.0 | \n",
- "
\n",
- " \n",
- " 196 | \n",
- " 58.0 | \n",
- " NaN | \n",
- " 70.0 | \n",
- " 82.0 | \n",
- " 64.0 | \n",
- "
\n",
- " \n",
- " 197 | \n",
- " NaN | \n",
- " 97.0 | \n",
- " 129.0 | \n",
- " 76.0 | \n",
- " 13.0 | \n",
- "
\n",
- " \n",
- " 198 | \n",
- " 131.0 | \n",
- " 15.0 | \n",
- " NaN | \n",
- " 44.0 | \n",
- " 114.0 | \n",
- "
\n",
- " \n",
- " 199 | \n",
- " 79.0 | \n",
- " NaN | \n",
- " 95.0 | \n",
- " 128.0 | \n",
- " NaN | \n",
- "
\n",
- " \n",
- "
\n",
- "
100 rows × 5 columns
\n",
- "
"
- ],
- "text/plain": [
- " Python En Math Physic Chem\n",
- "100 122.0 10.0 5.0 28.0 57.0\n",
- "101 NaN 129.0 16.0 114.0 26.0\n",
- "102 97.0 121.0 122.0 29.0 65.0\n",
- "103 141.0 73.0 120.0 147.0 1.0\n",
- "104 126.0 NaN 86.0 116.0 17.0\n",
- "105 85.0 NaN 42.0 121.0 66.0\n",
- "106 142.0 65.0 1.0 124.0 83.0\n",
- "107 136.0 141.0 NaN 86.0 113.0\n",
- "108 15.0 37.0 124.0 110.0 102.0\n",
- "109 63.0 30.0 NaN 69.0 58.0\n",
- "110 NaN NaN 113.0 109.0 16.0\n",
- "111 5.0 51.0 87.0 58.0 126.0\n",
- "112 53.0 97.0 76.0 37.0 45.0\n",
- "113 42.0 148.0 NaN 97.0 NaN\n",
- "114 70.0 138.0 69.0 68.0 134.0\n",
- "115 NaN 136.0 113.0 22.0 94.0\n",
- "116 31.0 137.0 6.0 20.0 28.0\n",
- "117 148.0 74.0 134.0 4.0 124.0\n",
- "118 102.0 81.0 138.0 128.0 32.0\n",
- "119 27.0 111.0 13.0 NaN 22.0\n",
- "120 28.0 93.0 121.0 NaN 4.0\n",
- "121 136.0 NaN 25.0 97.0 19.0\n",
- "122 111.0 70.0 12.0 38.0 58.0\n",
- "123 NaN 103.0 147.0 86.0 8.0\n",
- "124 10.0 10.0 46.0 63.0 149.0\n",
- "125 7.0 75.0 97.0 108.0 31.0\n",
- "126 88.0 6.0 NaN NaN 55.0\n",
- "127 33.0 74.0 106.0 50.0 46.0\n",
- "128 74.0 28.0 26.0 100.0 76.0\n",
- "129 76.0 18.0 101.0 NaN NaN\n",
- ".. ... ... ... ... ...\n",
- "170 144.0 124.0 77.0 92.0 82.0\n",
- "171 36.0 98.0 NaN 43.0 80.0\n",
- "172 51.0 NaN 68.0 34.0 74.0\n",
- "173 149.0 NaN 18.0 141.0 NaN\n",
- "174 8.0 139.0 146.0 112.0 NaN\n",
- "175 115.0 NaN 64.0 62.0 9.0\n",
- "176 NaN 7.0 140.0 45.0 148.0\n",
- "177 NaN 43.0 68.0 109.0 18.0\n",
- "178 31.0 100.0 NaN 49.0 123.0\n",
- "179 29.0 46.0 69.0 57.0 90.0\n",
- "180 146.0 86.0 18.0 22.0 46.0\n",
- "181 71.0 50.0 40.0 NaN 140.0\n",
- "182 4.0 100.0 147.0 116.0 110.0\n",
- "183 55.0 87.0 93.0 NaN 34.0\n",
- "184 NaN 109.0 124.0 87.0 82.0\n",
- "185 10.0 118.0 139.0 50.0 51.0\n",
- "186 32.0 12.0 71.0 36.0 NaN\n",
- "187 94.0 NaN 138.0 13.0 149.0\n",
- "188 65.0 101.0 123.0 128.0 86.0\n",
- "189 43.0 94.0 NaN 29.0 132.0\n",
- "190 68.0 135.0 94.0 28.0 125.0\n",
- "191 30.0 60.0 98.0 NaN 15.0\n",
- "192 89.0 16.0 10.0 135.0 4.0\n",
- "193 104.0 139.0 97.0 29.0 17.0\n",
- "194 5.0 29.0 41.0 99.0 NaN\n",
- "195 19.0 102.0 135.0 41.0 40.0\n",
- "196 58.0 NaN 70.0 82.0 64.0\n",
- "197 NaN 97.0 129.0 76.0 13.0\n",
- "198 131.0 15.0 NaN 44.0 114.0\n",
- "199 79.0 NaN 95.0 128.0 NaN\n",
- "\n",
- "[100 rows x 5 columns]"
- ]
- },
- "execution_count": 16,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
"source": [
"df"
]
},
{
"cell_type": "code",
- "execution_count": 18,
+ "execution_count": null,
"metadata": {
"scrolled": true
},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "Python True\n",
- "En True\n",
- "Math True\n",
- "Physic True\n",
- "Chem True\n",
- "dtype: bool"
- ]
- },
- "execution_count": 18,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "outputs": [],
"source": [
"df.isnull().any()"
]
},
{
"cell_type": "code",
- "execution_count": 22,
+ "execution_count": null,
"metadata": {
"scrolled": true
},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "Python 14\n",
- "En 14\n",
- "Math 15\n",
- "Physic 11\n",
- "Chem 13\n",
- "dtype: int64"
- ]
- },
- "execution_count": 22,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "outputs": [],
"source": [
"df.isnull().sum()"
]
},
{
"cell_type": "code",
- "execution_count": 23,
+ "execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@@ -1401,658 +125,28 @@
},
{
"cell_type": "code",
- "execution_count": 24,
- "metadata": {
- "collapsed": true
- },
- "outputs": [
- {
- "data": {
- "text/plain": [
- "Python 14\n",
- "En 14\n",
- "Math 15\n",
- "Physic 11\n",
- "Chem 13\n",
- "dtype: int64"
- ]
- },
- "execution_count": 24,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
"source": [
"df2.isnull().sum()"
]
},
{
"cell_type": "code",
- "execution_count": 26,
- "metadata": {
- "collapsed": true
- },
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " Python | \n",
- " En | \n",
- " Math | \n",
- " Physic | \n",
- " Chem | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " 100 | \n",
- " 122.0 | \n",
- " 10.0 | \n",
- " 5.0 | \n",
- " 28.0 | \n",
- " 57.0 | \n",
- "
\n",
- " \n",
- " 101 | \n",
- " 100.0 | \n",
- " 129.0 | \n",
- " 16.0 | \n",
- " 114.0 | \n",
- " 26.0 | \n",
- "
\n",
- " \n",
- " 102 | \n",
- " 97.0 | \n",
- " 121.0 | \n",
- " 122.0 | \n",
- " 29.0 | \n",
- " 65.0 | \n",
- "
\n",
- " \n",
- " 103 | \n",
- " 141.0 | \n",
- " 73.0 | \n",
- " 120.0 | \n",
- " 147.0 | \n",
- " 1.0 | \n",
- "
\n",
- " \n",
- " 104 | \n",
- " 126.0 | \n",
- " 100.0 | \n",
- " 86.0 | \n",
- " 116.0 | \n",
- " 17.0 | \n",
- "
\n",
- " \n",
- " 105 | \n",
- " 85.0 | \n",
- " 100.0 | \n",
- " 42.0 | \n",
- " 121.0 | \n",
- " 66.0 | \n",
- "
\n",
- " \n",
- " 106 | \n",
- " 142.0 | \n",
- " 65.0 | \n",
- " 1.0 | \n",
- " 124.0 | \n",
- " 83.0 | \n",
- "
\n",
- " \n",
- " 107 | \n",
- " 136.0 | \n",
- " 141.0 | \n",
- " 100.0 | \n",
- " 86.0 | \n",
- " 113.0 | \n",
- "
\n",
- " \n",
- " 108 | \n",
- " 15.0 | \n",
- " 37.0 | \n",
- " 124.0 | \n",
- " 110.0 | \n",
- " 102.0 | \n",
- "
\n",
- " \n",
- " 109 | \n",
- " 63.0 | \n",
- " 30.0 | \n",
- " 100.0 | \n",
- " 69.0 | \n",
- " 58.0 | \n",
- "
\n",
- " \n",
- " 110 | \n",
- " 100.0 | \n",
- " 100.0 | \n",
- " 113.0 | \n",
- " 109.0 | \n",
- " 16.0 | \n",
- "
\n",
- " \n",
- " 111 | \n",
- " 5.0 | \n",
- " 51.0 | \n",
- " 87.0 | \n",
- " 58.0 | \n",
- " 126.0 | \n",
- "
\n",
- " \n",
- " 112 | \n",
- " 53.0 | \n",
- " 97.0 | \n",
- " 76.0 | \n",
- " 37.0 | \n",
- " 45.0 | \n",
- "
\n",
- " \n",
- " 113 | \n",
- " 42.0 | \n",
- " 148.0 | \n",
- " 100.0 | \n",
- " 97.0 | \n",
- " 100.0 | \n",
- "
\n",
- " \n",
- " 114 | \n",
- " 70.0 | \n",
- " 138.0 | \n",
- " 69.0 | \n",
- " 68.0 | \n",
- " 134.0 | \n",
- "
\n",
- " \n",
- " 115 | \n",
- " 100.0 | \n",
- " 136.0 | \n",
- " 113.0 | \n",
- " 22.0 | \n",
- " 94.0 | \n",
- "
\n",
- " \n",
- " 116 | \n",
- " 31.0 | \n",
- " 137.0 | \n",
- " 6.0 | \n",
- " 20.0 | \n",
- " 28.0 | \n",
- "
\n",
- " \n",
- " 117 | \n",
- " 148.0 | \n",
- " 74.0 | \n",
- " 134.0 | \n",
- " 4.0 | \n",
- " 124.0 | \n",
- "
\n",
- " \n",
- " 118 | \n",
- " 102.0 | \n",
- " 81.0 | \n",
- " 138.0 | \n",
- " 128.0 | \n",
- " 32.0 | \n",
- "
\n",
- " \n",
- " 119 | \n",
- " 27.0 | \n",
- " 111.0 | \n",
- " 13.0 | \n",
- " 100.0 | \n",
- " 22.0 | \n",
- "
\n",
- " \n",
- " 120 | \n",
- " 28.0 | \n",
- " 93.0 | \n",
- " 121.0 | \n",
- " 100.0 | \n",
- " 4.0 | \n",
- "
\n",
- " \n",
- " 121 | \n",
- " 136.0 | \n",
- " 100.0 | \n",
- " 25.0 | \n",
- " 97.0 | \n",
- " 19.0 | \n",
- "
\n",
- " \n",
- " 122 | \n",
- " 111.0 | \n",
- " 70.0 | \n",
- " 12.0 | \n",
- " 38.0 | \n",
- " 58.0 | \n",
- "
\n",
- " \n",
- " 123 | \n",
- " 100.0 | \n",
- " 103.0 | \n",
- " 147.0 | \n",
- " 86.0 | \n",
- " 8.0 | \n",
- "
\n",
- " \n",
- " 124 | \n",
- " 10.0 | \n",
- " 10.0 | \n",
- " 46.0 | \n",
- " 63.0 | \n",
- " 149.0 | \n",
- "
\n",
- " \n",
- " 125 | \n",
- " 7.0 | \n",
- " 75.0 | \n",
- " 97.0 | \n",
- " 108.0 | \n",
- " 31.0 | \n",
- "
\n",
- " \n",
- " 126 | \n",
- " 88.0 | \n",
- " 6.0 | \n",
- " 100.0 | \n",
- " 100.0 | \n",
- " 55.0 | \n",
- "
\n",
- " \n",
- " 127 | \n",
- " 33.0 | \n",
- " 74.0 | \n",
- " 106.0 | \n",
- " 50.0 | \n",
- " 46.0 | \n",
- "
\n",
- " \n",
- " 128 | \n",
- " 74.0 | \n",
- " 28.0 | \n",
- " 26.0 | \n",
- " 100.0 | \n",
- " 76.0 | \n",
- "
\n",
- " \n",
- " 129 | \n",
- " 76.0 | \n",
- " 18.0 | \n",
- " 101.0 | \n",
- " 100.0 | \n",
- " 100.0 | \n",
- "
\n",
- " \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- "
\n",
- " \n",
- " 170 | \n",
- " 144.0 | \n",
- " 124.0 | \n",
- " 77.0 | \n",
- " 92.0 | \n",
- " 82.0 | \n",
- "
\n",
- " \n",
- " 171 | \n",
- " 36.0 | \n",
- " 98.0 | \n",
- " 100.0 | \n",
- " 43.0 | \n",
- " 80.0 | \n",
- "
\n",
- " \n",
- " 172 | \n",
- " 51.0 | \n",
- " 100.0 | \n",
- " 68.0 | \n",
- " 34.0 | \n",
- " 74.0 | \n",
- "
\n",
- " \n",
- " 173 | \n",
- " 149.0 | \n",
- " 100.0 | \n",
- " 18.0 | \n",
- " 141.0 | \n",
- " 100.0 | \n",
- "
\n",
- " \n",
- " 174 | \n",
- " 8.0 | \n",
- " 139.0 | \n",
- " 146.0 | \n",
- " 112.0 | \n",
- " 100.0 | \n",
- "
\n",
- " \n",
- " 175 | \n",
- " 115.0 | \n",
- " 100.0 | \n",
- " 64.0 | \n",
- " 62.0 | \n",
- " 9.0 | \n",
- "
\n",
- " \n",
- " 176 | \n",
- " 100.0 | \n",
- " 7.0 | \n",
- " 140.0 | \n",
- " 45.0 | \n",
- " 148.0 | \n",
- "
\n",
- " \n",
- " 177 | \n",
- " 100.0 | \n",
- " 43.0 | \n",
- " 68.0 | \n",
- " 109.0 | \n",
- " 18.0 | \n",
- "
\n",
- " \n",
- " 178 | \n",
- " 31.0 | \n",
- " 100.0 | \n",
- " 100.0 | \n",
- " 49.0 | \n",
- " 123.0 | \n",
- "
\n",
- " \n",
- " 179 | \n",
- " 29.0 | \n",
- " 46.0 | \n",
- " 69.0 | \n",
- " 57.0 | \n",
- " 90.0 | \n",
- "
\n",
- " \n",
- " 180 | \n",
- " 146.0 | \n",
- " 86.0 | \n",
- " 18.0 | \n",
- " 22.0 | \n",
- " 46.0 | \n",
- "
\n",
- " \n",
- " 181 | \n",
- " 71.0 | \n",
- " 50.0 | \n",
- " 40.0 | \n",
- " 100.0 | \n",
- " 140.0 | \n",
- "
\n",
- " \n",
- " 182 | \n",
- " 4.0 | \n",
- " 100.0 | \n",
- " 147.0 | \n",
- " 116.0 | \n",
- " 110.0 | \n",
- "
\n",
- " \n",
- " 183 | \n",
- " 55.0 | \n",
- " 87.0 | \n",
- " 93.0 | \n",
- " 100.0 | \n",
- " 34.0 | \n",
- "
\n",
- " \n",
- " 184 | \n",
- " 100.0 | \n",
- " 109.0 | \n",
- " 124.0 | \n",
- " 87.0 | \n",
- " 82.0 | \n",
- "
\n",
- " \n",
- " 185 | \n",
- " 10.0 | \n",
- " 118.0 | \n",
- " 139.0 | \n",
- " 50.0 | \n",
- " 51.0 | \n",
- "
\n",
- " \n",
- " 186 | \n",
- " 32.0 | \n",
- " 12.0 | \n",
- " 71.0 | \n",
- " 36.0 | \n",
- " 100.0 | \n",
- "
\n",
- " \n",
- " 187 | \n",
- " 94.0 | \n",
- " 100.0 | \n",
- " 138.0 | \n",
- " 13.0 | \n",
- " 149.0 | \n",
- "
\n",
- " \n",
- " 188 | \n",
- " 65.0 | \n",
- " 101.0 | \n",
- " 123.0 | \n",
- " 128.0 | \n",
- " 86.0 | \n",
- "
\n",
- " \n",
- " 189 | \n",
- " 43.0 | \n",
- " 94.0 | \n",
- " 100.0 | \n",
- " 29.0 | \n",
- " 132.0 | \n",
- "
\n",
- " \n",
- " 190 | \n",
- " 68.0 | \n",
- " 135.0 | \n",
- " 94.0 | \n",
- " 28.0 | \n",
- " 125.0 | \n",
- "
\n",
- " \n",
- " 191 | \n",
- " 30.0 | \n",
- " 60.0 | \n",
- " 98.0 | \n",
- " 100.0 | \n",
- " 15.0 | \n",
- "
\n",
- " \n",
- " 192 | \n",
- " 89.0 | \n",
- " 16.0 | \n",
- " 10.0 | \n",
- " 135.0 | \n",
- " 4.0 | \n",
- "
\n",
- " \n",
- " 193 | \n",
- " 104.0 | \n",
- " 139.0 | \n",
- " 97.0 | \n",
- " 29.0 | \n",
- " 17.0 | \n",
- "
\n",
- " \n",
- " 194 | \n",
- " 5.0 | \n",
- " 29.0 | \n",
- " 41.0 | \n",
- " 99.0 | \n",
- " 100.0 | \n",
- "
\n",
- " \n",
- " 195 | \n",
- " 19.0 | \n",
- " 102.0 | \n",
- " 135.0 | \n",
- " 41.0 | \n",
- " 40.0 | \n",
- "
\n",
- " \n",
- " 196 | \n",
- " 58.0 | \n",
- " 100.0 | \n",
- " 70.0 | \n",
- " 82.0 | \n",
- " 64.0 | \n",
- "
\n",
- " \n",
- " 197 | \n",
- " 100.0 | \n",
- " 97.0 | \n",
- " 129.0 | \n",
- " 76.0 | \n",
- " 13.0 | \n",
- "
\n",
- " \n",
- " 198 | \n",
- " 131.0 | \n",
- " 15.0 | \n",
- " 100.0 | \n",
- " 44.0 | \n",
- " 114.0 | \n",
- "
\n",
- " \n",
- " 199 | \n",
- " 79.0 | \n",
- " 100.0 | \n",
- " 95.0 | \n",
- " 128.0 | \n",
- " 100.0 | \n",
- "
\n",
- " \n",
- "
\n",
- "
100 rows × 5 columns
\n",
- "
"
- ],
- "text/plain": [
- " Python En Math Physic Chem\n",
- "100 122.0 10.0 5.0 28.0 57.0\n",
- "101 100.0 129.0 16.0 114.0 26.0\n",
- "102 97.0 121.0 122.0 29.0 65.0\n",
- "103 141.0 73.0 120.0 147.0 1.0\n",
- "104 126.0 100.0 86.0 116.0 17.0\n",
- "105 85.0 100.0 42.0 121.0 66.0\n",
- "106 142.0 65.0 1.0 124.0 83.0\n",
- "107 136.0 141.0 100.0 86.0 113.0\n",
- "108 15.0 37.0 124.0 110.0 102.0\n",
- "109 63.0 30.0 100.0 69.0 58.0\n",
- "110 100.0 100.0 113.0 109.0 16.0\n",
- "111 5.0 51.0 87.0 58.0 126.0\n",
- "112 53.0 97.0 76.0 37.0 45.0\n",
- "113 42.0 148.0 100.0 97.0 100.0\n",
- "114 70.0 138.0 69.0 68.0 134.0\n",
- "115 100.0 136.0 113.0 22.0 94.0\n",
- "116 31.0 137.0 6.0 20.0 28.0\n",
- "117 148.0 74.0 134.0 4.0 124.0\n",
- "118 102.0 81.0 138.0 128.0 32.0\n",
- "119 27.0 111.0 13.0 100.0 22.0\n",
- "120 28.0 93.0 121.0 100.0 4.0\n",
- "121 136.0 100.0 25.0 97.0 19.0\n",
- "122 111.0 70.0 12.0 38.0 58.0\n",
- "123 100.0 103.0 147.0 86.0 8.0\n",
- "124 10.0 10.0 46.0 63.0 149.0\n",
- "125 7.0 75.0 97.0 108.0 31.0\n",
- "126 88.0 6.0 100.0 100.0 55.0\n",
- "127 33.0 74.0 106.0 50.0 46.0\n",
- "128 74.0 28.0 26.0 100.0 76.0\n",
- "129 76.0 18.0 101.0 100.0 100.0\n",
- ".. ... ... ... ... ...\n",
- "170 144.0 124.0 77.0 92.0 82.0\n",
- "171 36.0 98.0 100.0 43.0 80.0\n",
- "172 51.0 100.0 68.0 34.0 74.0\n",
- "173 149.0 100.0 18.0 141.0 100.0\n",
- "174 8.0 139.0 146.0 112.0 100.0\n",
- "175 115.0 100.0 64.0 62.0 9.0\n",
- "176 100.0 7.0 140.0 45.0 148.0\n",
- "177 100.0 43.0 68.0 109.0 18.0\n",
- "178 31.0 100.0 100.0 49.0 123.0\n",
- "179 29.0 46.0 69.0 57.0 90.0\n",
- "180 146.0 86.0 18.0 22.0 46.0\n",
- "181 71.0 50.0 40.0 100.0 140.0\n",
- "182 4.0 100.0 147.0 116.0 110.0\n",
- "183 55.0 87.0 93.0 100.0 34.0\n",
- "184 100.0 109.0 124.0 87.0 82.0\n",
- "185 10.0 118.0 139.0 50.0 51.0\n",
- "186 32.0 12.0 71.0 36.0 100.0\n",
- "187 94.0 100.0 138.0 13.0 149.0\n",
- "188 65.0 101.0 123.0 128.0 86.0\n",
- "189 43.0 94.0 100.0 29.0 132.0\n",
- "190 68.0 135.0 94.0 28.0 125.0\n",
- "191 30.0 60.0 98.0 100.0 15.0\n",
- "192 89.0 16.0 10.0 135.0 4.0\n",
- "193 104.0 139.0 97.0 29.0 17.0\n",
- "194 5.0 29.0 41.0 99.0 100.0\n",
- "195 19.0 102.0 135.0 41.0 40.0\n",
- "196 58.0 100.0 70.0 82.0 64.0\n",
- "197 100.0 97.0 129.0 76.0 13.0\n",
- "198 131.0 15.0 100.0 44.0 114.0\n",
- "199 79.0 100.0 95.0 128.0 100.0\n",
- "\n",
- "[100 rows x 5 columns]"
- ]
- },
- "execution_count": 26,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
"source": [
"# 固定值填充\n",
- "df2.fillna(value=100)"
+ "df.fillna(value=100)"
]
},
{
"cell_type": "code",
- "execution_count": 27,
+ "execution_count": null,
"metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "Python 71.662791\n",
- "En 75.627907\n",
- "Math 77.929412\n",
- "Physic 73.471910\n",
- "Chem 69.080460\n",
- "dtype: float64"
- ]
- },
- "execution_count": 27,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "outputs": [],
"source": [
"df2.mean()"
]
@@ -2066,605 +160,9 @@
},
{
"cell_type": "code",
- "execution_count": 29,
- "metadata": {
- "collapsed": true
- },
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " Python | \n",
- " En | \n",
- " Math | \n",
- " Physic | \n",
- " Chem | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " 100 | \n",
- " 122 | \n",
- " 10 | \n",
- " 5 | \n",
- " 28 | \n",
- " 57 | \n",
- "
\n",
- " \n",
- " 101 | \n",
- " 71 | \n",
- " 129 | \n",
- " 16 | \n",
- " 114 | \n",
- " 26 | \n",
- "
\n",
- " \n",
- " 102 | \n",
- " 97 | \n",
- " 121 | \n",
- " 122 | \n",
- " 29 | \n",
- " 65 | \n",
- "
\n",
- " \n",
- " 103 | \n",
- " 141 | \n",
- " 73 | \n",
- " 120 | \n",
- " 147 | \n",
- " 1 | \n",
- "
\n",
- " \n",
- " 104 | \n",
- " 126 | \n",
- " 75 | \n",
- " 86 | \n",
- " 116 | \n",
- " 17 | \n",
- "
\n",
- " \n",
- " 105 | \n",
- " 85 | \n",
- " 75 | \n",
- " 42 | \n",
- " 121 | \n",
- " 66 | \n",
- "
\n",
- " \n",
- " 106 | \n",
- " 142 | \n",
- " 65 | \n",
- " 1 | \n",
- " 124 | \n",
- " 83 | \n",
- "
\n",
- " \n",
- " 107 | \n",
- " 136 | \n",
- " 141 | \n",
- " 77 | \n",
- " 86 | \n",
- " 113 | \n",
- "
\n",
- " \n",
- " 108 | \n",
- " 15 | \n",
- " 37 | \n",
- " 124 | \n",
- " 110 | \n",
- " 102 | \n",
- "
\n",
- " \n",
- " 109 | \n",
- " 63 | \n",
- " 30 | \n",
- " 77 | \n",
- " 69 | \n",
- " 58 | \n",
- "
\n",
- " \n",
- " 110 | \n",
- " 71 | \n",
- " 75 | \n",
- " 113 | \n",
- " 109 | \n",
- " 16 | \n",
- "
\n",
- " \n",
- " 111 | \n",
- " 5 | \n",
- " 51 | \n",
- " 87 | \n",
- " 58 | \n",
- " 126 | \n",
- "
\n",
- " \n",
- " 112 | \n",
- " 53 | \n",
- " 97 | \n",
- " 76 | \n",
- " 37 | \n",
- " 45 | \n",
- "
\n",
- " \n",
- " 113 | \n",
- " 42 | \n",
- " 148 | \n",
- " 77 | \n",
- " 97 | \n",
- " 69 | \n",
- "
\n",
- " \n",
- " 114 | \n",
- " 70 | \n",
- " 138 | \n",
- " 69 | \n",
- " 68 | \n",
- " 134 | \n",
- "
\n",
- " \n",
- " 115 | \n",
- " 71 | \n",
- " 136 | \n",
- " 113 | \n",
- " 22 | \n",
- " 94 | \n",
- "
\n",
- " \n",
- " 116 | \n",
- " 31 | \n",
- " 137 | \n",
- " 6 | \n",
- " 20 | \n",
- " 28 | \n",
- "
\n",
- " \n",
- " 117 | \n",
- " 148 | \n",
- " 74 | \n",
- " 134 | \n",
- " 4 | \n",
- " 124 | \n",
- "
\n",
- " \n",
- " 118 | \n",
- " 102 | \n",
- " 81 | \n",
- " 138 | \n",
- " 128 | \n",
- " 32 | \n",
- "
\n",
- " \n",
- " 119 | \n",
- " 27 | \n",
- " 111 | \n",
- " 13 | \n",
- " 73 | \n",
- " 22 | \n",
- "
\n",
- " \n",
- " 120 | \n",
- " 28 | \n",
- " 93 | \n",
- " 121 | \n",
- " 73 | \n",
- " 4 | \n",
- "
\n",
- " \n",
- " 121 | \n",
- " 136 | \n",
- " 75 | \n",
- " 25 | \n",
- " 97 | \n",
- " 19 | \n",
- "
\n",
- " \n",
- " 122 | \n",
- " 111 | \n",
- " 70 | \n",
- " 12 | \n",
- " 38 | \n",
- " 58 | \n",
- "
\n",
- " \n",
- " 123 | \n",
- " 71 | \n",
- " 103 | \n",
- " 147 | \n",
- " 86 | \n",
- " 8 | \n",
- "
\n",
- " \n",
- " 124 | \n",
- " 10 | \n",
- " 10 | \n",
- " 46 | \n",
- " 63 | \n",
- " 149 | \n",
- "
\n",
- " \n",
- " 125 | \n",
- " 7 | \n",
- " 75 | \n",
- " 97 | \n",
- " 108 | \n",
- " 31 | \n",
- "
\n",
- " \n",
- " 126 | \n",
- " 88 | \n",
- " 6 | \n",
- " 77 | \n",
- " 73 | \n",
- " 55 | \n",
- "
\n",
- " \n",
- " 127 | \n",
- " 33 | \n",
- " 74 | \n",
- " 106 | \n",
- " 50 | \n",
- " 46 | \n",
- "
\n",
- " \n",
- " 128 | \n",
- " 74 | \n",
- " 28 | \n",
- " 26 | \n",
- " 100 | \n",
- " 76 | \n",
- "
\n",
- " \n",
- " 129 | \n",
- " 76 | \n",
- " 18 | \n",
- " 101 | \n",
- " 73 | \n",
- " 69 | \n",
- "
\n",
- " \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- "
\n",
- " \n",
- " 170 | \n",
- " 144 | \n",
- " 124 | \n",
- " 77 | \n",
- " 92 | \n",
- " 82 | \n",
- "
\n",
- " \n",
- " 171 | \n",
- " 36 | \n",
- " 98 | \n",
- " 77 | \n",
- " 43 | \n",
- " 80 | \n",
- "
\n",
- " \n",
- " 172 | \n",
- " 51 | \n",
- " 75 | \n",
- " 68 | \n",
- " 34 | \n",
- " 74 | \n",
- "
\n",
- " \n",
- " 173 | \n",
- " 149 | \n",
- " 75 | \n",
- " 18 | \n",
- " 141 | \n",
- " 69 | \n",
- "
\n",
- " \n",
- " 174 | \n",
- " 8 | \n",
- " 139 | \n",
- " 146 | \n",
- " 112 | \n",
- " 69 | \n",
- "
\n",
- " \n",
- " 175 | \n",
- " 115 | \n",
- " 75 | \n",
- " 64 | \n",
- " 62 | \n",
- " 9 | \n",
- "
\n",
- " \n",
- " 176 | \n",
- " 71 | \n",
- " 7 | \n",
- " 140 | \n",
- " 45 | \n",
- " 148 | \n",
- "
\n",
- " \n",
- " 177 | \n",
- " 71 | \n",
- " 43 | \n",
- " 68 | \n",
- " 109 | \n",
- " 18 | \n",
- "
\n",
- " \n",
- " 178 | \n",
- " 31 | \n",
- " 100 | \n",
- " 77 | \n",
- " 49 | \n",
- " 123 | \n",
- "
\n",
- " \n",
- " 179 | \n",
- " 29 | \n",
- " 46 | \n",
- " 69 | \n",
- " 57 | \n",
- " 90 | \n",
- "
\n",
- " \n",
- " 180 | \n",
- " 146 | \n",
- " 86 | \n",
- " 18 | \n",
- " 22 | \n",
- " 46 | \n",
- "
\n",
- " \n",
- " 181 | \n",
- " 71 | \n",
- " 50 | \n",
- " 40 | \n",
- " 73 | \n",
- " 140 | \n",
- "
\n",
- " \n",
- " 182 | \n",
- " 4 | \n",
- " 100 | \n",
- " 147 | \n",
- " 116 | \n",
- " 110 | \n",
- "
\n",
- " \n",
- " 183 | \n",
- " 55 | \n",
- " 87 | \n",
- " 93 | \n",
- " 73 | \n",
- " 34 | \n",
- "
\n",
- " \n",
- " 184 | \n",
- " 71 | \n",
- " 109 | \n",
- " 124 | \n",
- " 87 | \n",
- " 82 | \n",
- "
\n",
- " \n",
- " 185 | \n",
- " 10 | \n",
- " 118 | \n",
- " 139 | \n",
- " 50 | \n",
- " 51 | \n",
- "
\n",
- " \n",
- " 186 | \n",
- " 32 | \n",
- " 12 | \n",
- " 71 | \n",
- " 36 | \n",
- " 69 | \n",
- "
\n",
- " \n",
- " 187 | \n",
- " 94 | \n",
- " 75 | \n",
- " 138 | \n",
- " 13 | \n",
- " 149 | \n",
- "
\n",
- " \n",
- " 188 | \n",
- " 65 | \n",
- " 101 | \n",
- " 123 | \n",
- " 128 | \n",
- " 86 | \n",
- "
\n",
- " \n",
- " 189 | \n",
- " 43 | \n",
- " 94 | \n",
- " 77 | \n",
- " 29 | \n",
- " 132 | \n",
- "
\n",
- " \n",
- " 190 | \n",
- " 68 | \n",
- " 135 | \n",
- " 94 | \n",
- " 28 | \n",
- " 125 | \n",
- "
\n",
- " \n",
- " 191 | \n",
- " 30 | \n",
- " 60 | \n",
- " 98 | \n",
- " 73 | \n",
- " 15 | \n",
- "
\n",
- " \n",
- " 192 | \n",
- " 89 | \n",
- " 16 | \n",
- " 10 | \n",
- " 135 | \n",
- " 4 | \n",
- "
\n",
- " \n",
- " 193 | \n",
- " 104 | \n",
- " 139 | \n",
- " 97 | \n",
- " 29 | \n",
- " 17 | \n",
- "
\n",
- " \n",
- " 194 | \n",
- " 5 | \n",
- " 29 | \n",
- " 41 | \n",
- " 99 | \n",
- " 69 | \n",
- "
\n",
- " \n",
- " 195 | \n",
- " 19 | \n",
- " 102 | \n",
- " 135 | \n",
- " 41 | \n",
- " 40 | \n",
- "
\n",
- " \n",
- " 196 | \n",
- " 58 | \n",
- " 75 | \n",
- " 70 | \n",
- " 82 | \n",
- " 64 | \n",
- "
\n",
- " \n",
- " 197 | \n",
- " 71 | \n",
- " 97 | \n",
- " 129 | \n",
- " 76 | \n",
- " 13 | \n",
- "
\n",
- " \n",
- " 198 | \n",
- " 131 | \n",
- " 15 | \n",
- " 77 | \n",
- " 44 | \n",
- " 114 | \n",
- "
\n",
- " \n",
- " 199 | \n",
- " 79 | \n",
- " 75 | \n",
- " 95 | \n",
- " 128 | \n",
- " 69 | \n",
- "
\n",
- " \n",
- "
\n",
- "
100 rows × 5 columns
\n",
- "
"
- ],
- "text/plain": [
- " Python En Math Physic Chem\n",
- "100 122 10 5 28 57\n",
- "101 71 129 16 114 26\n",
- "102 97 121 122 29 65\n",
- "103 141 73 120 147 1\n",
- "104 126 75 86 116 17\n",
- "105 85 75 42 121 66\n",
- "106 142 65 1 124 83\n",
- "107 136 141 77 86 113\n",
- "108 15 37 124 110 102\n",
- "109 63 30 77 69 58\n",
- "110 71 75 113 109 16\n",
- "111 5 51 87 58 126\n",
- "112 53 97 76 37 45\n",
- "113 42 148 77 97 69\n",
- "114 70 138 69 68 134\n",
- "115 71 136 113 22 94\n",
- "116 31 137 6 20 28\n",
- "117 148 74 134 4 124\n",
- "118 102 81 138 128 32\n",
- "119 27 111 13 73 22\n",
- "120 28 93 121 73 4\n",
- "121 136 75 25 97 19\n",
- "122 111 70 12 38 58\n",
- "123 71 103 147 86 8\n",
- "124 10 10 46 63 149\n",
- "125 7 75 97 108 31\n",
- "126 88 6 77 73 55\n",
- "127 33 74 106 50 46\n",
- "128 74 28 26 100 76\n",
- "129 76 18 101 73 69\n",
- ".. ... ... ... ... ...\n",
- "170 144 124 77 92 82\n",
- "171 36 98 77 43 80\n",
- "172 51 75 68 34 74\n",
- "173 149 75 18 141 69\n",
- "174 8 139 146 112 69\n",
- "175 115 75 64 62 9\n",
- "176 71 7 140 45 148\n",
- "177 71 43 68 109 18\n",
- "178 31 100 77 49 123\n",
- "179 29 46 69 57 90\n",
- "180 146 86 18 22 46\n",
- "181 71 50 40 73 140\n",
- "182 4 100 147 116 110\n",
- "183 55 87 93 73 34\n",
- "184 71 109 124 87 82\n",
- "185 10 118 139 50 51\n",
- "186 32 12 71 36 69\n",
- "187 94 75 138 13 149\n",
- "188 65 101 123 128 86\n",
- "189 43 94 77 29 132\n",
- "190 68 135 94 28 125\n",
- "191 30 60 98 73 15\n",
- "192 89 16 10 135 4\n",
- "193 104 139 97 29 17\n",
- "194 5 29 41 99 69\n",
- "195 19 102 135 41 40\n",
- "196 58 75 70 82 64\n",
- "197 71 97 129 76 13\n",
- "198 131 15 77 44 114\n",
- "199 79 75 95 128 69\n",
- "\n",
- "[100 rows x 5 columns]"
- ]
- },
- "execution_count": 29,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
"source": [
"# 均值\n",
"df3 = df2.fillna(value=df2.mean())\n",
@@ -2673,22 +171,11 @@
},
{
"cell_type": "code",
- "execution_count": 31,
+ "execution_count": null,
"metadata": {
"scrolled": true
},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "array([ 6, 18, 1, 17, 19, 5, 17, 16, 13, 3])"
- ]
- },
- "execution_count": 31,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "outputs": [],
"source": [
"nd = np.random.randint(0,20,size = 10)\n",
"nd"
@@ -2696,20 +183,9 @@
},
{
"cell_type": "code",
- "execution_count": 33,
+ "execution_count": null,
"metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "array([ 1, 3, 5, 6, 13, 16, 17, 17, 18, 19])"
- ]
- },
- "execution_count": 33,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "outputs": [],
"source": [
"nd.sort()\n",
"nd"
@@ -2717,645 +193,27 @@
},
{
"cell_type": "code",
- "execution_count": 34,
+ "execution_count": null,
"metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "14.5"
- ]
- },
- "execution_count": 34,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "outputs": [],
"source": [
"(13 + 16)/2"
]
},
{
"cell_type": "code",
- "execution_count": 35,
+ "execution_count": null,
"metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "14.5"
- ]
- },
- "execution_count": 35,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "outputs": [],
"source": [
"np.median(nd)"
]
},
{
"cell_type": "code",
- "execution_count": 36,
- "metadata": {
- "collapsed": true
- },
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " Python | \n",
- " En | \n",
- " Math | \n",
- " Physic | \n",
- " Chem | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " 100 | \n",
- " 122.0 | \n",
- " 10.0 | \n",
- " 5.0 | \n",
- " 28.0 | \n",
- " 57.0 | \n",
- "
\n",
- " \n",
- " 101 | \n",
- " 68.0 | \n",
- " 129.0 | \n",
- " 16.0 | \n",
- " 114.0 | \n",
- " 26.0 | \n",
- "
\n",
- " \n",
- " 102 | \n",
- " 97.0 | \n",
- " 121.0 | \n",
- " 122.0 | \n",
- " 29.0 | \n",
- " 65.0 | \n",
- "
\n",
- " \n",
- " 103 | \n",
- " 141.0 | \n",
- " 73.0 | \n",
- " 120.0 | \n",
- " 147.0 | \n",
- " 1.0 | \n",
- "
\n",
- " \n",
- " 104 | \n",
- " 126.0 | \n",
- " 82.5 | \n",
- " 86.0 | \n",
- " 116.0 | \n",
- " 17.0 | \n",
- "
\n",
- " \n",
- " 105 | \n",
- " 85.0 | \n",
- " 82.5 | \n",
- " 42.0 | \n",
- " 121.0 | \n",
- " 66.0 | \n",
- "
\n",
- " \n",
- " 106 | \n",
- " 142.0 | \n",
- " 65.0 | \n",
- " 1.0 | \n",
- " 124.0 | \n",
- " 83.0 | \n",
- "
\n",
- " \n",
- " 107 | \n",
- " 136.0 | \n",
- " 141.0 | \n",
- " 86.0 | \n",
- " 86.0 | \n",
- " 113.0 | \n",
- "
\n",
- " \n",
- " 108 | \n",
- " 15.0 | \n",
- " 37.0 | \n",
- " 124.0 | \n",
- " 110.0 | \n",
- " 102.0 | \n",
- "
\n",
- " \n",
- " 109 | \n",
- " 63.0 | \n",
- " 30.0 | \n",
- " 86.0 | \n",
- " 69.0 | \n",
- " 58.0 | \n",
- "
\n",
- " \n",
- " 110 | \n",
- " 68.0 | \n",
- " 82.5 | \n",
- " 113.0 | \n",
- " 109.0 | \n",
- " 16.0 | \n",
- "
\n",
- " \n",
- " 111 | \n",
- " 5.0 | \n",
- " 51.0 | \n",
- " 87.0 | \n",
- " 58.0 | \n",
- " 126.0 | \n",
- "
\n",
- " \n",
- " 112 | \n",
- " 53.0 | \n",
- " 97.0 | \n",
- " 76.0 | \n",
- " 37.0 | \n",
- " 45.0 | \n",
- "
\n",
- " \n",
- " 113 | \n",
- " 42.0 | \n",
- " 148.0 | \n",
- " 86.0 | \n",
- " 97.0 | \n",
- " 65.0 | \n",
- "
\n",
- " \n",
- " 114 | \n",
- " 70.0 | \n",
- " 138.0 | \n",
- " 69.0 | \n",
- " 68.0 | \n",
- " 134.0 | \n",
- "
\n",
- " \n",
- " 115 | \n",
- " 68.0 | \n",
- " 136.0 | \n",
- " 113.0 | \n",
- " 22.0 | \n",
- " 94.0 | \n",
- "
\n",
- " \n",
- " 116 | \n",
- " 31.0 | \n",
- " 137.0 | \n",
- " 6.0 | \n",
- " 20.0 | \n",
- " 28.0 | \n",
- "
\n",
- " \n",
- " 117 | \n",
- " 148.0 | \n",
- " 74.0 | \n",
- " 134.0 | \n",
- " 4.0 | \n",
- " 124.0 | \n",
- "
\n",
- " \n",
- " 118 | \n",
- " 102.0 | \n",
- " 81.0 | \n",
- " 138.0 | \n",
- " 128.0 | \n",
- " 32.0 | \n",
- "
\n",
- " \n",
- " 119 | \n",
- " 27.0 | \n",
- " 111.0 | \n",
- " 13.0 | \n",
- " 69.0 | \n",
- " 22.0 | \n",
- "
\n",
- " \n",
- " 120 | \n",
- " 28.0 | \n",
- " 93.0 | \n",
- " 121.0 | \n",
- " 69.0 | \n",
- " 4.0 | \n",
- "
\n",
- " \n",
- " 121 | \n",
- " 136.0 | \n",
- " 82.5 | \n",
- " 25.0 | \n",
- " 97.0 | \n",
- " 19.0 | \n",
- "
\n",
- " \n",
- " 122 | \n",
- " 111.0 | \n",
- " 70.0 | \n",
- " 12.0 | \n",
- " 38.0 | \n",
- " 58.0 | \n",
- "
\n",
- " \n",
- " 123 | \n",
- " 68.0 | \n",
- " 103.0 | \n",
- " 147.0 | \n",
- " 86.0 | \n",
- " 8.0 | \n",
- "
\n",
- " \n",
- " 124 | \n",
- " 10.0 | \n",
- " 10.0 | \n",
- " 46.0 | \n",
- " 63.0 | \n",
- " 149.0 | \n",
- "
\n",
- " \n",
- " 125 | \n",
- " 7.0 | \n",
- " 75.0 | \n",
- " 97.0 | \n",
- " 108.0 | \n",
- " 31.0 | \n",
- "
\n",
- " \n",
- " 126 | \n",
- " 88.0 | \n",
- " 6.0 | \n",
- " 86.0 | \n",
- " 69.0 | \n",
- " 55.0 | \n",
- "
\n",
- " \n",
- " 127 | \n",
- " 33.0 | \n",
- " 74.0 | \n",
- " 106.0 | \n",
- " 50.0 | \n",
- " 46.0 | \n",
- "
\n",
- " \n",
- " 128 | \n",
- " 74.0 | \n",
- " 28.0 | \n",
- " 26.0 | \n",
- " 100.0 | \n",
- " 76.0 | \n",
- "
\n",
- " \n",
- " 129 | \n",
- " 76.0 | \n",
- " 18.0 | \n",
- " 101.0 | \n",
- " 69.0 | \n",
- " 65.0 | \n",
- "
\n",
- " \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- "
\n",
- " \n",
- " 170 | \n",
- " 144.0 | \n",
- " 124.0 | \n",
- " 77.0 | \n",
- " 92.0 | \n",
- " 82.0 | \n",
- "
\n",
- " \n",
- " 171 | \n",
- " 36.0 | \n",
- " 98.0 | \n",
- " 86.0 | \n",
- " 43.0 | \n",
- " 80.0 | \n",
- "
\n",
- " \n",
- " 172 | \n",
- " 51.0 | \n",
- " 82.5 | \n",
- " 68.0 | \n",
- " 34.0 | \n",
- " 74.0 | \n",
- "
\n",
- " \n",
- " 173 | \n",
- " 149.0 | \n",
- " 82.5 | \n",
- " 18.0 | \n",
- " 141.0 | \n",
- " 65.0 | \n",
- "
\n",
- " \n",
- " 174 | \n",
- " 8.0 | \n",
- " 139.0 | \n",
- " 146.0 | \n",
- " 112.0 | \n",
- " 65.0 | \n",
- "
\n",
- " \n",
- " 175 | \n",
- " 115.0 | \n",
- " 82.5 | \n",
- " 64.0 | \n",
- " 62.0 | \n",
- " 9.0 | \n",
- "
\n",
- " \n",
- " 176 | \n",
- " 68.0 | \n",
- " 7.0 | \n",
- " 140.0 | \n",
- " 45.0 | \n",
- " 148.0 | \n",
- "
\n",
- " \n",
- " 177 | \n",
- " 68.0 | \n",
- " 43.0 | \n",
- " 68.0 | \n",
- " 109.0 | \n",
- " 18.0 | \n",
- "
\n",
- " \n",
- " 178 | \n",
- " 31.0 | \n",
- " 100.0 | \n",
- " 86.0 | \n",
- " 49.0 | \n",
- " 123.0 | \n",
- "
\n",
- " \n",
- " 179 | \n",
- " 29.0 | \n",
- " 46.0 | \n",
- " 69.0 | \n",
- " 57.0 | \n",
- " 90.0 | \n",
- "
\n",
- " \n",
- " 180 | \n",
- " 146.0 | \n",
- " 86.0 | \n",
- " 18.0 | \n",
- " 22.0 | \n",
- " 46.0 | \n",
- "
\n",
- " \n",
- " 181 | \n",
- " 71.0 | \n",
- " 50.0 | \n",
- " 40.0 | \n",
- " 69.0 | \n",
- " 140.0 | \n",
- "
\n",
- " \n",
- " 182 | \n",
- " 4.0 | \n",
- " 100.0 | \n",
- " 147.0 | \n",
- " 116.0 | \n",
- " 110.0 | \n",
- "
\n",
- " \n",
- " 183 | \n",
- " 55.0 | \n",
- " 87.0 | \n",
- " 93.0 | \n",
- " 69.0 | \n",
- " 34.0 | \n",
- "
\n",
- " \n",
- " 184 | \n",
- " 68.0 | \n",
- " 109.0 | \n",
- " 124.0 | \n",
- " 87.0 | \n",
- " 82.0 | \n",
- "
\n",
- " \n",
- " 185 | \n",
- " 10.0 | \n",
- " 118.0 | \n",
- " 139.0 | \n",
- " 50.0 | \n",
- " 51.0 | \n",
- "
\n",
- " \n",
- " 186 | \n",
- " 32.0 | \n",
- " 12.0 | \n",
- " 71.0 | \n",
- " 36.0 | \n",
- " 65.0 | \n",
- "
\n",
- " \n",
- " 187 | \n",
- " 94.0 | \n",
- " 82.5 | \n",
- " 138.0 | \n",
- " 13.0 | \n",
- " 149.0 | \n",
- "
\n",
- " \n",
- " 188 | \n",
- " 65.0 | \n",
- " 101.0 | \n",
- " 123.0 | \n",
- " 128.0 | \n",
- " 86.0 | \n",
- "
\n",
- " \n",
- " 189 | \n",
- " 43.0 | \n",
- " 94.0 | \n",
- " 86.0 | \n",
- " 29.0 | \n",
- " 132.0 | \n",
- "
\n",
- " \n",
- " 190 | \n",
- " 68.0 | \n",
- " 135.0 | \n",
- " 94.0 | \n",
- " 28.0 | \n",
- " 125.0 | \n",
- "
\n",
- " \n",
- " 191 | \n",
- " 30.0 | \n",
- " 60.0 | \n",
- " 98.0 | \n",
- " 69.0 | \n",
- " 15.0 | \n",
- "
\n",
- " \n",
- " 192 | \n",
- " 89.0 | \n",
- " 16.0 | \n",
- " 10.0 | \n",
- " 135.0 | \n",
- " 4.0 | \n",
- "
\n",
- " \n",
- " 193 | \n",
- " 104.0 | \n",
- " 139.0 | \n",
- " 97.0 | \n",
- " 29.0 | \n",
- " 17.0 | \n",
- "
\n",
- " \n",
- " 194 | \n",
- " 5.0 | \n",
- " 29.0 | \n",
- " 41.0 | \n",
- " 99.0 | \n",
- " 65.0 | \n",
- "
\n",
- " \n",
- " 195 | \n",
- " 19.0 | \n",
- " 102.0 | \n",
- " 135.0 | \n",
- " 41.0 | \n",
- " 40.0 | \n",
- "
\n",
- " \n",
- " 196 | \n",
- " 58.0 | \n",
- " 82.5 | \n",
- " 70.0 | \n",
- " 82.0 | \n",
- " 64.0 | \n",
- "
\n",
- " \n",
- " 197 | \n",
- " 68.0 | \n",
- " 97.0 | \n",
- " 129.0 | \n",
- " 76.0 | \n",
- " 13.0 | \n",
- "
\n",
- " \n",
- " 198 | \n",
- " 131.0 | \n",
- " 15.0 | \n",
- " 86.0 | \n",
- " 44.0 | \n",
- " 114.0 | \n",
- "
\n",
- " \n",
- " 199 | \n",
- " 79.0 | \n",
- " 82.5 | \n",
- " 95.0 | \n",
- " 128.0 | \n",
- " 65.0 | \n",
- "
\n",
- " \n",
- "
\n",
- "
100 rows × 5 columns
\n",
- "
"
- ],
- "text/plain": [
- " Python En Math Physic Chem\n",
- "100 122.0 10.0 5.0 28.0 57.0\n",
- "101 68.0 129.0 16.0 114.0 26.0\n",
- "102 97.0 121.0 122.0 29.0 65.0\n",
- "103 141.0 73.0 120.0 147.0 1.0\n",
- "104 126.0 82.5 86.0 116.0 17.0\n",
- "105 85.0 82.5 42.0 121.0 66.0\n",
- "106 142.0 65.0 1.0 124.0 83.0\n",
- "107 136.0 141.0 86.0 86.0 113.0\n",
- "108 15.0 37.0 124.0 110.0 102.0\n",
- "109 63.0 30.0 86.0 69.0 58.0\n",
- "110 68.0 82.5 113.0 109.0 16.0\n",
- "111 5.0 51.0 87.0 58.0 126.0\n",
- "112 53.0 97.0 76.0 37.0 45.0\n",
- "113 42.0 148.0 86.0 97.0 65.0\n",
- "114 70.0 138.0 69.0 68.0 134.0\n",
- "115 68.0 136.0 113.0 22.0 94.0\n",
- "116 31.0 137.0 6.0 20.0 28.0\n",
- "117 148.0 74.0 134.0 4.0 124.0\n",
- "118 102.0 81.0 138.0 128.0 32.0\n",
- "119 27.0 111.0 13.0 69.0 22.0\n",
- "120 28.0 93.0 121.0 69.0 4.0\n",
- "121 136.0 82.5 25.0 97.0 19.0\n",
- "122 111.0 70.0 12.0 38.0 58.0\n",
- "123 68.0 103.0 147.0 86.0 8.0\n",
- "124 10.0 10.0 46.0 63.0 149.0\n",
- "125 7.0 75.0 97.0 108.0 31.0\n",
- "126 88.0 6.0 86.0 69.0 55.0\n",
- "127 33.0 74.0 106.0 50.0 46.0\n",
- "128 74.0 28.0 26.0 100.0 76.0\n",
- "129 76.0 18.0 101.0 69.0 65.0\n",
- ".. ... ... ... ... ...\n",
- "170 144.0 124.0 77.0 92.0 82.0\n",
- "171 36.0 98.0 86.0 43.0 80.0\n",
- "172 51.0 82.5 68.0 34.0 74.0\n",
- "173 149.0 82.5 18.0 141.0 65.0\n",
- "174 8.0 139.0 146.0 112.0 65.0\n",
- "175 115.0 82.5 64.0 62.0 9.0\n",
- "176 68.0 7.0 140.0 45.0 148.0\n",
- "177 68.0 43.0 68.0 109.0 18.0\n",
- "178 31.0 100.0 86.0 49.0 123.0\n",
- "179 29.0 46.0 69.0 57.0 90.0\n",
- "180 146.0 86.0 18.0 22.0 46.0\n",
- "181 71.0 50.0 40.0 69.0 140.0\n",
- "182 4.0 100.0 147.0 116.0 110.0\n",
- "183 55.0 87.0 93.0 69.0 34.0\n",
- "184 68.0 109.0 124.0 87.0 82.0\n",
- "185 10.0 118.0 139.0 50.0 51.0\n",
- "186 32.0 12.0 71.0 36.0 65.0\n",
- "187 94.0 82.5 138.0 13.0 149.0\n",
- "188 65.0 101.0 123.0 128.0 86.0\n",
- "189 43.0 94.0 86.0 29.0 132.0\n",
- "190 68.0 135.0 94.0 28.0 125.0\n",
- "191 30.0 60.0 98.0 69.0 15.0\n",
- "192 89.0 16.0 10.0 135.0 4.0\n",
- "193 104.0 139.0 97.0 29.0 17.0\n",
- "194 5.0 29.0 41.0 99.0 65.0\n",
- "195 19.0 102.0 135.0 41.0 40.0\n",
- "196 58.0 82.5 70.0 82.0 64.0\n",
- "197 68.0 97.0 129.0 76.0 13.0\n",
- "198 131.0 15.0 86.0 44.0 114.0\n",
- "199 79.0 82.5 95.0 128.0 65.0\n",
- "\n",
- "[100 rows x 5 columns]"
- ]
- },
- "execution_count": 36,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
"source": [
"# 中位数填充\n",
"df2.median()\n",
@@ -3365,605 +223,9 @@
},
{
"cell_type": "code",
- "execution_count": 37,
- "metadata": {
- "collapsed": true
- },
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " Python | \n",
- " En | \n",
- " Math | \n",
- " Physic | \n",
- " Chem | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " 100 | \n",
- " 122.0 | \n",
- " 10.0 | \n",
- " 5.0 | \n",
- " 28.0 | \n",
- " 57.0 | \n",
- "
\n",
- " \n",
- " 101 | \n",
- " NaN | \n",
- " 129.0 | \n",
- " 16.0 | \n",
- " 114.0 | \n",
- " 26.0 | \n",
- "
\n",
- " \n",
- " 102 | \n",
- " 97.0 | \n",
- " 121.0 | \n",
- " 122.0 | \n",
- " 29.0 | \n",
- " 65.0 | \n",
- "
\n",
- " \n",
- " 103 | \n",
- " 141.0 | \n",
- " 73.0 | \n",
- " 120.0 | \n",
- " 147.0 | \n",
- " 1.0 | \n",
- "
\n",
- " \n",
- " 104 | \n",
- " 126.0 | \n",
- " NaN | \n",
- " 86.0 | \n",
- " 116.0 | \n",
- " 17.0 | \n",
- "
\n",
- " \n",
- " 105 | \n",
- " 85.0 | \n",
- " NaN | \n",
- " 42.0 | \n",
- " 121.0 | \n",
- " 66.0 | \n",
- "
\n",
- " \n",
- " 106 | \n",
- " 142.0 | \n",
- " 65.0 | \n",
- " 1.0 | \n",
- " 124.0 | \n",
- " 83.0 | \n",
- "
\n",
- " \n",
- " 107 | \n",
- " 136.0 | \n",
- " 141.0 | \n",
- " NaN | \n",
- " 86.0 | \n",
- " 113.0 | \n",
- "
\n",
- " \n",
- " 108 | \n",
- " 15.0 | \n",
- " 37.0 | \n",
- " 124.0 | \n",
- " 110.0 | \n",
- " 102.0 | \n",
- "
\n",
- " \n",
- " 109 | \n",
- " 63.0 | \n",
- " 30.0 | \n",
- " NaN | \n",
- " 69.0 | \n",
- " 58.0 | \n",
- "
\n",
- " \n",
- " 110 | \n",
- " NaN | \n",
- " NaN | \n",
- " 113.0 | \n",
- " 109.0 | \n",
- " 16.0 | \n",
- "
\n",
- " \n",
- " 111 | \n",
- " 5.0 | \n",
- " 51.0 | \n",
- " 87.0 | \n",
- " 58.0 | \n",
- " 126.0 | \n",
- "
\n",
- " \n",
- " 112 | \n",
- " 53.0 | \n",
- " 97.0 | \n",
- " 76.0 | \n",
- " 37.0 | \n",
- " 45.0 | \n",
- "
\n",
- " \n",
- " 113 | \n",
- " 42.0 | \n",
- " 148.0 | \n",
- " NaN | \n",
- " 97.0 | \n",
- " NaN | \n",
- "
\n",
- " \n",
- " 114 | \n",
- " 70.0 | \n",
- " 138.0 | \n",
- " 69.0 | \n",
- " 68.0 | \n",
- " 134.0 | \n",
- "
\n",
- " \n",
- " 115 | \n",
- " NaN | \n",
- " 136.0 | \n",
- " 113.0 | \n",
- " 22.0 | \n",
- " 94.0 | \n",
- "
\n",
- " \n",
- " 116 | \n",
- " 31.0 | \n",
- " 137.0 | \n",
- " 6.0 | \n",
- " 20.0 | \n",
- " 28.0 | \n",
- "
\n",
- " \n",
- " 117 | \n",
- " 148.0 | \n",
- " 74.0 | \n",
- " 134.0 | \n",
- " 4.0 | \n",
- " 124.0 | \n",
- "
\n",
- " \n",
- " 118 | \n",
- " 102.0 | \n",
- " 81.0 | \n",
- " 138.0 | \n",
- " 128.0 | \n",
- " 32.0 | \n",
- "
\n",
- " \n",
- " 119 | \n",
- " 27.0 | \n",
- " 111.0 | \n",
- " 13.0 | \n",
- " NaN | \n",
- " 22.0 | \n",
- "
\n",
- " \n",
- " 120 | \n",
- " 28.0 | \n",
- " 93.0 | \n",
- " 121.0 | \n",
- " NaN | \n",
- " 4.0 | \n",
- "
\n",
- " \n",
- " 121 | \n",
- " 136.0 | \n",
- " NaN | \n",
- " 25.0 | \n",
- " 97.0 | \n",
- " 19.0 | \n",
- "
\n",
- " \n",
- " 122 | \n",
- " 111.0 | \n",
- " 70.0 | \n",
- " 12.0 | \n",
- " 38.0 | \n",
- " 58.0 | \n",
- "
\n",
- " \n",
- " 123 | \n",
- " NaN | \n",
- " 103.0 | \n",
- " 147.0 | \n",
- " 86.0 | \n",
- " 8.0 | \n",
- "
\n",
- " \n",
- " 124 | \n",
- " 10.0 | \n",
- " 10.0 | \n",
- " 46.0 | \n",
- " 63.0 | \n",
- " 149.0 | \n",
- "
\n",
- " \n",
- " 125 | \n",
- " 7.0 | \n",
- " 75.0 | \n",
- " 97.0 | \n",
- " 108.0 | \n",
- " 31.0 | \n",
- "
\n",
- " \n",
- " 126 | \n",
- " 88.0 | \n",
- " 6.0 | \n",
- " NaN | \n",
- " NaN | \n",
- " 55.0 | \n",
- "
\n",
- " \n",
- " 127 | \n",
- " 33.0 | \n",
- " 74.0 | \n",
- " 106.0 | \n",
- " 50.0 | \n",
- " 46.0 | \n",
- "
\n",
- " \n",
- " 128 | \n",
- " 74.0 | \n",
- " 28.0 | \n",
- " 26.0 | \n",
- " 100.0 | \n",
- " 76.0 | \n",
- "
\n",
- " \n",
- " 129 | \n",
- " 76.0 | \n",
- " 18.0 | \n",
- " 101.0 | \n",
- " NaN | \n",
- " NaN | \n",
- "
\n",
- " \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- "
\n",
- " \n",
- " 170 | \n",
- " 144.0 | \n",
- " 124.0 | \n",
- " 77.0 | \n",
- " 92.0 | \n",
- " 82.0 | \n",
- "
\n",
- " \n",
- " 171 | \n",
- " 36.0 | \n",
- " 98.0 | \n",
- " NaN | \n",
- " 43.0 | \n",
- " 80.0 | \n",
- "
\n",
- " \n",
- " 172 | \n",
- " 51.0 | \n",
- " NaN | \n",
- " 68.0 | \n",
- " 34.0 | \n",
- " 74.0 | \n",
- "
\n",
- " \n",
- " 173 | \n",
- " 149.0 | \n",
- " NaN | \n",
- " 18.0 | \n",
- " 141.0 | \n",
- " NaN | \n",
- "
\n",
- " \n",
- " 174 | \n",
- " 8.0 | \n",
- " 139.0 | \n",
- " 146.0 | \n",
- " 112.0 | \n",
- " NaN | \n",
- "
\n",
- " \n",
- " 175 | \n",
- " 115.0 | \n",
- " NaN | \n",
- " 64.0 | \n",
- " 62.0 | \n",
- " 9.0 | \n",
- "
\n",
- " \n",
- " 176 | \n",
- " NaN | \n",
- " 7.0 | \n",
- " 140.0 | \n",
- " 45.0 | \n",
- " 148.0 | \n",
- "
\n",
- " \n",
- " 177 | \n",
- " NaN | \n",
- " 43.0 | \n",
- " 68.0 | \n",
- " 109.0 | \n",
- " 18.0 | \n",
- "
\n",
- " \n",
- " 178 | \n",
- " 31.0 | \n",
- " 100.0 | \n",
- " NaN | \n",
- " 49.0 | \n",
- " 123.0 | \n",
- "
\n",
- " \n",
- " 179 | \n",
- " 29.0 | \n",
- " 46.0 | \n",
- " 69.0 | \n",
- " 57.0 | \n",
- " 90.0 | \n",
- "
\n",
- " \n",
- " 180 | \n",
- " 146.0 | \n",
- " 86.0 | \n",
- " 18.0 | \n",
- " 22.0 | \n",
- " 46.0 | \n",
- "
\n",
- " \n",
- " 181 | \n",
- " 71.0 | \n",
- " 50.0 | \n",
- " 40.0 | \n",
- " NaN | \n",
- " 140.0 | \n",
- "
\n",
- " \n",
- " 182 | \n",
- " 4.0 | \n",
- " 100.0 | \n",
- " 147.0 | \n",
- " 116.0 | \n",
- " 110.0 | \n",
- "
\n",
- " \n",
- " 183 | \n",
- " 55.0 | \n",
- " 87.0 | \n",
- " 93.0 | \n",
- " NaN | \n",
- " 34.0 | \n",
- "
\n",
- " \n",
- " 184 | \n",
- " NaN | \n",
- " 109.0 | \n",
- " 124.0 | \n",
- " 87.0 | \n",
- " 82.0 | \n",
- "
\n",
- " \n",
- " 185 | \n",
- " 10.0 | \n",
- " 118.0 | \n",
- " 139.0 | \n",
- " 50.0 | \n",
- " 51.0 | \n",
- "
\n",
- " \n",
- " 186 | \n",
- " 32.0 | \n",
- " 12.0 | \n",
- " 71.0 | \n",
- " 36.0 | \n",
- " NaN | \n",
- "
\n",
- " \n",
- " 187 | \n",
- " 94.0 | \n",
- " NaN | \n",
- " 138.0 | \n",
- " 13.0 | \n",
- " 149.0 | \n",
- "
\n",
- " \n",
- " 188 | \n",
- " 65.0 | \n",
- " 101.0 | \n",
- " 123.0 | \n",
- " 128.0 | \n",
- " 86.0 | \n",
- "
\n",
- " \n",
- " 189 | \n",
- " 43.0 | \n",
- " 94.0 | \n",
- " NaN | \n",
- " 29.0 | \n",
- " 132.0 | \n",
- "
\n",
- " \n",
- " 190 | \n",
- " 68.0 | \n",
- " 135.0 | \n",
- " 94.0 | \n",
- " 28.0 | \n",
- " 125.0 | \n",
- "
\n",
- " \n",
- " 191 | \n",
- " 30.0 | \n",
- " 60.0 | \n",
- " 98.0 | \n",
- " NaN | \n",
- " 15.0 | \n",
- "
\n",
- " \n",
- " 192 | \n",
- " 89.0 | \n",
- " 16.0 | \n",
- " 10.0 | \n",
- " 135.0 | \n",
- " 4.0 | \n",
- "
\n",
- " \n",
- " 193 | \n",
- " 104.0 | \n",
- " 139.0 | \n",
- " 97.0 | \n",
- " 29.0 | \n",
- " 17.0 | \n",
- "
\n",
- " \n",
- " 194 | \n",
- " 5.0 | \n",
- " 29.0 | \n",
- " 41.0 | \n",
- " 99.0 | \n",
- " NaN | \n",
- "
\n",
- " \n",
- " 195 | \n",
- " 19.0 | \n",
- " 102.0 | \n",
- " 135.0 | \n",
- " 41.0 | \n",
- " 40.0 | \n",
- "
\n",
- " \n",
- " 196 | \n",
- " 58.0 | \n",
- " NaN | \n",
- " 70.0 | \n",
- " 82.0 | \n",
- " 64.0 | \n",
- "
\n",
- " \n",
- " 197 | \n",
- " NaN | \n",
- " 97.0 | \n",
- " 129.0 | \n",
- " 76.0 | \n",
- " 13.0 | \n",
- "
\n",
- " \n",
- " 198 | \n",
- " 131.0 | \n",
- " 15.0 | \n",
- " NaN | \n",
- " 44.0 | \n",
- " 114.0 | \n",
- "
\n",
- " \n",
- " 199 | \n",
- " 79.0 | \n",
- " NaN | \n",
- " 95.0 | \n",
- " 128.0 | \n",
- " NaN | \n",
- "
\n",
- " \n",
- "
\n",
- "
100 rows × 5 columns
\n",
- "
"
- ],
- "text/plain": [
- " Python En Math Physic Chem\n",
- "100 122.0 10.0 5.0 28.0 57.0\n",
- "101 NaN 129.0 16.0 114.0 26.0\n",
- "102 97.0 121.0 122.0 29.0 65.0\n",
- "103 141.0 73.0 120.0 147.0 1.0\n",
- "104 126.0 NaN 86.0 116.0 17.0\n",
- "105 85.0 NaN 42.0 121.0 66.0\n",
- "106 142.0 65.0 1.0 124.0 83.0\n",
- "107 136.0 141.0 NaN 86.0 113.0\n",
- "108 15.0 37.0 124.0 110.0 102.0\n",
- "109 63.0 30.0 NaN 69.0 58.0\n",
- "110 NaN NaN 113.0 109.0 16.0\n",
- "111 5.0 51.0 87.0 58.0 126.0\n",
- "112 53.0 97.0 76.0 37.0 45.0\n",
- "113 42.0 148.0 NaN 97.0 NaN\n",
- "114 70.0 138.0 69.0 68.0 134.0\n",
- "115 NaN 136.0 113.0 22.0 94.0\n",
- "116 31.0 137.0 6.0 20.0 28.0\n",
- "117 148.0 74.0 134.0 4.0 124.0\n",
- "118 102.0 81.0 138.0 128.0 32.0\n",
- "119 27.0 111.0 13.0 NaN 22.0\n",
- "120 28.0 93.0 121.0 NaN 4.0\n",
- "121 136.0 NaN 25.0 97.0 19.0\n",
- "122 111.0 70.0 12.0 38.0 58.0\n",
- "123 NaN 103.0 147.0 86.0 8.0\n",
- "124 10.0 10.0 46.0 63.0 149.0\n",
- "125 7.0 75.0 97.0 108.0 31.0\n",
- "126 88.0 6.0 NaN NaN 55.0\n",
- "127 33.0 74.0 106.0 50.0 46.0\n",
- "128 74.0 28.0 26.0 100.0 76.0\n",
- "129 76.0 18.0 101.0 NaN NaN\n",
- ".. ... ... ... ... ...\n",
- "170 144.0 124.0 77.0 92.0 82.0\n",
- "171 36.0 98.0 NaN 43.0 80.0\n",
- "172 51.0 NaN 68.0 34.0 74.0\n",
- "173 149.0 NaN 18.0 141.0 NaN\n",
- "174 8.0 139.0 146.0 112.0 NaN\n",
- "175 115.0 NaN 64.0 62.0 9.0\n",
- "176 NaN 7.0 140.0 45.0 148.0\n",
- "177 NaN 43.0 68.0 109.0 18.0\n",
- "178 31.0 100.0 NaN 49.0 123.0\n",
- "179 29.0 46.0 69.0 57.0 90.0\n",
- "180 146.0 86.0 18.0 22.0 46.0\n",
- "181 71.0 50.0 40.0 NaN 140.0\n",
- "182 4.0 100.0 147.0 116.0 110.0\n",
- "183 55.0 87.0 93.0 NaN 34.0\n",
- "184 NaN 109.0 124.0 87.0 82.0\n",
- "185 10.0 118.0 139.0 50.0 51.0\n",
- "186 32.0 12.0 71.0 36.0 NaN\n",
- "187 94.0 NaN 138.0 13.0 149.0\n",
- "188 65.0 101.0 123.0 128.0 86.0\n",
- "189 43.0 94.0 NaN 29.0 132.0\n",
- "190 68.0 135.0 94.0 28.0 125.0\n",
- "191 30.0 60.0 98.0 NaN 15.0\n",
- "192 89.0 16.0 10.0 135.0 4.0\n",
- "193 104.0 139.0 97.0 29.0 17.0\n",
- "194 5.0 29.0 41.0 99.0 NaN\n",
- "195 19.0 102.0 135.0 41.0 40.0\n",
- "196 58.0 NaN 70.0 82.0 64.0\n",
- "197 NaN 97.0 129.0 76.0 13.0\n",
- "198 131.0 15.0 NaN 44.0 114.0\n",
- "199 79.0 NaN 95.0 128.0 NaN\n",
- "\n",
- "[100 rows x 5 columns]"
- ]
- },
- "execution_count": 37,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
"source": [
"# 众数填充,数量最多的那个数\n",
"df2"
@@ -3971,605 +233,9 @@
},
{
"cell_type": "code",
- "execution_count": 42,
- "metadata": {
- "collapsed": true
- },
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " Python | \n",
- " En | \n",
- " Math | \n",
- " Physic | \n",
- " Chem | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " 100 | \n",
- " 82 | \n",
- " 89 | \n",
- " 99 | \n",
- " 101 | \n",
- " 125 | \n",
- "
\n",
- " \n",
- " 101 | \n",
- " 4 | \n",
- " 31 | \n",
- " 109 | \n",
- " 32 | \n",
- " 5 | \n",
- "
\n",
- " \n",
- " 102 | \n",
- " 56 | \n",
- " 103 | \n",
- " 56 | \n",
- " 61 | \n",
- " 90 | \n",
- "
\n",
- " \n",
- " 103 | \n",
- " 47 | \n",
- " 100 | \n",
- " 147 | \n",
- " 138 | \n",
- " 99 | \n",
- "
\n",
- " \n",
- " 104 | \n",
- " 38 | \n",
- " 46 | \n",
- " 82 | \n",
- " 75 | \n",
- " 44 | \n",
- "
\n",
- " \n",
- " 105 | \n",
- " 18 | \n",
- " 11 | \n",
- " 122 | \n",
- " 3 | \n",
- " 126 | \n",
- "
\n",
- " \n",
- " 106 | \n",
- " 56 | \n",
- " 26 | \n",
- " 106 | \n",
- " 14 | \n",
- " 139 | \n",
- "
\n",
- " \n",
- " 107 | \n",
- " 3 | \n",
- " 137 | \n",
- " 75 | \n",
- " 67 | \n",
- " 144 | \n",
- "
\n",
- " \n",
- " 108 | \n",
- " 35 | \n",
- " 47 | \n",
- " 102 | \n",
- " 60 | \n",
- " 63 | \n",
- "
\n",
- " \n",
- " 109 | \n",
- " 86 | \n",
- " 126 | \n",
- " 57 | \n",
- " 88 | \n",
- " 149 | \n",
- "
\n",
- " \n",
- " 110 | \n",
- " 19 | \n",
- " 140 | \n",
- " 30 | \n",
- " 35 | \n",
- " 33 | \n",
- "
\n",
- " \n",
- " 111 | \n",
- " 76 | \n",
- " 1 | \n",
- " 5 | \n",
- " 11 | \n",
- " 33 | \n",
- "
\n",
- " \n",
- " 112 | \n",
- " 31 | \n",
- " 54 | \n",
- " 91 | \n",
- " 119 | \n",
- " 69 | \n",
- "
\n",
- " \n",
- " 113 | \n",
- " 64 | \n",
- " 37 | \n",
- " 50 | \n",
- " 23 | \n",
- " 21 | \n",
- "
\n",
- " \n",
- " 114 | \n",
- " 72 | \n",
- " 57 | \n",
- " 138 | \n",
- " 15 | \n",
- " 21 | \n",
- "
\n",
- " \n",
- " 115 | \n",
- " 55 | \n",
- " 120 | \n",
- " 104 | \n",
- " 32 | \n",
- " 25 | \n",
- "
\n",
- " \n",
- " 116 | \n",
- " 96 | \n",
- " 24 | \n",
- " 89 | \n",
- " 22 | \n",
- " 146 | \n",
- "
\n",
- " \n",
- " 117 | \n",
- " 63 | \n",
- " 0 | \n",
- " 8 | \n",
- " 64 | \n",
- " 89 | \n",
- "
\n",
- " \n",
- " 118 | \n",
- " 28 | \n",
- " 46 | \n",
- " 125 | \n",
- " 82 | \n",
- " 74 | \n",
- "
\n",
- " \n",
- " 119 | \n",
- " 85 | \n",
- " 39 | \n",
- " 70 | \n",
- " 132 | \n",
- " 111 | \n",
- "
\n",
- " \n",
- " 120 | \n",
- " 109 | \n",
- " 90 | \n",
- " 44 | \n",
- " 74 | \n",
- " 39 | \n",
- "
\n",
- " \n",
- " 121 | \n",
- " 2 | \n",
- " 148 | \n",
- " 103 | \n",
- " 114 | \n",
- " 65 | \n",
- "
\n",
- " \n",
- " 122 | \n",
- " 110 | \n",
- " 29 | \n",
- " 99 | \n",
- " 80 | \n",
- " 57 | \n",
- "
\n",
- " \n",
- " 123 | \n",
- " 109 | \n",
- " 88 | \n",
- " 81 | \n",
- " 135 | \n",
- " 71 | \n",
- "
\n",
- " \n",
- " 124 | \n",
- " 70 | \n",
- " 103 | \n",
- " 134 | \n",
- " 121 | \n",
- " 121 | \n",
- "
\n",
- " \n",
- " 125 | \n",
- " 51 | \n",
- " 92 | \n",
- " 117 | \n",
- " 27 | \n",
- " 43 | \n",
- "
\n",
- " \n",
- " 126 | \n",
- " 6 | \n",
- " 92 | \n",
- " 97 | \n",
- " 59 | \n",
- " 105 | \n",
- "
\n",
- " \n",
- " 127 | \n",
- " 65 | \n",
- " 90 | \n",
- " 52 | \n",
- " 148 | \n",
- " 22 | \n",
- "
\n",
- " \n",
- " 128 | \n",
- " 4 | \n",
- " 129 | \n",
- " 17 | \n",
- " 119 | \n",
- " 13 | \n",
- "
\n",
- " \n",
- " 129 | \n",
- " 24 | \n",
- " 100 | \n",
- " 107 | \n",
- " 28 | \n",
- " 139 | \n",
- "
\n",
- " \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- "
\n",
- " \n",
- " 2070 | \n",
- " 127 | \n",
- " 77 | \n",
- " 24 | \n",
- " 16 | \n",
- " 31 | \n",
- "
\n",
- " \n",
- " 2071 | \n",
- " 93 | \n",
- " 61 | \n",
- " 9 | \n",
- " 28 | \n",
- " 22 | \n",
- "
\n",
- " \n",
- " 2072 | \n",
- " 116 | \n",
- " 61 | \n",
- " 54 | \n",
- " 8 | \n",
- " 61 | \n",
- "
\n",
- " \n",
- " 2073 | \n",
- " 4 | \n",
- " 72 | \n",
- " 140 | \n",
- " 112 | \n",
- " 34 | \n",
- "
\n",
- " \n",
- " 2074 | \n",
- " 26 | \n",
- " 108 | \n",
- " 123 | \n",
- " 32 | \n",
- " 33 | \n",
- "
\n",
- " \n",
- " 2075 | \n",
- " 46 | \n",
- " 130 | \n",
- " 135 | \n",
- " 124 | \n",
- " 113 | \n",
- "
\n",
- " \n",
- " 2076 | \n",
- " 33 | \n",
- " 18 | \n",
- " 136 | \n",
- " 38 | \n",
- " 20 | \n",
- "
\n",
- " \n",
- " 2077 | \n",
- " 107 | \n",
- " 11 | \n",
- " 129 | \n",
- " 54 | \n",
- " 119 | \n",
- "
\n",
- " \n",
- " 2078 | \n",
- " 84 | \n",
- " 55 | \n",
- " 129 | \n",
- " 37 | \n",
- " 87 | \n",
- "
\n",
- " \n",
- " 2079 | \n",
- " 95 | \n",
- " 50 | \n",
- " 45 | \n",
- " 19 | \n",
- " 84 | \n",
- "
\n",
- " \n",
- " 2080 | \n",
- " 124 | \n",
- " 74 | \n",
- " 65 | \n",
- " 140 | \n",
- " 53 | \n",
- "
\n",
- " \n",
- " 2081 | \n",
- " 26 | \n",
- " 35 | \n",
- " 149 | \n",
- " 145 | \n",
- " 127 | \n",
- "
\n",
- " \n",
- " 2082 | \n",
- " 19 | \n",
- " 21 | \n",
- " 101 | \n",
- " 3 | \n",
- " 89 | \n",
- "
\n",
- " \n",
- " 2083 | \n",
- " 84 | \n",
- " 10 | \n",
- " 131 | \n",
- " 71 | \n",
- " 4 | \n",
- "
\n",
- " \n",
- " 2084 | \n",
- " 28 | \n",
- " 74 | \n",
- " 105 | \n",
- " 68 | \n",
- " 89 | \n",
- "
\n",
- " \n",
- " 2085 | \n",
- " 23 | \n",
- " 93 | \n",
- " 84 | \n",
- " 97 | \n",
- " 88 | \n",
- "
\n",
- " \n",
- " 2086 | \n",
- " 86 | \n",
- " 133 | \n",
- " 26 | \n",
- " 125 | \n",
- " 13 | \n",
- "
\n",
- " \n",
- " 2087 | \n",
- " 21 | \n",
- " 124 | \n",
- " 40 | \n",
- " 115 | \n",
- " 5 | \n",
- "
\n",
- " \n",
- " 2088 | \n",
- " 20 | \n",
- " 15 | \n",
- " 35 | \n",
- " 31 | \n",
- " 37 | \n",
- "
\n",
- " \n",
- " 2089 | \n",
- " 96 | \n",
- " 123 | \n",
- " 123 | \n",
- " 5 | \n",
- " 64 | \n",
- "
\n",
- " \n",
- " 2090 | \n",
- " 22 | \n",
- " 43 | \n",
- " 92 | \n",
- " 78 | \n",
- " 60 | \n",
- "
\n",
- " \n",
- " 2091 | \n",
- " 16 | \n",
- " 31 | \n",
- " 17 | \n",
- " 60 | \n",
- " 58 | \n",
- "
\n",
- " \n",
- " 2092 | \n",
- " 65 | \n",
- " 18 | \n",
- " 13 | \n",
- " 13 | \n",
- " 34 | \n",
- "
\n",
- " \n",
- " 2093 | \n",
- " 69 | \n",
- " 49 | \n",
- " 109 | \n",
- " 40 | \n",
- " 58 | \n",
- "
\n",
- " \n",
- " 2094 | \n",
- " 128 | \n",
- " 46 | \n",
- " 10 | \n",
- " 82 | \n",
- " 111 | \n",
- "
\n",
- " \n",
- " 2095 | \n",
- " 26 | \n",
- " 59 | \n",
- " 8 | \n",
- " 54 | \n",
- " 149 | \n",
- "
\n",
- " \n",
- " 2096 | \n",
- " 111 | \n",
- " 47 | \n",
- " 90 | \n",
- " 92 | \n",
- " 66 | \n",
- "
\n",
- " \n",
- " 2097 | \n",
- " 5 | \n",
- " 97 | \n",
- " 73 | \n",
- " 140 | \n",
- " 104 | \n",
- "
\n",
- " \n",
- " 2098 | \n",
- " 102 | \n",
- " 6 | \n",
- " 7 | \n",
- " 5 | \n",
- " 119 | \n",
- "
\n",
- " \n",
- " 2099 | \n",
- " 97 | \n",
- " 19 | \n",
- " 77 | \n",
- " 143 | \n",
- " 48 | \n",
- "
\n",
- " \n",
- "
\n",
- "
2000 rows × 5 columns
\n",
- "
"
- ],
- "text/plain": [
- " Python En Math Physic Chem\n",
- "100 82 89 99 101 125\n",
- "101 4 31 109 32 5\n",
- "102 56 103 56 61 90\n",
- "103 47 100 147 138 99\n",
- "104 38 46 82 75 44\n",
- "105 18 11 122 3 126\n",
- "106 56 26 106 14 139\n",
- "107 3 137 75 67 144\n",
- "108 35 47 102 60 63\n",
- "109 86 126 57 88 149\n",
- "110 19 140 30 35 33\n",
- "111 76 1 5 11 33\n",
- "112 31 54 91 119 69\n",
- "113 64 37 50 23 21\n",
- "114 72 57 138 15 21\n",
- "115 55 120 104 32 25\n",
- "116 96 24 89 22 146\n",
- "117 63 0 8 64 89\n",
- "118 28 46 125 82 74\n",
- "119 85 39 70 132 111\n",
- "120 109 90 44 74 39\n",
- "121 2 148 103 114 65\n",
- "122 110 29 99 80 57\n",
- "123 109 88 81 135 71\n",
- "124 70 103 134 121 121\n",
- "125 51 92 117 27 43\n",
- "126 6 92 97 59 105\n",
- "127 65 90 52 148 22\n",
- "128 4 129 17 119 13\n",
- "129 24 100 107 28 139\n",
- "... ... ... ... ... ...\n",
- "2070 127 77 24 16 31\n",
- "2071 93 61 9 28 22\n",
- "2072 116 61 54 8 61\n",
- "2073 4 72 140 112 34\n",
- "2074 26 108 123 32 33\n",
- "2075 46 130 135 124 113\n",
- "2076 33 18 136 38 20\n",
- "2077 107 11 129 54 119\n",
- "2078 84 55 129 37 87\n",
- "2079 95 50 45 19 84\n",
- "2080 124 74 65 140 53\n",
- "2081 26 35 149 145 127\n",
- "2082 19 21 101 3 89\n",
- "2083 84 10 131 71 4\n",
- "2084 28 74 105 68 89\n",
- "2085 23 93 84 97 88\n",
- "2086 86 133 26 125 13\n",
- "2087 21 124 40 115 5\n",
- "2088 20 15 35 31 37\n",
- "2089 96 123 123 5 64\n",
- "2090 22 43 92 78 60\n",
- "2091 16 31 17 60 58\n",
- "2092 65 18 13 13 34\n",
- "2093 69 49 109 40 58\n",
- "2094 128 46 10 82 111\n",
- "2095 26 59 8 54 149\n",
- "2096 111 47 90 92 66\n",
- "2097 5 97 73 140 104\n",
- "2098 102 6 7 5 119\n",
- "2099 97 19 77 143 48\n",
- "\n",
- "[2000 rows x 5 columns]"
- ]
- },
- "execution_count": 42,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
"source": [
"df = DataFrame(np.random.randint(0,150,size = (2000,5)),index = np.arange(100,2100),columns=['Python','En','Math','Physic','Chem'])\n",
"df"
@@ -4577,7 +243,7 @@
},
{
"cell_type": "code",
- "execution_count": 43,
+ "execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@@ -4595,258 +261,36 @@
},
{
"cell_type": "code",
- "execution_count": 44,
- "metadata": {
- "collapsed": true
- },
- "outputs": [
- {
- "data": {
- "text/plain": [
- "Python 190\n",
- "En 200\n",
- "Math 194\n",
- "Physic 189\n",
- "Chem 181\n",
- "dtype: int64"
- ]
- },
- "execution_count": 44,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
"source": [
"df.isnull().sum()"
]
},
{
"cell_type": "code",
- "execution_count": 45,
- "metadata": {
- "collapsed": true
- },
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " Python | \n",
- " En | \n",
- " Math | \n",
- " Physic | \n",
- " Chem | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " 100 | \n",
- " 82.0 | \n",
- " 89.0 | \n",
- " 99.0 | \n",
- " 101.0 | \n",
- " 125.0 | \n",
- "
\n",
- " \n",
- " 101 | \n",
- " 4.0 | \n",
- " 31.0 | \n",
- " 109.0 | \n",
- " 32.0 | \n",
- " 5.0 | \n",
- "
\n",
- " \n",
- " 102 | \n",
- " 56.0 | \n",
- " 103.0 | \n",
- " 56.0 | \n",
- " NaN | \n",
- " 90.0 | \n",
- "
\n",
- " \n",
- " 103 | \n",
- " 47.0 | \n",
- " 100.0 | \n",
- " 147.0 | \n",
- " 138.0 | \n",
- " 99.0 | \n",
- "
\n",
- " \n",
- " 104 | \n",
- " 38.0 | \n",
- " 46.0 | \n",
- " NaN | \n",
- " 75.0 | \n",
- " 44.0 | \n",
- "
\n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- " Python En Math Physic Chem\n",
- "100 82.0 89.0 99.0 101.0 125.0\n",
- "101 4.0 31.0 109.0 32.0 5.0\n",
- "102 56.0 103.0 56.0 NaN 90.0\n",
- "103 47.0 100.0 147.0 138.0 99.0\n",
- "104 38.0 46.0 NaN 75.0 44.0"
- ]
- },
- "execution_count": 45,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
"source": [
"df.head()"
]
},
{
"cell_type": "code",
- "execution_count": 46,
- "metadata": {
- "collapsed": true
- },
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " Python | \n",
- " En | \n",
- " Math | \n",
- " Physic | \n",
- " Chem | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " 2095 | \n",
- " 26.0 | \n",
- " 59.0 | \n",
- " 8.0 | \n",
- " 54.0 | \n",
- " 149.0 | \n",
- "
\n",
- " \n",
- " 2096 | \n",
- " NaN | \n",
- " 47.0 | \n",
- " 90.0 | \n",
- " 92.0 | \n",
- " 66.0 | \n",
- "
\n",
- " \n",
- " 2097 | \n",
- " 5.0 | \n",
- " 97.0 | \n",
- " 73.0 | \n",
- " 140.0 | \n",
- " 104.0 | \n",
- "
\n",
- " \n",
- " 2098 | \n",
- " 102.0 | \n",
- " 6.0 | \n",
- " 7.0 | \n",
- " 5.0 | \n",
- " 119.0 | \n",
- "
\n",
- " \n",
- " 2099 | \n",
- " 97.0 | \n",
- " 19.0 | \n",
- " 77.0 | \n",
- " NaN | \n",
- " 48.0 | \n",
- "
\n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- " Python En Math Physic Chem\n",
- "2095 26.0 59.0 8.0 54.0 149.0\n",
- "2096 NaN 47.0 90.0 92.0 66.0\n",
- "2097 5.0 97.0 73.0 140.0 104.0\n",
- "2098 102.0 6.0 7.0 5.0 119.0\n",
- "2099 97.0 19.0 77.0 NaN 48.0"
- ]
- },
- "execution_count": 46,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
"source": [
"df.tail()"
]
},
{
"cell_type": "code",
- "execution_count": 48,
- "metadata": {
- "collapsed": true
- },
- "outputs": [
- {
- "data": {
- "text/plain": [
- "array([ 82., 4., 56., 47., 38., 18., 3., 35., 86., 19., 76.,\n",
- " 31., 64., 72., 55., 96., 63., 28., 85., 109., 2., 110.,\n",
- " 70., 51., 6., 65., 24., 48., 44., 11., 114., 129., 87.,\n",
- " 108., 125., nan, 140., 132., 91., 34., 54., 30., 12., 98.,\n",
- " 142., 79., 13., 77., 40., 139., 39., 81., 112., 36., 22.,\n",
- " 5., 120., 17., 127., 119., 59., 146., 89., 103., 8., 97.,\n",
- " 130., 73., 83., 122., 95., 100., 41., 21., 136., 80., 101.,\n",
- " 50., 27., 71., 16., 141., 126., 102., 145., 15., 52., 94.,\n",
- " 10., 33., 137., 9., 128., 88., 26., 84., 93., 1., 7.,\n",
- " 131., 107., 148., 0., 105., 66., 32., 115., 118., 58., 53.,\n",
- " 29., 42., 57., 62., 25., 60., 69., 133., 68., 20., 106.,\n",
- " 147., 78., 90., 124., 149., 92., 75., 117., 143., 99., 37.,\n",
- " 123., 45., 61., 121., 135., 138., 116., 14., 104., 74., 46.,\n",
- " 111., 23., 43., 49., 144., 113., 67., 134.])"
- ]
- },
- "execution_count": 48,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
"source": [
"# 去重之后的数据\n",
"df['Python'].unique()"
@@ -4854,166 +298,18 @@
},
{
"cell_type": "code",
- "execution_count": 49,
- "metadata": {
- "collapsed": true
- },
- "outputs": [
- {
- "data": {
- "text/plain": [
- "143.0 20\n",
- "136.0 20\n",
- "102.0 19\n",
- "105.0 19\n",
- "26.0 19\n",
- "69.0 19\n",
- "31.0 18\n",
- "148.0 18\n",
- "75.0 18\n",
- "139.0 18\n",
- "1.0 18\n",
- "35.0 17\n",
- "140.0 17\n",
- "110.0 17\n",
- "125.0 17\n",
- "146.0 17\n",
- "141.0 17\n",
- "64.0 16\n",
- "30.0 16\n",
- "79.0 16\n",
- "73.0 16\n",
- "40.0 16\n",
- "10.0 15\n",
- "6.0 15\n",
- "65.0 15\n",
- "81.0 15\n",
- "28.0 15\n",
- "48.0 15\n",
- "92.0 15\n",
- "103.0 15\n",
- " ..\n",
- "104.0 9\n",
- "12.0 9\n",
- "116.0 9\n",
- "13.0 9\n",
- "59.0 9\n",
- "93.0 9\n",
- "124.0 9\n",
- "85.0 8\n",
- "135.0 8\n",
- "131.0 8\n",
- "68.0 8\n",
- "66.0 8\n",
- "62.0 8\n",
- "120.0 8\n",
- "17.0 8\n",
- "25.0 8\n",
- "145.0 7\n",
- "58.0 7\n",
- "134.0 7\n",
- "113.0 7\n",
- "123.0 7\n",
- "39.0 7\n",
- "34.0 7\n",
- "43.0 7\n",
- "74.0 6\n",
- "144.0 6\n",
- "132.0 6\n",
- "142.0 5\n",
- "67.0 5\n",
- "49.0 5\n",
- "Name: Python, Length: 150, dtype: int64"
- ]
- },
- "execution_count": 49,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
"source": [
"df['Python'].value_counts()"
]
},
{
"cell_type": "code",
- "execution_count": 53,
- "metadata": {
- "collapsed": true
- },
- "outputs": [
- {
- "data": {
- "text/plain": [
- "8.0 21\n",
- "96.0 19\n",
- "118.0 19\n",
- "24.0 19\n",
- "43.0 19\n",
- "27.0 19\n",
- "19.0 19\n",
- "41.0 18\n",
- "0.0 18\n",
- "3.0 18\n",
- "52.0 18\n",
- "4.0 17\n",
- "137.0 17\n",
- "1.0 17\n",
- "101.0 17\n",
- "51.0 17\n",
- "39.0 17\n",
- "100.0 17\n",
- "127.0 17\n",
- "115.0 16\n",
- "33.0 16\n",
- "112.0 16\n",
- "92.0 16\n",
- "126.0 16\n",
- "133.0 15\n",
- "32.0 15\n",
- "89.0 15\n",
- "95.0 15\n",
- "36.0 15\n",
- "93.0 15\n",
- " ..\n",
- "12.0 9\n",
- "28.0 9\n",
- "106.0 9\n",
- "45.0 9\n",
- "80.0 9\n",
- "84.0 9\n",
- "58.0 9\n",
- "79.0 9\n",
- "71.0 9\n",
- "83.0 9\n",
- "142.0 9\n",
- "7.0 9\n",
- "6.0 8\n",
- "61.0 8\n",
- "149.0 8\n",
- "34.0 8\n",
- "20.0 8\n",
- "38.0 8\n",
- "130.0 8\n",
- "104.0 7\n",
- "120.0 7\n",
- "56.0 7\n",
- "146.0 7\n",
- "98.0 7\n",
- "134.0 6\n",
- "123.0 6\n",
- "35.0 6\n",
- "87.0 5\n",
- "42.0 5\n",
- "119.0 4\n",
- "Name: En, Length: 150, dtype: int64"
- ]
- },
- "execution_count": 53,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
"source": [
"en = df['En'].value_counts()\n",
"en"
@@ -5021,44 +317,20 @@
},
{
"cell_type": "code",
- "execution_count": 54,
+ "execution_count": null,
"metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "8.0"
- ]
- },
- "execution_count": 54,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "outputs": [],
"source": [
"en.index[0]"
]
},
{
"cell_type": "code",
- "execution_count": 52,
+ "execution_count": null,
"metadata": {
"scrolled": true
},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Python 75.0\n",
- "En 74.0\n",
- "Math 77.5\n",
- "Physic 73.0\n",
- "Chem 72.0\n",
- "dtype: float64 \n"
- ]
- }
- ],
+ "outputs": [],
"source": [
"s = df.median()\n",
"print(s,type(s))"
@@ -5066,7 +338,7 @@
},
{
"cell_type": "code",
- "execution_count": 55,
+ "execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@@ -5077,25 +349,9 @@
},
{
"cell_type": "code",
- "execution_count": 57,
+ "execution_count": null,
"metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "Python 143.0\n",
- "En 8.0\n",
- "Math 80.0\n",
- "Physic 31.0\n",
- "Chem 125.0\n",
- "dtype: float64"
- ]
- },
- "execution_count": 57,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "outputs": [],
"source": [
"s = Series(zhongshu,index = df.columns)\n",
"s"
@@ -5103,605 +359,9 @@
},
{
"cell_type": "code",
- "execution_count": 60,
- "metadata": {
- "collapsed": true
- },
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " Python | \n",
- " En | \n",
- " Math | \n",
- " Physic | \n",
- " Chem | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " 100 | \n",
- " 82.0 | \n",
- " 89.0 | \n",
- " 99.0 | \n",
- " 101.0 | \n",
- " 125.0 | \n",
- "
\n",
- " \n",
- " 101 | \n",
- " 4.0 | \n",
- " 31.0 | \n",
- " 109.0 | \n",
- " 32.0 | \n",
- " 5.0 | \n",
- "
\n",
- " \n",
- " 102 | \n",
- " 56.0 | \n",
- " 103.0 | \n",
- " 56.0 | \n",
- " 31.0 | \n",
- " 90.0 | \n",
- "
\n",
- " \n",
- " 103 | \n",
- " 47.0 | \n",
- " 100.0 | \n",
- " 147.0 | \n",
- " 138.0 | \n",
- " 99.0 | \n",
- "
\n",
- " \n",
- " 104 | \n",
- " 38.0 | \n",
- " 46.0 | \n",
- " 80.0 | \n",
- " 75.0 | \n",
- " 44.0 | \n",
- "
\n",
- " \n",
- " 105 | \n",
- " 18.0 | \n",
- " 11.0 | \n",
- " 122.0 | \n",
- " 3.0 | \n",
- " 126.0 | \n",
- "
\n",
- " \n",
- " 106 | \n",
- " 56.0 | \n",
- " 26.0 | \n",
- " 106.0 | \n",
- " 14.0 | \n",
- " 139.0 | \n",
- "
\n",
- " \n",
- " 107 | \n",
- " 3.0 | \n",
- " 137.0 | \n",
- " 75.0 | \n",
- " 67.0 | \n",
- " 144.0 | \n",
- "
\n",
- " \n",
- " 108 | \n",
- " 35.0 | \n",
- " 47.0 | \n",
- " 102.0 | \n",
- " 60.0 | \n",
- " 63.0 | \n",
- "
\n",
- " \n",
- " 109 | \n",
- " 86.0 | \n",
- " 126.0 | \n",
- " 80.0 | \n",
- " 88.0 | \n",
- " 149.0 | \n",
- "
\n",
- " \n",
- " 110 | \n",
- " 19.0 | \n",
- " 140.0 | \n",
- " 80.0 | \n",
- " 35.0 | \n",
- " 33.0 | \n",
- "
\n",
- " \n",
- " 111 | \n",
- " 76.0 | \n",
- " 8.0 | \n",
- " 5.0 | \n",
- " 11.0 | \n",
- " 33.0 | \n",
- "
\n",
- " \n",
- " 112 | \n",
- " 31.0 | \n",
- " 54.0 | \n",
- " 91.0 | \n",
- " 119.0 | \n",
- " 69.0 | \n",
- "
\n",
- " \n",
- " 113 | \n",
- " 64.0 | \n",
- " 37.0 | \n",
- " 50.0 | \n",
- " 23.0 | \n",
- " 21.0 | \n",
- "
\n",
- " \n",
- " 114 | \n",
- " 72.0 | \n",
- " 57.0 | \n",
- " 138.0 | \n",
- " 15.0 | \n",
- " 21.0 | \n",
- "
\n",
- " \n",
- " 115 | \n",
- " 55.0 | \n",
- " 120.0 | \n",
- " 104.0 | \n",
- " 32.0 | \n",
- " 25.0 | \n",
- "
\n",
- " \n",
- " 116 | \n",
- " 96.0 | \n",
- " 24.0 | \n",
- " 89.0 | \n",
- " 31.0 | \n",
- " 146.0 | \n",
- "
\n",
- " \n",
- " 117 | \n",
- " 63.0 | \n",
- " 8.0 | \n",
- " 8.0 | \n",
- " 64.0 | \n",
- " 89.0 | \n",
- "
\n",
- " \n",
- " 118 | \n",
- " 28.0 | \n",
- " 8.0 | \n",
- " 125.0 | \n",
- " 82.0 | \n",
- " 74.0 | \n",
- "
\n",
- " \n",
- " 119 | \n",
- " 85.0 | \n",
- " 39.0 | \n",
- " 70.0 | \n",
- " 132.0 | \n",
- " 111.0 | \n",
- "
\n",
- " \n",
- " 120 | \n",
- " 109.0 | \n",
- " 90.0 | \n",
- " 80.0 | \n",
- " 74.0 | \n",
- " 39.0 | \n",
- "
\n",
- " \n",
- " 121 | \n",
- " 2.0 | \n",
- " 8.0 | \n",
- " 103.0 | \n",
- " 114.0 | \n",
- " 65.0 | \n",
- "
\n",
- " \n",
- " 122 | \n",
- " 110.0 | \n",
- " 29.0 | \n",
- " 99.0 | \n",
- " 80.0 | \n",
- " 57.0 | \n",
- "
\n",
- " \n",
- " 123 | \n",
- " 109.0 | \n",
- " 88.0 | \n",
- " 81.0 | \n",
- " 135.0 | \n",
- " 71.0 | \n",
- "
\n",
- " \n",
- " 124 | \n",
- " 70.0 | \n",
- " 103.0 | \n",
- " 134.0 | \n",
- " 121.0 | \n",
- " 121.0 | \n",
- "
\n",
- " \n",
- " 125 | \n",
- " 51.0 | \n",
- " 92.0 | \n",
- " 117.0 | \n",
- " 31.0 | \n",
- " 43.0 | \n",
- "
\n",
- " \n",
- " 126 | \n",
- " 6.0 | \n",
- " 92.0 | \n",
- " 97.0 | \n",
- " 59.0 | \n",
- " 105.0 | \n",
- "
\n",
- " \n",
- " 127 | \n",
- " 65.0 | \n",
- " 90.0 | \n",
- " 52.0 | \n",
- " 148.0 | \n",
- " 22.0 | \n",
- "
\n",
- " \n",
- " 128 | \n",
- " 4.0 | \n",
- " 129.0 | \n",
- " 17.0 | \n",
- " 119.0 | \n",
- " 13.0 | \n",
- "
\n",
- " \n",
- " 129 | \n",
- " 24.0 | \n",
- " 100.0 | \n",
- " 107.0 | \n",
- " 28.0 | \n",
- " 139.0 | \n",
- "
\n",
- " \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- "
\n",
- " \n",
- " 2070 | \n",
- " 127.0 | \n",
- " 77.0 | \n",
- " 24.0 | \n",
- " 16.0 | \n",
- " 125.0 | \n",
- "
\n",
- " \n",
- " 2071 | \n",
- " 93.0 | \n",
- " 61.0 | \n",
- " 9.0 | \n",
- " 28.0 | \n",
- " 22.0 | \n",
- "
\n",
- " \n",
- " 2072 | \n",
- " 116.0 | \n",
- " 61.0 | \n",
- " 54.0 | \n",
- " 8.0 | \n",
- " 61.0 | \n",
- "
\n",
- " \n",
- " 2073 | \n",
- " 4.0 | \n",
- " 72.0 | \n",
- " 140.0 | \n",
- " 31.0 | \n",
- " 34.0 | \n",
- "
\n",
- " \n",
- " 2074 | \n",
- " 143.0 | \n",
- " 108.0 | \n",
- " 123.0 | \n",
- " 32.0 | \n",
- " 33.0 | \n",
- "
\n",
- " \n",
- " 2075 | \n",
- " 46.0 | \n",
- " 8.0 | \n",
- " 135.0 | \n",
- " 124.0 | \n",
- " 113.0 | \n",
- "
\n",
- " \n",
- " 2076 | \n",
- " 143.0 | \n",
- " 18.0 | \n",
- " 136.0 | \n",
- " 38.0 | \n",
- " 125.0 | \n",
- "
\n",
- " \n",
- " 2077 | \n",
- " 143.0 | \n",
- " 11.0 | \n",
- " 129.0 | \n",
- " 54.0 | \n",
- " 119.0 | \n",
- "
\n",
- " \n",
- " 2078 | \n",
- " 84.0 | \n",
- " 55.0 | \n",
- " 129.0 | \n",
- " 37.0 | \n",
- " 87.0 | \n",
- "
\n",
- " \n",
- " 2079 | \n",
- " 95.0 | \n",
- " 50.0 | \n",
- " 45.0 | \n",
- " 19.0 | \n",
- " 84.0 | \n",
- "
\n",
- " \n",
- " 2080 | \n",
- " 124.0 | \n",
- " 74.0 | \n",
- " 65.0 | \n",
- " 31.0 | \n",
- " 53.0 | \n",
- "
\n",
- " \n",
- " 2081 | \n",
- " 26.0 | \n",
- " 35.0 | \n",
- " 149.0 | \n",
- " 145.0 | \n",
- " 127.0 | \n",
- "
\n",
- " \n",
- " 2082 | \n",
- " 19.0 | \n",
- " 21.0 | \n",
- " 101.0 | \n",
- " 3.0 | \n",
- " 89.0 | \n",
- "
\n",
- " \n",
- " 2083 | \n",
- " 84.0 | \n",
- " 8.0 | \n",
- " 131.0 | \n",
- " 71.0 | \n",
- " 4.0 | \n",
- "
\n",
- " \n",
- " 2084 | \n",
- " 28.0 | \n",
- " 74.0 | \n",
- " 105.0 | \n",
- " 68.0 | \n",
- " 89.0 | \n",
- "
\n",
- " \n",
- " 2085 | \n",
- " 23.0 | \n",
- " 93.0 | \n",
- " 84.0 | \n",
- " 97.0 | \n",
- " 88.0 | \n",
- "
\n",
- " \n",
- " 2086 | \n",
- " 86.0 | \n",
- " 133.0 | \n",
- " 26.0 | \n",
- " 125.0 | \n",
- " 13.0 | \n",
- "
\n",
- " \n",
- " 2087 | \n",
- " 21.0 | \n",
- " 124.0 | \n",
- " 40.0 | \n",
- " 31.0 | \n",
- " 5.0 | \n",
- "
\n",
- " \n",
- " 2088 | \n",
- " 20.0 | \n",
- " 15.0 | \n",
- " 35.0 | \n",
- " 31.0 | \n",
- " 37.0 | \n",
- "
\n",
- " \n",
- " 2089 | \n",
- " 96.0 | \n",
- " 123.0 | \n",
- " 123.0 | \n",
- " 5.0 | \n",
- " 64.0 | \n",
- "
\n",
- " \n",
- " 2090 | \n",
- " 22.0 | \n",
- " 43.0 | \n",
- " 92.0 | \n",
- " 78.0 | \n",
- " 60.0 | \n",
- "
\n",
- " \n",
- " 2091 | \n",
- " 16.0 | \n",
- " 31.0 | \n",
- " 17.0 | \n",
- " 60.0 | \n",
- " 58.0 | \n",
- "
\n",
- " \n",
- " 2092 | \n",
- " 65.0 | \n",
- " 18.0 | \n",
- " 13.0 | \n",
- " 13.0 | \n",
- " 34.0 | \n",
- "
\n",
- " \n",
- " 2093 | \n",
- " 69.0 | \n",
- " 49.0 | \n",
- " 109.0 | \n",
- " 40.0 | \n",
- " 58.0 | \n",
- "
\n",
- " \n",
- " 2094 | \n",
- " 128.0 | \n",
- " 46.0 | \n",
- " 10.0 | \n",
- " 82.0 | \n",
- " 111.0 | \n",
- "
\n",
- " \n",
- " 2095 | \n",
- " 26.0 | \n",
- " 59.0 | \n",
- " 8.0 | \n",
- " 54.0 | \n",
- " 149.0 | \n",
- "
\n",
- " \n",
- " 2096 | \n",
- " 143.0 | \n",
- " 47.0 | \n",
- " 90.0 | \n",
- " 92.0 | \n",
- " 66.0 | \n",
- "
\n",
- " \n",
- " 2097 | \n",
- " 5.0 | \n",
- " 97.0 | \n",
- " 73.0 | \n",
- " 140.0 | \n",
- " 104.0 | \n",
- "
\n",
- " \n",
- " 2098 | \n",
- " 102.0 | \n",
- " 6.0 | \n",
- " 7.0 | \n",
- " 5.0 | \n",
- " 119.0 | \n",
- "
\n",
- " \n",
- " 2099 | \n",
- " 97.0 | \n",
- " 19.0 | \n",
- " 77.0 | \n",
- " 31.0 | \n",
- " 48.0 | \n",
- "
\n",
- " \n",
- "
\n",
- "
2000 rows × 5 columns
\n",
- "
"
- ],
- "text/plain": [
- " Python En Math Physic Chem\n",
- "100 82.0 89.0 99.0 101.0 125.0\n",
- "101 4.0 31.0 109.0 32.0 5.0\n",
- "102 56.0 103.0 56.0 31.0 90.0\n",
- "103 47.0 100.0 147.0 138.0 99.0\n",
- "104 38.0 46.0 80.0 75.0 44.0\n",
- "105 18.0 11.0 122.0 3.0 126.0\n",
- "106 56.0 26.0 106.0 14.0 139.0\n",
- "107 3.0 137.0 75.0 67.0 144.0\n",
- "108 35.0 47.0 102.0 60.0 63.0\n",
- "109 86.0 126.0 80.0 88.0 149.0\n",
- "110 19.0 140.0 80.0 35.0 33.0\n",
- "111 76.0 8.0 5.0 11.0 33.0\n",
- "112 31.0 54.0 91.0 119.0 69.0\n",
- "113 64.0 37.0 50.0 23.0 21.0\n",
- "114 72.0 57.0 138.0 15.0 21.0\n",
- "115 55.0 120.0 104.0 32.0 25.0\n",
- "116 96.0 24.0 89.0 31.0 146.0\n",
- "117 63.0 8.0 8.0 64.0 89.0\n",
- "118 28.0 8.0 125.0 82.0 74.0\n",
- "119 85.0 39.0 70.0 132.0 111.0\n",
- "120 109.0 90.0 80.0 74.0 39.0\n",
- "121 2.0 8.0 103.0 114.0 65.0\n",
- "122 110.0 29.0 99.0 80.0 57.0\n",
- "123 109.0 88.0 81.0 135.0 71.0\n",
- "124 70.0 103.0 134.0 121.0 121.0\n",
- "125 51.0 92.0 117.0 31.0 43.0\n",
- "126 6.0 92.0 97.0 59.0 105.0\n",
- "127 65.0 90.0 52.0 148.0 22.0\n",
- "128 4.0 129.0 17.0 119.0 13.0\n",
- "129 24.0 100.0 107.0 28.0 139.0\n",
- "... ... ... ... ... ...\n",
- "2070 127.0 77.0 24.0 16.0 125.0\n",
- "2071 93.0 61.0 9.0 28.0 22.0\n",
- "2072 116.0 61.0 54.0 8.0 61.0\n",
- "2073 4.0 72.0 140.0 31.0 34.0\n",
- "2074 143.0 108.0 123.0 32.0 33.0\n",
- "2075 46.0 8.0 135.0 124.0 113.0\n",
- "2076 143.0 18.0 136.0 38.0 125.0\n",
- "2077 143.0 11.0 129.0 54.0 119.0\n",
- "2078 84.0 55.0 129.0 37.0 87.0\n",
- "2079 95.0 50.0 45.0 19.0 84.0\n",
- "2080 124.0 74.0 65.0 31.0 53.0\n",
- "2081 26.0 35.0 149.0 145.0 127.0\n",
- "2082 19.0 21.0 101.0 3.0 89.0\n",
- "2083 84.0 8.0 131.0 71.0 4.0\n",
- "2084 28.0 74.0 105.0 68.0 89.0\n",
- "2085 23.0 93.0 84.0 97.0 88.0\n",
- "2086 86.0 133.0 26.0 125.0 13.0\n",
- "2087 21.0 124.0 40.0 31.0 5.0\n",
- "2088 20.0 15.0 35.0 31.0 37.0\n",
- "2089 96.0 123.0 123.0 5.0 64.0\n",
- "2090 22.0 43.0 92.0 78.0 60.0\n",
- "2091 16.0 31.0 17.0 60.0 58.0\n",
- "2092 65.0 18.0 13.0 13.0 34.0\n",
- "2093 69.0 49.0 109.0 40.0 58.0\n",
- "2094 128.0 46.0 10.0 82.0 111.0\n",
- "2095 26.0 59.0 8.0 54.0 149.0\n",
- "2096 143.0 47.0 90.0 92.0 66.0\n",
- "2097 5.0 97.0 73.0 140.0 104.0\n",
- "2098 102.0 6.0 7.0 5.0 119.0\n",
- "2099 97.0 19.0 77.0 31.0 48.0\n",
- "\n",
- "[2000 rows x 5 columns]"
- ]
- },
- "execution_count": 60,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
"source": [
"df2 = df.fillna(s)\n",
"df2"
@@ -5709,285 +369,27 @@
},
{
"cell_type": "code",
- "execution_count": 61,
- "metadata": {
- "collapsed": true
- },
- "outputs": [
- {
- "data": {
- "text/plain": [
- "Python 0\n",
- "En 0\n",
- "Math 0\n",
- "Physic 0\n",
- "Chem 0\n",
- "dtype: int64"
- ]
- },
- "execution_count": 61,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
"source": [
"df2.isnull().sum()"
]
},
{
"cell_type": "code",
- "execution_count": 62,
- "metadata": {
- "collapsed": true
- },
- "outputs": [
- {
- "data": {
- "text/plain": [
- "Python 190\n",
- "En 200\n",
- "Math 194\n",
- "Physic 189\n",
- "Chem 181\n",
- "dtype: int64"
- ]
- },
- "execution_count": 62,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
"source": [
"df.isnull().sum()"
]
},
{
"cell_type": "code",
- "execution_count": 65,
+ "execution_count": null,
"metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " Python | \n",
- " En | \n",
- " Math | \n",
- " Physic | \n",
- " Chem | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " 100 | \n",
- " 82.0 | \n",
- " 89.0 | \n",
- " 99.0 | \n",
- " 101.0 | \n",
- " 125.0 | \n",
- "
\n",
- " \n",
- " 101 | \n",
- " 4.0 | \n",
- " 31.0 | \n",
- " 109.0 | \n",
- " 32.0 | \n",
- " 5.0 | \n",
- "
\n",
- " \n",
- " 102 | \n",
- " 56.0 | \n",
- " 103.0 | \n",
- " 56.0 | \n",
- " NaN | \n",
- " 90.0 | \n",
- "
\n",
- " \n",
- " 103 | \n",
- " 47.0 | \n",
- " 100.0 | \n",
- " 147.0 | \n",
- " 138.0 | \n",
- " 99.0 | \n",
- "
\n",
- " \n",
- " 104 | \n",
- " 38.0 | \n",
- " 46.0 | \n",
- " NaN | \n",
- " 75.0 | \n",
- " 44.0 | \n",
- "
\n",
- " \n",
- " 105 | \n",
- " 18.0 | \n",
- " 11.0 | \n",
- " 122.0 | \n",
- " 3.0 | \n",
- " 126.0 | \n",
- "
\n",
- " \n",
- " 106 | \n",
- " 56.0 | \n",
- " 26.0 | \n",
- " 106.0 | \n",
- " 14.0 | \n",
- " 139.0 | \n",
- "
\n",
- " \n",
- " 107 | \n",
- " 3.0 | \n",
- " 137.0 | \n",
- " 75.0 | \n",
- " 67.0 | \n",
- " 144.0 | \n",
- "
\n",
- " \n",
- " 108 | \n",
- " 35.0 | \n",
- " 47.0 | \n",
- " 102.0 | \n",
- " 60.0 | \n",
- " 63.0 | \n",
- "
\n",
- " \n",
- " 109 | \n",
- " 86.0 | \n",
- " 126.0 | \n",
- " NaN | \n",
- " 88.0 | \n",
- " 149.0 | \n",
- "
\n",
- " \n",
- " 110 | \n",
- " 19.0 | \n",
- " 140.0 | \n",
- " NaN | \n",
- " 35.0 | \n",
- " 33.0 | \n",
- "
\n",
- " \n",
- " 111 | \n",
- " 76.0 | \n",
- " NaN | \n",
- " 5.0 | \n",
- " 11.0 | \n",
- " 33.0 | \n",
- "
\n",
- " \n",
- " 112 | \n",
- " 31.0 | \n",
- " 54.0 | \n",
- " 91.0 | \n",
- " 119.0 | \n",
- " 69.0 | \n",
- "
\n",
- " \n",
- " 113 | \n",
- " 64.0 | \n",
- " 37.0 | \n",
- " 50.0 | \n",
- " 23.0 | \n",
- " 21.0 | \n",
- "
\n",
- " \n",
- " 114 | \n",
- " 72.0 | \n",
- " 57.0 | \n",
- " 138.0 | \n",
- " 15.0 | \n",
- " 21.0 | \n",
- "
\n",
- " \n",
- " 115 | \n",
- " 55.0 | \n",
- " 120.0 | \n",
- " 104.0 | \n",
- " 32.0 | \n",
- " 25.0 | \n",
- "
\n",
- " \n",
- " 116 | \n",
- " 96.0 | \n",
- " 24.0 | \n",
- " 89.0 | \n",
- " NaN | \n",
- " 146.0 | \n",
- "
\n",
- " \n",
- " 117 | \n",
- " 63.0 | \n",
- " NaN | \n",
- " 8.0 | \n",
- " 64.0 | \n",
- " 89.0 | \n",
- "
\n",
- " \n",
- " 118 | \n",
- " 28.0 | \n",
- " NaN | \n",
- " 125.0 | \n",
- " 82.0 | \n",
- " 74.0 | \n",
- "
\n",
- " \n",
- " 119 | \n",
- " 85.0 | \n",
- " 39.0 | \n",
- " 70.0 | \n",
- " 132.0 | \n",
- " 111.0 | \n",
- "
\n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- " Python En Math Physic Chem\n",
- "100 82.0 89.0 99.0 101.0 125.0\n",
- "101 4.0 31.0 109.0 32.0 5.0\n",
- "102 56.0 103.0 56.0 NaN 90.0\n",
- "103 47.0 100.0 147.0 138.0 99.0\n",
- "104 38.0 46.0 NaN 75.0 44.0\n",
- "105 18.0 11.0 122.0 3.0 126.0\n",
- "106 56.0 26.0 106.0 14.0 139.0\n",
- "107 3.0 137.0 75.0 67.0 144.0\n",
- "108 35.0 47.0 102.0 60.0 63.0\n",
- "109 86.0 126.0 NaN 88.0 149.0\n",
- "110 19.0 140.0 NaN 35.0 33.0\n",
- "111 76.0 NaN 5.0 11.0 33.0\n",
- "112 31.0 54.0 91.0 119.0 69.0\n",
- "113 64.0 37.0 50.0 23.0 21.0\n",
- "114 72.0 57.0 138.0 15.0 21.0\n",
- "115 55.0 120.0 104.0 32.0 25.0\n",
- "116 96.0 24.0 89.0 NaN 146.0\n",
- "117 63.0 NaN 8.0 64.0 89.0\n",
- "118 28.0 NaN 125.0 82.0 74.0\n",
- "119 85.0 39.0 70.0 132.0 111.0"
- ]
- },
- "execution_count": 65,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "outputs": [],
"source": [
"df3 = df.iloc[:20]\n",
"df3"
@@ -5995,233 +397,9 @@
},
{
"cell_type": "code",
- "execution_count": 70,
- "metadata": {
- "collapsed": true
- },
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " Python | \n",
- " En | \n",
- " Math | \n",
- " Physic | \n",
- " Chem | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " 100 | \n",
- " 82.0 | \n",
- " 89.0 | \n",
- " 99.0 | \n",
- " 101.0 | \n",
- " 125.0 | \n",
- "
\n",
- " \n",
- " 101 | \n",
- " 4.0 | \n",
- " 31.0 | \n",
- " 109.0 | \n",
- " 32.0 | \n",
- " 5.0 | \n",
- "
\n",
- " \n",
- " 102 | \n",
- " 56.0 | \n",
- " 103.0 | \n",
- " 56.0 | \n",
- " 90.0 | \n",
- " 90.0 | \n",
- "
\n",
- " \n",
- " 103 | \n",
- " 47.0 | \n",
- " 100.0 | \n",
- " 147.0 | \n",
- " 138.0 | \n",
- " 99.0 | \n",
- "
\n",
- " \n",
- " 104 | \n",
- " 38.0 | \n",
- " 46.0 | \n",
- " 75.0 | \n",
- " 75.0 | \n",
- " 44.0 | \n",
- "
\n",
- " \n",
- " 105 | \n",
- " 18.0 | \n",
- " 11.0 | \n",
- " 122.0 | \n",
- " 3.0 | \n",
- " 126.0 | \n",
- "
\n",
- " \n",
- " 106 | \n",
- " 56.0 | \n",
- " 26.0 | \n",
- " 106.0 | \n",
- " 14.0 | \n",
- " 139.0 | \n",
- "
\n",
- " \n",
- " 107 | \n",
- " 3.0 | \n",
- " 137.0 | \n",
- " 75.0 | \n",
- " 67.0 | \n",
- " 144.0 | \n",
- "
\n",
- " \n",
- " 108 | \n",
- " 35.0 | \n",
- " 47.0 | \n",
- " 102.0 | \n",
- " 60.0 | \n",
- " 63.0 | \n",
- "
\n",
- " \n",
- " 109 | \n",
- " 86.0 | \n",
- " 126.0 | \n",
- " 88.0 | \n",
- " 88.0 | \n",
- " 149.0 | \n",
- "
\n",
- " \n",
- " 110 | \n",
- " 19.0 | \n",
- " 140.0 | \n",
- " 35.0 | \n",
- " 35.0 | \n",
- " 33.0 | \n",
- "
\n",
- " \n",
- " 111 | \n",
- " 76.0 | \n",
- " 5.0 | \n",
- " 5.0 | \n",
- " 11.0 | \n",
- " 33.0 | \n",
- "
\n",
- " \n",
- " 112 | \n",
- " 31.0 | \n",
- " 54.0 | \n",
- " 91.0 | \n",
- " 119.0 | \n",
- " 69.0 | \n",
- "
\n",
- " \n",
- " 113 | \n",
- " 64.0 | \n",
- " 37.0 | \n",
- " 50.0 | \n",
- " 23.0 | \n",
- " 21.0 | \n",
- "
\n",
- " \n",
- " 114 | \n",
- " 72.0 | \n",
- " 57.0 | \n",
- " 138.0 | \n",
- " 15.0 | \n",
- " 21.0 | \n",
- "
\n",
- " \n",
- " 115 | \n",
- " 55.0 | \n",
- " 120.0 | \n",
- " 104.0 | \n",
- " 32.0 | \n",
- " 25.0 | \n",
- "
\n",
- " \n",
- " 116 | \n",
- " 96.0 | \n",
- " 24.0 | \n",
- " 89.0 | \n",
- " 146.0 | \n",
- " 146.0 | \n",
- "
\n",
- " \n",
- " 117 | \n",
- " 63.0 | \n",
- " 8.0 | \n",
- " 8.0 | \n",
- " 64.0 | \n",
- " 89.0 | \n",
- "
\n",
- " \n",
- " 118 | \n",
- " 28.0 | \n",
- " 125.0 | \n",
- " 125.0 | \n",
- " 82.0 | \n",
- " 74.0 | \n",
- "
\n",
- " \n",
- " 119 | \n",
- " 85.0 | \n",
- " 39.0 | \n",
- " 70.0 | \n",
- " 132.0 | \n",
- " 111.0 | \n",
- "
\n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- " Python En Math Physic Chem\n",
- "100 82.0 89.0 99.0 101.0 125.0\n",
- "101 4.0 31.0 109.0 32.0 5.0\n",
- "102 56.0 103.0 56.0 90.0 90.0\n",
- "103 47.0 100.0 147.0 138.0 99.0\n",
- "104 38.0 46.0 75.0 75.0 44.0\n",
- "105 18.0 11.0 122.0 3.0 126.0\n",
- "106 56.0 26.0 106.0 14.0 139.0\n",
- "107 3.0 137.0 75.0 67.0 144.0\n",
- "108 35.0 47.0 102.0 60.0 63.0\n",
- "109 86.0 126.0 88.0 88.0 149.0\n",
- "110 19.0 140.0 35.0 35.0 33.0\n",
- "111 76.0 5.0 5.0 11.0 33.0\n",
- "112 31.0 54.0 91.0 119.0 69.0\n",
- "113 64.0 37.0 50.0 23.0 21.0\n",
- "114 72.0 57.0 138.0 15.0 21.0\n",
- "115 55.0 120.0 104.0 32.0 25.0\n",
- "116 96.0 24.0 89.0 146.0 146.0\n",
- "117 63.0 8.0 8.0 64.0 89.0\n",
- "118 28.0 125.0 125.0 82.0 74.0\n",
- "119 85.0 39.0 70.0 132.0 111.0"
- ]
- },
- "execution_count": 70,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
"source": [
"'''method : {'backfill', 'bfill', 'pad', 'ffill', None}, default None\n",
" Method to use for filling holes in reindexed Series\n",
@@ -6232,20 +410,9 @@
},
{
"cell_type": "code",
- "execution_count": 71,
+ "execution_count": null,
"metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "(2000, 5)"
- ]
- },
- "execution_count": 71,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "outputs": [],
"source": [
"#数据量足够大,空数据比较少,直接删除\n",
"df.shape"
@@ -6277,7 +444,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.6.5"
+ "version": "3.7.7"
}
},
"nbformat": 4,
diff --git "a/Day76-90/code/4-pandas\345\244\232\345\261\202\347\264\242\345\274\225.ipynb" "b/Day76-90/code/4-pandas\345\244\232\345\261\202\347\264\242\345\274\225.ipynb"
index 01f9dd637..d8e0d1ee9 100644
--- "a/Day76-90/code/4-pandas\345\244\232\345\261\202\347\264\242\345\274\225.ipynb"
+++ "b/Day76-90/code/4-pandas\345\244\232\345\261\202\347\264\242\345\274\225.ipynb"
@@ -82,95 +82,21 @@
},
{
"cell_type": "code",
- "execution_count": 4,
+ "execution_count": 1,
"metadata": {
"scrolled": true
},
"outputs": [
{
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " | \n",
- " Python | \n",
- " En | \n",
- " Math | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " 张三 | \n",
- " 期中 | \n",
- " 73 | \n",
- " 5 | \n",
- " 25 | \n",
- "
\n",
- " \n",
- " 期末 | \n",
- " 37 | \n",
- " 36 | \n",
- " 56 | \n",
- "
\n",
- " \n",
- " 李四 | \n",
- " 期中 | \n",
- " 149 | \n",
- " 81 | \n",
- " 142 | \n",
- "
\n",
- " \n",
- " 期末 | \n",
- " 71 | \n",
- " 138 | \n",
- " 0 | \n",
- "
\n",
- " \n",
- " 王五 | \n",
- " 期中 | \n",
- " 11 | \n",
- " 94 | \n",
- " 103 | \n",
- "
\n",
- " \n",
- " 期末 | \n",
- " 25 | \n",
- " 121 | \n",
- " 83 | \n",
- "
\n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- " Python En Math\n",
- "张三 期中 73 5 25\n",
- " 期末 37 36 56\n",
- "李四 期中 149 81 142\n",
- " 期末 71 138 0\n",
- "王五 期中 11 94 103\n",
- " 期末 25 121 83"
- ]
- },
- "execution_count": 4,
- "metadata": {},
- "output_type": "execute_result"
+ "ename": "NameError",
+ "evalue": "name 'DataFrame' is not defined",
+ "output_type": "error",
+ "traceback": [
+ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
+ "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
+ "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mdf\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mDataFrame\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrandom\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrandint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m150\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0msize\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0;36m6\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m3\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mcolumns\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'Python'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m'En'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m'Math'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mindex\u001b[0m \u001b[0;34m=\u001b[0m\u001b[0mpd\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mMultiIndex\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfrom_product\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'张三'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m'李四'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m'王五'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'期中'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m'期末'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0mdf\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
+ "\u001b[0;31mNameError\u001b[0m: name 'DataFrame' is not defined"
+ ]
}
],
"source": [
@@ -560,7 +486,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.6.5"
+ "version": "3.7.7"
}
},
"nbformat": 4,
diff --git "a/Day76-90/code/5-pandas\345\244\232\345\261\202\347\264\242\345\274\225\350\256\241\347\256\227.ipynb" "b/Day76-90/code/5-pandas\345\244\232\345\261\202\347\264\242\345\274\225\350\256\241\347\256\227.ipynb"
index 22e1c8e38..4bcaad27c 100644
--- "a/Day76-90/code/5-pandas\345\244\232\345\261\202\347\264\242\345\274\225\350\256\241\347\256\227.ipynb"
+++ "b/Day76-90/code/5-pandas\345\244\232\345\261\202\347\264\242\345\274\225\350\256\241\347\256\227.ipynb"
@@ -992,7 +992,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.6.5"
+ "version": "3.7.7"
}
},
"nbformat": 4,
diff --git "a/Day76-90/code/6-pandas\346\225\260\346\215\256\351\233\206\346\210\220.ipynb" "b/Day76-90/code/6-pandas\346\225\260\346\215\256\351\233\206\346\210\220.ipynb"
index e128ee4a1..7df4f33a7 100644
--- "a/Day76-90/code/6-pandas\346\225\260\346\215\256\351\233\206\346\210\220.ipynb"
+++ "b/Day76-90/code/6-pandas\346\225\260\346\215\256\351\233\206\346\210\220.ipynb"
@@ -1201,7 +1201,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.6.5"
+ "version": "3.7.7"
}
},
"nbformat": 4,
diff --git "a/Day76-90/code/7-pandas\346\225\260\346\215\256\351\233\206\346\210\220merge.ipynb" "b/Day76-90/code/7-pandas\346\225\260\346\215\256\351\233\206\346\210\220merge.ipynb"
index 8b2eefcef..06fd9f690 100644
--- "a/Day76-90/code/7-pandas\346\225\260\346\215\256\351\233\206\346\210\220merge.ipynb"
+++ "b/Day76-90/code/7-pandas\346\225\260\346\215\256\351\233\206\346\210\220merge.ipynb"
@@ -1264,7 +1264,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.6.5"
+ "version": "3.7.7"
}
},
"nbformat": 4,
diff --git "a/Day76-90/code/8-pandas\345\210\206\347\273\204\350\201\232\345\220\210\346\223\215\344\275\234.ipynb" "b/Day76-90/code/8-pandas\345\210\206\347\273\204\350\201\232\345\220\210\346\223\215\344\275\234.ipynb"
index 7c16aff82..e9dddcc7e 100644
--- "a/Day76-90/code/8-pandas\345\210\206\347\273\204\350\201\232\345\220\210\346\223\215\344\275\234.ipynb"
+++ "b/Day76-90/code/8-pandas\345\210\206\347\273\204\350\201\232\345\220\210\346\223\215\344\275\234.ipynb"
@@ -869,7 +869,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.6.5"
+ "version": "3.7.7"
}
},
"nbformat": 4,