提交 ab45ce56 编写于 作者: J jackfrued

修改了部分文档

上级 cdb7fddd
......@@ -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:</script>
...
```
> 说明:`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**
......
......@@ -133,21 +133,7 @@ class SubjectMapper(ModelMapper):
<meta charset="UTF-8">
<title>学科信息</title>
<style>
#container {
width: 80%;
margin: 10px auto;
}
#main>dl>dt {
font-size: 1.5em;
font-weight: bold;
}
#main>dl>dd {
font-size: 1.2em;
}
a {
text-decoration: none;
color: darkcyan;
}
/* 此处省略层叠样式表 */
</style>
</head>
<body>
......@@ -157,7 +143,9 @@ class SubjectMapper(ModelMapper):
<div id="main">
<dl v-for="subject in subjects">
<dt>
<a :href="'/static/html/teachers.html?sno=' + subject.no">{{ subject.name }}</a>
<a :href="'/static/html/teachers.html?sno=' + subject.no">
{{ subject.name }}
</a>
<img v-if="subject.is_hot" src="/static/images/hot-icon-small.png">
</dt>
<dd>{{ subject.intro }}</dd>
......
......@@ -156,48 +156,14 @@ urlpatterns = [
通过Vue.js渲染页面。
```Python
```HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>老师信息</title>
<style>
#container {
width: 80%;
margin: 10px auto;
}
.teacher {
width: 100%;
margin: 0 auto;
padding: 10px 0;
border-bottom: 1px dashed gray;
overflow: auto;
}
.teacher>div {
float: left;
}
.photo {
height: 140px;
border-radius: 75px;
overflow: hidden;
margin-left: 20px;
}
.info {
width: 75%;
margin-left: 30px;
}
.info div {
clear: both;
margin: 5px 10px;
}
.info span {
margin-right: 25px;
}
a {
text-decoration: none;
color: darkcyan;
}
/* 此处省略掉层叠样式表 */
</style>
</head>
<body>
......@@ -217,9 +183,11 @@ urlpatterns = [
</div>
<div class="intro">{{ teacher.intro }}</div>
<div class="comment">
<a href="" @click.prevent="praise(teacher)">好评</a>&nbsp;&nbsp;(<strong>{{ teacher.good_count }}</strong>)
<a href="" @click.prevent="praise(teacher)">好评</a>&nbsp;&nbsp;
(<strong>{{ teacher.good_count }}</strong>)
&nbsp;&nbsp;&nbsp;&nbsp;
<a href="" @click.prevent="criticize(teacher)">差评</a>&nbsp;&nbsp;(<strong>{{ teacher.bad_count }}</strong>)
<a href="" @click.prevent="criticize(teacher)">差评</a>&nbsp;&nbsp;
(<strong>{{ teacher.bad_count }}</strong>)
</div>
</div>
</div>
......@@ -355,7 +323,7 @@ JSON Web Token通常简称为JWT,它是一种开放标准(RFC 7519)。随
2. 在令牌过期之前,无法作废已经颁发的令牌,要解决这个问题,还需要额外的中间层和代码来辅助。
3. JWT是用户的身份令牌,一旦泄露,任何人都可以获得该用户的所有权限。为了降低令牌被盗用后产生的风险,JWT的有效期应该设置得比较短。对于一些比较重要的权限,使用时应通过其他方式再次对用户进行认证,例如短信验证码等。
#### 使用PyJWT生成和验证令牌
#### 使用PyJWT
在Python代码中,可以使用三方库`PyJWT`生成和验证JWT,下面是安装`PyJWT`的命令。
......
......@@ -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 @@
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>a</th>\n",
" <td>113</td>\n",
" <td>116</td>\n",
" <td>75</td>\n",
" <td>a</td>\n",
" <td>109</td>\n",
" <td>120</td>\n",
" <td>23</td>\n",
" </tr>\n",
" <tr>\n",
" <th>b</th>\n",
" <td>19</td>\n",
" <td>145</td>\n",
" <td>23</td>\n",
" <td>b</td>\n",
" <td>54</td>\n",
" <td>39</td>\n",
" <td>54</td>\n",
" </tr>\n",
" <tr>\n",
" <th>c</th>\n",
" <td>57</td>\n",
" <td>107</td>\n",
" <td>113</td>\n",
" <td>c</td>\n",
" <td>97</td>\n",
" <td>22</td>\n",
" <td>106</td>\n",
" </tr>\n",
" <tr>\n",
" <th>d</th>\n",
" <td>95</td>\n",
" <td>d</td>\n",
" <td>21</td>\n",
" <td>96</td>\n",
" <td>3</td>\n",
" <td>66</td>\n",
" </tr>\n",
" <tr>\n",
" <th>e</th>\n",
" <td>28</td>\n",
" <td>121</td>\n",
" <td>120</td>\n",
" <td>e</td>\n",
" <td>23</td>\n",
" <td>145</td>\n",
" <td>147</td>\n",
" </tr>\n",
" <tr>\n",
" <th>f</th>\n",
" <td>141</td>\n",
" <td>85</td>\n",
" <td>132</td>\n",
" <td>f</td>\n",
" <td>80</td>\n",
" <td>62</td>\n",
" <td>83</td>\n",
" </tr>\n",
" <tr>\n",
" <th>h</th>\n",
" <td>124</td>\n",
" <td>39</td>\n",
" <td>10</td>\n",
" <td>h</td>\n",
" <td>70</td>\n",
" <td>31</td>\n",
" <td>134</td>\n",
" </tr>\n",
" <tr>\n",
" <th>i</th>\n",
" <td>80</td>\n",
" <td>35</td>\n",
" <td>17</td>\n",
" <td>i</td>\n",
" <td>132</td>\n",
" <td>51</td>\n",
" <td>115</td>\n",
" </tr>\n",
" <tr>\n",
" <th>j</th>\n",
" <td>68</td>\n",
" <td>99</td>\n",
" <td>31</td>\n",
" <td>j</td>\n",
" <td>95</td>\n",
" <td>143</td>\n",
" <td>111</td>\n",
" </tr>\n",
" <tr>\n",
" <th>k</th>\n",
" <td>74</td>\n",
" <td>12</td>\n",
" <td>11</td>\n",
" <td>k</td>\n",
" <td>66</td>\n",
" <td>94</td>\n",
" <td>7</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\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,
......
{
"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
}
{
"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<ipython-input-1-25f058890288>\u001b[0m in \u001b[0;36m<module>\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": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th>Python</th>\n",
" <th>En</th>\n",
" <th>Math</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th rowspan=\"4\" valign=\"top\">张三</th>\n",
" <th rowspan=\"2\" valign=\"top\">期中</th>\n",
" <th>A</th>\n",
" <td>15</td>\n",
" <td>31</td>\n",
" <td>17</td>\n",
" </tr>\n",
" <tr>\n",
" <th>B</th>\n",
" <td>82</td>\n",
" <td>56</td>\n",
" <td>123</td>\n",
" </tr>\n",
" <tr>\n",
" <th rowspan=\"2\" valign=\"top\">期末</th>\n",
" <th>A</th>\n",
" <td>14</td>\n",
" <td>2</td>\n",
" <td>78</td>\n",
" </tr>\n",
" <tr>\n",
" <th>B</th>\n",
" <td>69</td>\n",
" <td>50</td>\n",
" <td>17</td>\n",
" </tr>\n",
" <tr>\n",
" <th rowspan=\"4\" valign=\"top\">李四</th>\n",
" <th rowspan=\"2\" valign=\"top\">期中</th>\n",
" <th>A</th>\n",
" <td>91</td>\n",
" <td>87</td>\n",
" <td>143</td>\n",
" </tr>\n",
" <tr>\n",
" <th>B</th>\n",
" <td>120</td>\n",
" <td>118</td>\n",
" <td>39</td>\n",
" </tr>\n",
" <tr>\n",
" <th rowspan=\"2\" valign=\"top\">期末</th>\n",
" <th>A</th>\n",
" <td>56</td>\n",
" <td>76</td>\n",
" <td>55</td>\n",
" </tr>\n",
" <tr>\n",
" <th>B</th>\n",
" <td>11</td>\n",
" <td>105</td>\n",
" <td>121</td>\n",
" </tr>\n",
" <tr>\n",
" <th rowspan=\"4\" valign=\"top\">王五</th>\n",
" <th rowspan=\"2\" valign=\"top\">期中</th>\n",
" <th>A</th>\n",
" <td>147</td>\n",
" <td>78</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>B</th>\n",
" <td>128</td>\n",
" <td>126</td>\n",
" <td>146</td>\n",
" </tr>\n",
" <tr>\n",
" <th rowspan=\"2\" valign=\"top\">期末</th>\n",
" <th>A</th>\n",
" <td>49</td>\n",
" <td>45</td>\n",
" <td>114</td>\n",
" </tr>\n",
" <tr>\n",
" <th>B</th>\n",
" <td>121</td>\n",
" <td>26</td>\n",
" <td>77</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"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": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th></th>\n",
" <th>Python</th>\n",
" <th>En</th>\n",
" <th>Math</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th rowspan=\"2\" valign=\"top\">张三</th>\n",
" <th>期中</th>\n",
" <td>73</td>\n",
" <td>5</td>\n",
" <td>25</td>\n",
" </tr>\n",
" <tr>\n",
" <th>期末</th>\n",
" <td>37</td>\n",
" <td>36</td>\n",
" <td>56</td>\n",
" </tr>\n",
" <tr>\n",
" <th rowspan=\"2\" valign=\"top\">李四</th>\n",
" <th>期中</th>\n",
" <td>149</td>\n",
" <td>81</td>\n",
" <td>142</td>\n",
" </tr>\n",
" <tr>\n",
" <th>期末</th>\n",
" <td>71</td>\n",
" <td>138</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th rowspan=\"2\" valign=\"top\">王五</th>\n",
" <th>期中</th>\n",
" <td>11</td>\n",
" <td>94</td>\n",
" <td>103</td>\n",
" </tr>\n",
" <tr>\n",
" <th>期末</th>\n",
" <td>25</td>\n",
" <td>121</td>\n",
" <td>83</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"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": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th></th>\n",
" <th>Python</th>\n",
" <th>En</th>\n",
" <th>Math</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th rowspan=\"2\" valign=\"top\">张三</th>\n",
" <th>期中</th>\n",
" <td>73</td>\n",
" <td>5</td>\n",
" <td>25</td>\n",
" </tr>\n",
" <tr>\n",
" <th>期末</th>\n",
" <td>37</td>\n",
" <td>36</td>\n",
" <td>56</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"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
}
此差异已折叠。
此差异已折叠。
......@@ -992,7 +992,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.5"
"version": "3.7.7"
}
},
"nbformat": 4,
......
......@@ -1201,7 +1201,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.5"
"version": "3.7.7"
}
},
"nbformat": 4,
......
......@@ -1264,7 +1264,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.5"
"version": "3.7.7"
}
},
"nbformat": 4,
......
......@@ -869,7 +869,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.5"
"version": "3.7.7"
}
},
"nbformat": 4,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册