diff --git a/.gitpod.yml b/.gitpod.yml new file mode 100644 index 0000000..ca23c83 --- /dev/null +++ b/.gitpod.yml @@ -0,0 +1,3 @@ +tasks: + - before: gp open Day01-15/Day01/code/hello.py + command: python3 Day01-15/Day01/code/hello.py diff --git a/Day01-15/Day01/初识Python.md b/Day01-15/Day01/初识Python.md index 7f439a2..fecb2c8 100644 --- a/Day01-15/Day01/初识Python.md +++ b/Day01-15/Day01/初识Python.md @@ -180,25 +180,32 @@ jupyter notebook ![](./res/python-jupyter-2.png) +#### Anaconda - 一站式的数据科学神器 +Anaconda是专注于数据科学的Python发行版本,其包含了conda、Python等190多个科学包及其依赖项。因为包含的内容较多,Anaconda的下载文件比较大,如果只需要其中一部分的包,或者需要节省带宽或存储空间,也可以使用Miniconda这个较小的发行版(仅包含conda和 Python)。对于学习数据科学的人来说,Anaconda是绝对的神器,有兴趣的读者可以阅读[《致Python初学者们 - Anaconda入门使用指南》](https://www.jianshu.com/p/169403f7e40c)一文进行了解。 + #### Sublime - 文本编辑神器 ![](./res/python-sublime.png) - 首先可以通过[官方网站](https://www.sublimetext.com/)下载安装程序安装Sublime 3或Sublime 2。 -- 安装包管理工具。通过快捷键Ctrl+`或者在View菜单中选择Show Console打开控制台,输入下面的代码。 +- 安装包管理工具。 + 1. 通过快捷键Ctrl+`或者在View菜单中选择Show Console打开控制台,输入下面的代码。 - Sublime 3 ```Python import urllib.request,os;pf='Package Control.sublime-package';ipp=sublime.installed_packages_path();urllib.request.install_opener(urllib.request.build_opener(urllib.request.ProxyHandler()));open(os.path.join(ipp,pf),'wb').write(urllib.request.urlopen('http://sublime.wbond.net/'+pf.replace(' ','%20')).read()) ``` - - Sublime 2 ```Python import urllib2,os;pf='Package Control.sublime-package';ipp=sublime.installed_packages_path();os.makedirs(ipp)ifnotos.path.exists(ipp)elseNone;urllib2.install_opener(urllib2.build_opener(urllib2.ProxyHandler()));open(os.path.join(ipp,pf),'wb').write(urllib2.urlopen('http://sublime.wbond.net/'+pf.replace(' ','%20')).read());print('Please restart Sublime Text to finish installation') ``` + 2. 手动安装浏览器输入 https://sublime.wbond.net/Package%20Control.sublime-package 下载这个文件 + 下载好以后,打开sublime text,选择菜单Preferences->Browse Packages... 打开安装目录 + 此时会进入到一个叫做Packages的目录下,点击进入上一层目录Sublime Text3,在此目录下有一个文件夹叫做Installed Packages,把刚才下载的文件放到这里就可以了。然后重启sublime text3,观察Preferences菜单最下边是否有Package Settings 和Package Control两个选项,如果有,则代表安装成功了。 + - 安装插件。通过Preference菜单的Package Control或快捷键Ctrl+Shift+P打开命令面板,在面板中输入Install Package就可以找到安装插件的工具,然后再查找需要的插件。我们推荐大家安装以下几个插件: @@ -214,9 +221,15 @@ PyCharm的安装、配置和使用我们在后面会进行介绍。 ![](./res/python-pycharm.png) +#### Gitpod - 一键式在线开发工具 + +只需单击即可在GitHub上打开任何Python项目。 + +[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/jackfrued/Python-100-Days) + ### 练习 -1. 在Python交互环境中下面的代码查看结果并将内容翻译成中文。 +1. 在Python交互环境中查看下面的代码结果,并将内容翻译成中文。 ```Python import this diff --git a/Day01-15/Day02/code/string.py b/Day01-15/Day02/code/strings.py similarity index 100% rename from Day01-15/Day02/code/string.py rename to Day01-15/Day02/code/strings.py diff --git a/Day01-15/Day02/语言元素.md b/Day01-15/Day02/语言元素.md index 4a0937c..a4e6476 100644 --- a/Day01-15/Day02/语言元素.md +++ b/Day01-15/Day02/语言元素.md @@ -6,7 +6,7 @@ ### 变量和类型 -在程序设计中,变量是一种存储数据的载体。计算机中的变量是实际存在的数据或者说是存储器中存储数据的一块内存空间,变量的值可以被读取和修改,这是所有计算和控制的基础。计算机能处理的数据有很多中类型,除了数值之外还可以处理文本、图形、音频、视频等各种各样的数据,那么不同的数据就需要定义不同的存储类型。Python中的数据类型很多,而且也允许我们自定义新的数据类型(这一点在后面会讲到),我们先介绍几种常用的数据类型。 +在程序设计中,变量是一种存储数据的载体。计算机中的变量是实际存在的数据或者说是存储器中存储数据的一块内存空间,变量的值可以被读取和修改,这是所有计算和控制的基础。计算机能处理的数据有很多种类型,除了数值之外还可以处理文本、图形、音频、视频等各种各样的数据,那么不同的数据就需要定义不同的存储类型。Python中的数据类型很多,而且也允许我们自定义新的数据类型(这一点在后面会讲到),我们先介绍几种常用的数据类型。 - 整型:Python中可以处理任意大小的整数(Python 2.x中有int和long两种类型的整数,但这种区分对Python来说意义不大,因此在Python 3.x中整数只有int这一种了),而且支持二进制(如`0b100`,换算成十进制是4)、八进制(如`0o100`,换算成十进制是64)、十进制(`100`)和十六进制(`0x100`,换算成十进制是256)的表示法。 - 浮点型:浮点数也就是小数,之所以称为浮点数,是因为按照科学记数法表示时,一个浮点数的小数点位置是可变的,浮点数除了数学写法(如`123.456`)之外还支持科学计数法(如`1.23456e2`)。 @@ -99,11 +99,11 @@ print(type(e)) 在对变量类型进行转换时可以使用Python的内置函数(准确的说下面列出的并不是真正意义上的函数,而是后面我们要讲到的创建对象的构造方法)。 -- int():将一个数值或字符串转换成整数,可以指定进制。 -- float():将一个字符串转换成浮点数。 -- str():将指定的对象转换成字符串形式,可以指定编码。 -- chr():将整数转换成该编码对应的字符串(一个字符)。 -- ord():将字符串(一个字符)转换成对应的编码(整数)。 +- `int()`:将一个数值或字符串转换成整数,可以指定进制。 +- `float()`:将一个字符串转换成浮点数。 +- `str()`:将指定的对象转换成字符串形式,可以指定编码。 +- `chr()`:将整数转换成该编码对应的字符串(一个字符)。 +- `ord()`:将字符串(一个字符)转换成对应的编码(整数)。 ### 运算符 @@ -118,15 +118,15 @@ Python支持多种运算符,下表大致按照优先级从高到低的顺序 | `+` `-` | 加,减 | | `>>` `<<` | 右移,左移 | | `&` | 按位与 | -| `^` `|` | 按位异或,按位或 | +| `^` `\|` | 按位异或,按位或 | | `<=` `<` `>` `>=` | 小于等于,小于,大于,大于等于 | | `==` `!=` | 等于,不等于 | | `is` `is not` | 身份运算符 | | `in` `not in` | 成员运算符 | | `not` `or` `and` | 逻辑运算符 | -| `=` `+=` `-=` `*=` `/=` `%=` `//=` `**=` `&=` `|=` `^=` `>>=` `<<=` | (复合)赋值运算符 | +| `=` `+=` `-=` `*=` `/=` `%=` `//=` `**=` `&=` `\|=` `^=` `>>=` `<<=` | (复合)赋值运算符 | ->**说明:**在实际开发中,如果搞不清楚优先级可以使用括号来确保运算的执行顺序。 +>**说明:** 在实际开发中,如果搞不清楚优先级可以使用括号来确保运算的执行顺序。 下面的例子演示了运算符的使用。 diff --git a/Day01-15/Day03/res/formula_1.png b/Day01-15/Day03/res/formula_1.png new file mode 100644 index 0000000..5a0a7e2 Binary files /dev/null and b/Day01-15/Day03/res/formula_1.png differ diff --git a/Day01-15/Day03/分支结构.md b/Day01-15/Day03/分支结构.md index 017363e..aa3ef7d 100644 --- a/Day01-15/Day03/分支结构.md +++ b/Day01-15/Day03/分支结构.md @@ -31,7 +31,7 @@ else: 当然如果要构造出更多的分支,可以使用`if…elif…else…`结构,例如下面的分段函数求值。 -$$f(x)=\begin{cases} 3x-5&\text{(x>1)}\\x+2&\text{(-1}\leq\text{x}\leq\text{1)}\\5x+3&\text {(x<-1)}\end{cases}$$ +![$$f(x)=\begin{cases} 3x-5&\text{(x>1)}\\x+2&\text{(-1}\leq\text{x}\leq\text{1)}\\5x+3&\text {(x<-1)}\end{cases}$$](./res/formula_1.png) ```Python """ @@ -79,7 +79,7 @@ else: print('f(%.2f) = %.2f' % (x, y)) ``` -> **说明:**大家可以自己感受一下这两种写法到底是哪一种更好。在之前我们提到的Python之禅中有这么一句话“Flat is better than nested.”,之所以提出这个观点是因为嵌套结构的嵌套层次多了之后会严重的影响代码的可读性,如果可以使用扁平化的结构就不要去用嵌套,因此之前的写法是更好的做法。 +> **说明:** 大家可以自己感受一下这两种写法到底是哪一种更好。在之前我们提到的Python之禅中有这么一句话“Flat is better than nested.”,之所以提出这个观点是因为嵌套结构的嵌套层次多了之后会严重的影响代码的可读性,如果可以使用扁平化的结构就不要去用嵌套,因此之前的写法是更好的做法。 ### 练习 @@ -130,7 +130,7 @@ else: result = '讲冷笑话' print(result) ``` -> **说明:**上面的代码中使用了random模块的randint函数生成指定范围的随机数来模拟掷骰子。 +> **说明:** 上面的代码中使用了random模块的randint函数生成指定范围的随机数来模拟掷骰子。 #### 练习3:百分制成绩转等级制 @@ -184,7 +184,7 @@ if a + b > c and a + c > b and b + c > a: else: print('不能构成三角形') ``` -> **说明:**上面的代码中使用了`math`模块的`sqrt`函数来计算平方根。用边长计算三角形面积的公式叫做[海伦公式](https://zh.wikipedia.org/zh-hans/海伦公式)。 +> **说明:** 上面的代码中使用了`math`模块的`sqrt`函数来计算平方根。用边长计算三角形面积的公式叫做[海伦公式](https://zh.wikipedia.org/zh-hans/海伦公式)。 #### 练习5:个人所得税计算器。 @@ -227,4 +227,4 @@ tax = abs(diff * rate - deduction) print('个人所得税: ¥%.2f元' % tax) print('实际到手收入: ¥%.2f元' % (diff + 3500 - tax)) ``` ->**说明:**上面的代码中使用了Python内置的`abs()`函数取绝对值来处理`-0`的问题。 +>**说明:** 上面的代码中使用了Python内置的`abs()`函数取绝对值来处理`-0`的问题。 diff --git a/Day01-15/Day04/code/for1.py b/Day01-15/Day04/code/for1.py index 062179a..659724d 100644 --- a/Day01-15/Day04/code/for1.py +++ b/Day01-15/Day04/code/for1.py @@ -8,6 +8,5 @@ Date: 2018-03-01 sum = 0 for x in range(1, 101): - if x % 2 == 0: - sum += x + sum += x print(sum) diff --git a/Day01-15/Day04/res/formula_1.png b/Day01-15/Day04/res/formula_1.png new file mode 100644 index 0000000..c21c2ae Binary files /dev/null and b/Day01-15/Day04/res/formula_1.png differ diff --git a/Day01-15/Day04/循环结构.md b/Day01-15/Day04/循环结构.md index c3adf99..ff0fd26 100644 --- a/Day01-15/Day04/循环结构.md +++ b/Day01-15/Day04/循环结构.md @@ -6,7 +6,7 @@ ### for-in循环 -如果明确的知道循环执行的次数或者是要对一个容器进行迭代(后面会讲到),那么我们推荐使用`for-in`循环,例如下面代码中计算$\sum_{n=1}^{100}n$。 +如果明确的知道循环执行的次数或者是要对一个容器进行迭代(后面会讲到),那么我们推荐使用`for-in`循环,例如下面代码中计算![$\sum_{n=1}^{100}n$](./res/formula_1.png)。 ```Python """ @@ -94,7 +94,7 @@ if counter > 7: print('你的智商余额明显不足') ``` -> **说明:**上面的代码中使用了`break`关键字来提前终止循环,需要注意的是`break`只能终止它所在的那个循环,这一点在使用嵌套的循环结构(下面会讲到)需要引起注意。除了`break`之外,还有另一个关键字是`continue`,它可以用来放弃本次循环后续的代码直接让循环进入下一轮。 +> **说明:** 上面的代码中使用了`break`关键字来提前终止循环,需要注意的是`break`只能终止它所在的那个循环,这一点在使用嵌套的循环结构(下面会讲到)需要引起注意。除了`break`之外,还有另一个关键字是`continue`,它可以用来放弃本次循环后续的代码直接让循环进入下一轮。 和分支结构一样,循环结构也是可以嵌套的,也就是说在循环中还可以构造循环结构。下面的例子演示了如何通过嵌套的循环来输出一个九九乘法表。 diff --git a/Day01-15/Day06/res/formula_1.png b/Day01-15/Day06/res/formula_1.png new file mode 100644 index 0000000..b9a84ed Binary files /dev/null and b/Day01-15/Day06/res/formula_1.png differ diff --git a/Day01-15/Day06/res/formula_2.png b/Day01-15/Day06/res/formula_2.png new file mode 100644 index 0000000..692fb08 Binary files /dev/null and b/Day01-15/Day06/res/formula_2.png differ diff --git a/Day01-15/Day06/函数和模块的使用.md b/Day01-15/Day06/函数和模块的使用.md index 202b9e7..217b800 100644 --- a/Day01-15/Day06/函数和模块的使用.md +++ b/Day01-15/Day06/函数和模块的使用.md @@ -2,11 +2,11 @@ 在讲解本章节的内容之前,我们先来研究一道数学题,请说出下面的方程有多少组正整数解。 -$$x_1 + x_2 + x_3 + x_4 = 8$$ +![$$x_1 + x_2 + x_3 + x_4 = 8$$](./res/formula_1.png) 事实上,上面的问题等同于将8个苹果分成四组每组至少一个苹果有多少种方案。想到这一点问题的答案就呼之欲出了。 -$$C_M^N =\frac{M!}{N!(M-N)!}, \text{(M=7, N=3)} $$ +![$$C_M^N =\frac{M!}{N!(M-N)!}, \text{(M=7, N=3)} $$](./res/formula_2.png) 可以用Python的程序来计算出这个值,代码如下所示。 @@ -59,7 +59,7 @@ n = int(input('n = ')) print(factorial(m) // factorial(n) // factorial(m - n)) ``` -> **说明:**Python的math模块中其实已经有一个factorial函数了,事实上要计算阶乘可以直接使用这个现成的函数而不用自己定义。下面例子中的某些函数其实Python中也是内置了,我们这里是为了讲解函数的定义和使用才把它们又实现了一遍,实际开发中不建议做这种低级的重复性的工作。 +> **说明:** Python的math模块中其实已经有一个factorial函数了,事实上要计算阶乘可以直接使用这个现成的函数而不用自己定义。下面例子中的某些函数其实Python中也是内置了,我们这里是为了讲解函数的定义和使用才把它们又实现了一遍,实际开发中不建议做这种低级的重复性的工作。 ### 函数的参数 @@ -337,7 +337,7 @@ if __name__ == '__main__': 在实际开发中,我们应该尽量减少对全局变量的使用,因为全局变量的作用域和影响过于广泛,可能会发生意料之外的修改和使用,除此之外全局变量比局部变量拥有更长的生命周期,可能导致对象占用的内存长时间无法被[垃圾回收](https://zh.wikipedia.org/wiki/%E5%9E%83%E5%9C%BE%E5%9B%9E%E6%94%B6_(%E8%A8%88%E7%AE%97%E6%A9%9F%E7%A7%91%E5%AD%B8))。事实上,减少对全局变量的使用,也是降低代码之间耦合度的一个重要举措,同时也是对[迪米特法则](https://zh.wikipedia.org/zh-hans/%E5%BE%97%E5%A2%A8%E5%BF%92%E8%80%B3%E5%AE%9A%E5%BE%8B)的践行。减少全局变量的使用就意味着我们应该尽量让变量的作用域在函数的内部,但是如果我们希望将一个局部变量的生命周期延长,使其在函数调用结束后依然可以访问,这时候就需要使用[闭包](https://zh.wikipedia.org/wiki/%E9%97%AD%E5%8C%85_(%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%A7%91%E5%AD%A6)),这个我们在后续的内容中进行讲解。 -> **说明**:很多人经常会将“闭包”一词和[“匿名函数”](https://zh.wikipedia.org/wiki/%E5%8C%BF%E5%90%8D%E5%87%BD%E6%95%B0)混为一谈,但实际上它们是不同的概念,如果想提前了解这个概念,推荐看看[维基百科](https://zh.wikipedia.org/wiki/)或者[知乎](https://www.zhihu.com/)上对这个概念的讨论。 +> **说明:** 很多人经常会将“闭包”一词和[“匿名函数”](https://zh.wikipedia.org/wiki/%E5%8C%BF%E5%90%8D%E5%87%BD%E6%95%B0)混为一谈,但实际上它们是不同的概念,如果想提前了解这个概念,推荐看看[维基百科](https://zh.wikipedia.org/wiki/)或者[知乎](https://www.zhihu.com/)上对这个概念的讨论。 说了那么多,其实结论很简单,从现在开始我们可以将Python代码按照下面的格式进行书写,这一点点的改进其实就是在我们理解了函数和作用域的基础上跨出的巨大的一步。 diff --git a/Day01-15/Day07/res/formula_1.png b/Day01-15/Day07/res/formula_1.png new file mode 100644 index 0000000..28fad34 Binary files /dev/null and b/Day01-15/Day07/res/formula_1.png differ diff --git a/Day01-15/Day07/res/formula_2.png b/Day01-15/Day07/res/formula_2.png new file mode 100644 index 0000000..86df5da Binary files /dev/null and b/Day01-15/Day07/res/formula_2.png differ diff --git a/Day01-15/Day07/res/formula_3.png b/Day01-15/Day07/res/formula_3.png new file mode 100644 index 0000000..92cd76d Binary files /dev/null and b/Day01-15/Day07/res/formula_3.png differ diff --git a/Day01-15/Day07/res/formula_4.png b/Day01-15/Day07/res/formula_4.png new file mode 100644 index 0000000..a37f92b Binary files /dev/null and b/Day01-15/Day07/res/formula_4.png differ diff --git a/Day01-15/Day07/字符串和常用数据结构.md b/Day01-15/Day07/字符串和常用数据结构.md index 5dff114..2272310 100644 --- a/Day01-15/Day07/字符串和常用数据结构.md +++ b/Day01-15/Day07/字符串和常用数据结构.md @@ -2,7 +2,7 @@ ### 使用字符串 -第二次世界大战促使了现代电子计算机的诞生,当初的想法很简单,就是用计算机来计算导弹的弹道,因此在计算机刚刚诞生的那个年代,计算机处理的信息主要是数值,而世界上的第一台电子计算机ENIAC每秒钟能够完成约5000次浮点运算。随着时间的推移,虽然对数值运算仍然是计算机日常工作中最为重要的事情之一,但是今天的计算机处理得更多的数据都是以文本信息的方式存在的,而Python表示文本信息的方式我们在很早以前就说过了,那就是字符串类型。所谓**字符串**,就是由零个或多个字符组成的有限序列,一般记为[$${\displaystyle s=a_{1}a_{2}\dots a_{n}(0\leq n \leq \infty)}$$](https://wikimedia.org/api/rest_v1/media/math/render/svg/e29bf631b090323edd6889f810e6cff29538b161)。 +第二次世界大战促使了现代电子计算机的诞生,当初的想法很简单,就是用计算机来计算导弹的弹道,因此在计算机刚刚诞生的那个年代,计算机处理的信息主要是数值,而世界上的第一台电子计算机ENIAC每秒钟能够完成约5000次浮点运算。随着时间的推移,虽然对数值运算仍然是计算机日常工作中最为重要的事情之一,但是今天的计算机处理得更多的数据都是以文本信息的方式存在的,而Python表示文本信息的方式我们在很早以前就说过了,那就是字符串类型。所谓**字符串**,就是由零个或多个字符组成的有限序列,一般记为![$${\displaystyle s=a_{1}a_{2}\dots a_{n}(0\leq n \leq \infty)}$$](./res/formula_1.png)。 我们可以通过下面的代码来了解字符串的使用。 @@ -183,11 +183,11 @@ if __name__ == '__main__': 除了上面提到的生成器语法,Python中还有另外一种定义生成器的方式,就是通过`yield`关键字将一个普通函数改造成生成器函数。下面的代码演示了如何实现一个生成[斐波拉切数列](https://zh.wikipedia.org/wiki/%E6%96%90%E6%B3%A2%E9%82%A3%E5%A5%91%E6%95%B0%E5%88%97)的生成器。所谓斐波拉切数列可以通过下面[递归](https://zh.wikipedia.org/wiki/%E9%80%92%E5%BD%92)的方法来进行定义: -$${\displaystyle F_{0}=0}$$ +![$${\displaystyle F_{0}=0}$$](./res/formula_2.png) -$${\displaystyle F_{1}=1}$$ +![$${\displaystyle F_{1}=1}$$](./res/formula_3.png) -$${\displaystyle F_{n}=F_{n-1}+F_{n-2}}({n}\geq{2})$$ +![$${\displaystyle F_{n}=F_{n-1}+F_{n-2}}({n}\geq{2})$$](./res/formula_4.png) ![](./res/fibonacci-blocks.png) @@ -307,7 +307,7 @@ if __name__ == '__main__': main() ``` -> **说明**:Python中允许通过一些特殊的方法来为某种类型或数据结构自定义运算符(后面的章节中会讲到),上面的代码中我们对集合进行运算的时候可以调用集合对象的方法,也可以直接使用对应的运算符,例如`&`运算符跟intersection方法的作用就是一样的,但是使用运算符让代码更加直观。 +> **说明:** Python中允许通过一些特殊的方法来为某种类型或数据结构自定义运算符(后面的章节中会讲到),上面的代码中我们对集合进行运算的时候可以调用集合对象的方法,也可以直接使用对应的运算符,例如`&`运算符跟intersection方法的作用就是一样的,但是使用运算符让代码更加直观。 ### 使用字典 @@ -530,7 +530,7 @@ if __name__ == '__main__': main() ``` -> **说明**:上面使用random模块的sample函数来实现从列表中选择不重复的n个元素。 +> **说明:** 上面使用random模块的sample函数来实现从列表中选择不重复的n个元素。 #### 综合案例2:[约瑟夫环问题](https://zh.wikipedia.org/wiki/%E7%BA%A6%E7%91%9F%E5%A4%AB%E6%96%AF%E9%97%AE%E9%A2%98) @@ -609,4 +609,4 @@ if __name__ == '__main__': main() ``` ->**说明**:最后这个案例来自[《Python编程快速上手:让繁琐工作自动化》](https://item.jd.com/11943853.html)一书(这本书对有编程基础想迅速使用Python将日常工作自动化的人来说还是不错的选择),对代码做了一点点的调整。 \ No newline at end of file +>**说明:** 最后这个案例来自[《Python编程快速上手:让繁琐工作自动化》](https://item.jd.com/11943853.html)一书(这本书对有编程基础想迅速使用Python将日常工作自动化的人来说还是不错的选择),对代码做了一点点的调整。 \ No newline at end of file diff --git a/Day01-15/Day08/面向对象编程基础.md b/Day01-15/Day08/面向对象编程基础.md index b4f4856..dbbedeb 100644 --- a/Day01-15/Day08/面向对象编程基础.md +++ b/Day01-15/Day08/面向对象编程基础.md @@ -8,13 +8,13 @@ ![](./res/oop-zhihu.png) -> **说明**:以上的内容来自于网络,不代表作者本人的观点和看法,与作者本人立场无关,相关责任不由作者承担。 +> **说明:** 以上的内容来自于网络,不代表作者本人的观点和看法,与作者本人立场无关,相关责任不由作者承担。 之前我们说过“程序是指令的集合”,我们在程序中书写的语句在执行时会变成一条或多条指令然后由CPU去执行。当然为了简化程序的设计,我们引入了函数的概念,把相对独立且经常重复使用的代码放置到函数中,在需要使用这些功能的时候只要调用函数即可;如果一个函数的功能过于复杂和臃肿,我们又可以进一步将函数继续切分为子函数来降低系统的复杂性。但是说了这么多,不知道大家是否发现,所谓编程就是程序员按照计算机的工作方式控制计算机完成各种任务。但是,计算机的工作方式与正常人类的思维模式是不同的,如果编程就必须得抛弃人类正常的思维方式去迎合计算机,编程的乐趣就少了很多,“每个人都应该学习编程”这样的豪言壮语就只能说说而已。当然,这些还不是最重要的,最重要的是当我们需要开发一个复杂的系统时,代码的复杂性会让开发和维护工作都变得举步维艰,所以在上世纪60年代末期,“[软件危机](https://zh.wikipedia.org/wiki/%E8%BD%AF%E4%BB%B6%E5%8D%B1%E6%9C%BA)”、“[软件工程](https://zh.wikipedia.org/wiki/%E8%BD%AF%E4%BB%B6%E5%B7%A5%E7%A8%8B)”等一系列的概念开始在行业中出现。 当然,程序员圈子内的人都知道,现实中并没有解决上面所说的这些问题的“[银弹](https://zh.wikipedia.org/wiki/%E6%B2%A1%E6%9C%89%E9%93%B6%E5%BC%B9)”,真正让软件开发者看到希望的是上世纪70年代诞生的[Smalltalk](https://zh.wikipedia.org/wiki/Smalltalk)编程语言中引入的面向对象的编程思想(面向对象编程的雏形可以追溯到更早期的[Simula](https://zh.wikipedia.org/wiki/Simula)语言)。按照这种编程理念,程序中的数据和操作数据的函数是一个逻辑上的整体,我们称之为“对象”,而我们解决问题的方式就是创建出需要的对象并向对象发出各种各样的消息,多个对象的协同工作最终可以让我们构造出复杂的系统来解决现实中的问题。 -> **说明**:当然面向对象也不是解决软件开发中所有问题的最后的“银弹”,所以今天的高级程序设计语言几乎都提供了对多种编程范式的支持,Python也不例外。 +> **说明:** 当然面向对象也不是解决软件开发中所有问题的最后的“银弹”,所以今天的高级程序设计语言几乎都提供了对多种编程范式的支持,Python也不例外。 ### 类和对象 @@ -44,10 +44,10 @@ class Student(object): if self.age < 18: print('%s只能观看《熊出没》.' % self.name) else: - print('%s正在观看岛国爱情动作片.' % self.name + print('%s正在观看岛国爱情动作片.' % self.name) ``` -> **说明**:写在类中的函数,我们通常称之为(对象的)方法,这些方法就是对象可以接收的消息。 +> **说明:** 写在类中的函数,我们通常称之为(对象的)方法,这些方法就是对象可以接收的消息。 ### 创建和使用对象 @@ -237,4 +237,4 @@ if __name__ == '__main__': main() ``` -> **说明**:本章中的插图来自于Grady Booch等著作的[《面向对象分析与设计》](https://item.jd.com/20476561918.html)一书,该书是讲解面向对象编程的经典著作,有兴趣的读者可以购买和阅读这本书来了解更多的面向对象的相关知识。 \ No newline at end of file +> **说明:** 本章中的插图来自于Grady Booch等著作的[《面向对象分析与设计》](https://item.jd.com/20476561918.html)一书,该书是讲解面向对象编程的经典著作,有兴趣的读者可以购买和阅读这本书来了解更多的面向对象的相关知识。 \ No newline at end of file diff --git a/Day01-15/Day09/面向对象进阶.md b/Day01-15/Day09/面向对象进阶.md index 168884d..956d910 100644 --- a/Day01-15/Day09/面向对象进阶.md +++ b/Day01-15/Day09/面向对象进阶.md @@ -636,7 +636,7 @@ if __name__ == '__main__': main() ``` ->**说明**:大家可以自己尝试在上面代码的基础上写一个简单的扑克游戏,例如21点(Black Jack),游戏的规则可以自己在网上找一找。 +>**说明:** 大家可以自己尝试在上面代码的基础上写一个简单的扑克游戏,例如21点(Black Jack),游戏的规则可以自己在网上找一找。 #### 案例3:工资结算系统 diff --git a/Day01-15/Day10/图形用户界面和游戏开发.md b/Day01-15/Day10/图形用户界面和游戏开发.md index 6dfada7..ae65624 100644 --- a/Day01-15/Day10/图形用户界面和游戏开发.md +++ b/Day01-15/Day10/图形用户界面和游戏开发.md @@ -128,7 +128,7 @@ if __name__ == '__main__': main() ``` -####加载图像 +#### 加载图像 如果需要直接加载图像到窗口上,可以使用pygame中image模块的函数来加载图像,再通过之前获得的窗口对象的`blit`方法渲染图像,代码如下所示。 @@ -164,7 +164,7 @@ if __name__ == '__main__': main() ``` -####实现动画效果 +#### 实现动画效果 说到[动画](https://zh.wikipedia.org/wiki/%E5%8A%A8%E7%94%BB)这个词大家都不会陌生,事实上要实现动画效果,本身的原理也非常简单,就是将不连续的图片连续的播放,只要每秒钟达到了一定的帧数,那么就可以做出比较流畅的动画效果。如果要让上面代码中的小球动起来,可以将小球的位置用变量来表示,并在循环中修改小球的位置再刷新整个窗口即可。 diff --git a/Day01-15/Day11/文件和异常.md b/Day01-15/Day11/文件和异常.md index 924aef9..3fca86d 100644 --- a/Day01-15/Day11/文件和异常.md +++ b/Day01-15/Day11/文件和异常.md @@ -103,7 +103,7 @@ if __name__ == '__main__': main() ``` -要将文本信息写入文件文件也非常简单,在使用`open`函数时指定好文件名并将文件模式设置为`'w'`即可。注意如果需要对文件内容进行追加式写入,应该将模式设置为`'a'`。如果要写入的文件不存在会自动创建文件而不是引发异常。下面的例子演示了如何将1-9999直接的素数分别写入三个文件中(1-99之间的素数保存在a.txt中,100-999之间的素数保存在b.txt中,1000-9999之间的素数保存在c.txt中)。 +要将文本信息写入文件文件也非常简单,在使用`open`函数时指定好文件名并将文件模式设置为`'w'`即可。注意如果需要对文件内容进行追加式写入,应该将模式设置为`'a'`。如果要写入的文件不存在会自动创建文件而不是引发异常。下面的例子演示了如何将1-9999之间的素数分别写入三个文件中(1-99之间的素数保存在a.txt中,100-999之间的素数保存在b.txt中,1000-9999之间的素数保存在c.txt中)。 ```Python from math import sqrt @@ -174,14 +174,14 @@ if __name__ == '__main__': ```JSON { - 'name': '骆昊', - 'age': 38, - 'qq': 957658, - 'friends': ['王大锤', '白元芳'], - 'cars': [ - {'brand': 'BYD', 'max_speed': 180}, - {'brand': 'Audi', 'max_speed': 280}, - {'brand': 'Benz', 'max_speed': 320} + "name": "骆昊", + "age": 38, + "qq": 957658, + "friends": ["王大锤", "白元芳"], + "cars": [ + {"brand": "BYD", "max_speed": 180}, + {"brand": "Audi", "max_speed": 280}, + {"brand": "Benz", "max_speed": 320} ] } ``` diff --git a/Day01-15/Day12/字符串和正则表达式.md b/Day01-15/Day12/字符串和正则表达式.md index 418d039..b8b9ae9 100644 --- a/Day01-15/Day12/字符串和正则表达式.md +++ b/Day01-15/Day12/字符串和正则表达式.md @@ -32,7 +32,7 @@ | \| | 分支 | foo\|bar | 可以匹配foo或者bar | | (?#) | 注释 | | | | (exp) | 匹配exp并捕获到自动命名的组中 | | | -| (?<name>exp) | 匹配exp并捕获到名为name的组中 | | | +| (? <name>exp) | 匹配exp并捕获到名为name的组中 | | | | (?:exp) | 匹配exp但是不捕获匹配的文本 | | | | (?=exp) | 匹配exp前面的位置 | \\b\\w+(?=ing) | 可以匹配I'm dancing中的danc | | (?<=exp) | 匹配exp后面的位置 | (?<=\\bdanc)\\w+\\b | 可以匹配I love dancing and reading中的第一个ing | @@ -44,7 +44,7 @@ | {M,N}? | 重复M到N次,但尽可能少重复 | | | | {M,}? | 重复M次以上,但尽可能少重复 | | | -> **说明:**如果需要匹配的字符是正则表达式中的特殊字符,那么可以使用\\进行转义处理,例如想匹配小数点可以写成\\.就可以了,因为直接写.会匹配任意字符;同理,想匹配圆括号必须写成\\(和\\),否则圆括号被视为正则表达式中的分组。 +> **说明:** 如果需要匹配的字符是正则表达式中的特殊字符,那么可以使用\\进行转义处理,例如想匹配小数点可以写成\\.就可以了,因为直接写.会匹配任意字符;同理,想匹配圆括号必须写成\\(和\\),否则圆括号被视为正则表达式中的分组。 ### Python对正则表达式的支持 @@ -64,7 +64,7 @@ Python提供了re模块来支持正则表达式相关操作,下面是re模块 | re.I / re.IGNORECASE | 忽略大小写匹配标记 | | re.M / re.MULTILINE | 多行匹配标记 | -> **说明:**上面提到的re模块中的这些函数,实际开发中也可以用正则表达式对象的方法替代对这些函数的使用,如果一个正则表达式需要重复的使用,那么先通过compile函数编译正则表达式并创建出正则表达式对象无疑是更为明智的选择。 +> **说明:** 上面提到的re模块中的这些函数,实际开发中也可以用正则表达式对象的方法替代对这些函数的使用,如果一个正则表达式需要重复的使用,那么先通过compile函数编译正则表达式并创建出正则表达式对象无疑是更为明智的选择。 下面我们通过一系列的例子来告诉大家在Python中如何使用正则表达式。 @@ -98,7 +98,7 @@ if __name__ == '__main__': main() ``` -> **提示**:上面在书写正则表达式时使用了“原始字符串”的写法(在字符串前面加上了r),所谓“原始字符串”就是字符串中的每个字符都是它原始的意义,说得更直接一点就是字符串中没有所谓的转义字符啦。因为正则表达式中有很多元字符和需要进行转义的地方,如果不使用原始字符串就需要将反斜杠写作\\\\,例如表示数字的\\d得书写成\\\\d,这样不仅写起来不方便,阅读的时候也会很吃力。 +> **提示:** 上面在书写正则表达式时使用了“原始字符串”的写法(在字符串前面加上了r),所谓“原始字符串”就是字符串中的每个字符都是它原始的意义,说得更直接一点就是字符串中没有所谓的转义字符啦。因为正则表达式中有很多元字符和需要进行转义的地方,如果不使用原始字符串就需要将反斜杠写作\\\\,例如表示数字的\\d得书写成\\\\d,这样不仅写起来不方便,阅读的时候也会很吃力。 #### 例子2:从一段文字中提取出国内手机号码。 @@ -136,7 +136,7 @@ if __name__ == '__main__': main() ``` -> **说明**:上面匹配国内手机号的正则表达式并不够好,因为像14开头的号码只有145或147,而上面的正则表达式并没有考虑这种情况,要匹配国内手机号,更好的正则表达式的写法是:`(?<=\D)(1[38]\d{9}|14[57]\d{8}|15[0-35-9]\d{8}|17[678]\d{8})(?=\D)`,国内最近好像有19和16开头的手机号了,但是这个暂时不在我们考虑之列。 +> **说明:** 上面匹配国内手机号的正则表达式并不够好,因为像14开头的号码只有145或147,而上面的正则表达式并没有考虑这种情况,要匹配国内手机号,更好的正则表达式的写法是:`(?<=\D)(1[38]\d{9}|14[57]\d{8}|15[0-35-9]\d{8}|17[678]\d{8})(?=\D)`,国内最近好像有19和16开头的手机号了,但是这个暂时不在我们考虑之列。 #### 例子3:替换字符串中的不良内容 @@ -155,7 +155,7 @@ if __name__ == '__main__': main() ``` -> **说明**:re模块的正则表达式相关函数中都有一个flags参数,它代表了正则表达式的匹配标记,可以通过该标记来指定匹配时是否忽略大小写、是否进行多行匹配、是否显示调试信息等。如果需要为flags参数指定多个值,可以使用[按位或运算符](http://www.runoob.com/python/python-operators.html#ysf5)进行叠加,如`flags=re.I | re.M`。 +> **说明:** re模块的正则表达式相关函数中都有一个flags参数,它代表了正则表达式的匹配标记,可以通过该标记来指定匹配时是否忽略大小写、是否进行多行匹配、是否显示调试信息等。如果需要为flags参数指定多个值,可以使用[按位或运算符](http://www.runoob.com/python/python-operators.html#ysf5)进行叠加,如`flags=re.I | re.M`。 #### 例子4:拆分长字符串 diff --git a/Day01-15/Day13/进程和线程.md b/Day01-15/Day13/进程和线程.md index c1d2093..befdc4c 100644 --- a/Day01-15/Day13/进程和线程.md +++ b/Day01-15/Day13/进程和线程.md @@ -320,7 +320,7 @@ if __name__ == '__main__': 除了计算密集型任务,其他的涉及到网络、存储介质I/O的任务都可以视为I/O密集型任务,这类任务的特点是CPU消耗很少,任务的大部分时间都在等待I/O操作完成(因为I/O的速度远远低于CPU和内存的速度)。对于I/O密集型任务,如果启动多任务,就可以减少I/O等待时间从而让CPU高效率的运转。有一大类的任务都属于I/O密集型任务,这其中包括了我们很快会涉及到的网络应用和Web应用。 -> **说明:**上面的内容和例子来自于[廖雪峰官方网站的《Python教程》](https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000),因为对作者文中的某些观点持有不同的看法,对原文的文字描述做了适当的调整。 +> **说明:** 上面的内容和例子来自于[廖雪峰官方网站的《Python教程》](https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000),因为对作者文中的某些观点持有不同的看法,对原文的文字描述做了适当的调整。 ### 单线程+异步I/O diff --git a/Day01-15/Day14-A/网络编程入门.md b/Day01-15/Day14-A/网络编程入门.md index a466865..234ca2d 100644 --- a/Day01-15/Day14-A/网络编程入门.md +++ b/Day01-15/Day14-A/网络编程入门.md @@ -70,9 +70,9 @@ JSON的例子: ```JSON { - 'from': 'Alice', - 'to': 'Bob', - 'content': 'Will you marry me?' + "from": "Alice", + "to": "Bob", + "content": "Will you marry me?" } ``` @@ -291,7 +291,7 @@ if __name__ == '__main__': 在这个案例中,我们使用了JSON作为数据传输的格式(通过JSON格式对传输的数据进行了序列化和反序列化的操作),但是JSON并不能携带二进制数据,因此对图片的二进制数据进行了Base64编码的处理。Base64是一种用64个字符表示所有二进制数据的编码方式,通过将二进制数据每6位一组的方式重新组织,刚好可以使用0~9的数字、大小写字母以及“+”和“/”总共64个字符表示从`000000`到`111111`的64种状态。[维基百科](https://zh.wikipedia.org/wiki/Base64)上有关于Base64编码的详细讲解,不熟悉Base64的读者可以自行阅读。 -> **说明**:上面的代码主要为了讲解网络编程的相关内容因此并没有对异常状况进行处理,请读者自行添加异常处理代码来增强程序的健壮性。 +> **说明:** 上面的代码主要为了讲解网络编程的相关内容因此并没有对异常状况进行处理,请读者自行添加异常处理代码来增强程序的健壮性。 #### UDP套接字 diff --git a/Day01-15/Day15/图像和办公文档处理.md b/Day01-15/Day15/图像和办公文档处理.md index d17be26..765afa0 100644 --- a/Day01-15/Day15/图像和办公文档处理.md +++ b/Day01-15/Day15/图像和办公文档处理.md @@ -76,7 +76,7 @@ Pillow中最为重要的是Image类,读取和处理图像都要通过这个类 ```Python >>> image = Image.open('./res/guido.png') - >>> image.rotata(180).show() + >>> image.rotate(180).show() >>> image.transpose(Image.FLIP_LEFT_RIGHT).show() ``` diff --git a/Day16-20/Python语言进阶.md b/Day16-20/Python语言进阶.md index ab7c6fc..b304f6e 100644 --- a/Day16-20/Python语言进阶.md +++ b/Day16-20/Python语言进阶.md @@ -198,7 +198,8 @@ - 常用算法: - 穷举法 - 又称为暴力破解法,对所有的可能性进行验证,直到找到正确答案。 - - 贪婪法 - 在对问题求解时,总是做出在当前看来是最好的选择,不追求最优解,快速找到满意解。 + - 贪婪法 - 在对问题求解时,总是做出在当前看来 + - 最好的选择,不追求最优解,快速找到满意解。 - 分治法 - 把一个复杂的问题分成两个或更多的相同或相似的子问题,再把子问题分成更小的子问题,直到可以直接求解的程度,最后将子问题的解进行合并得到原问题的解。 - 回溯法 - 回溯法又称为试探法,按选优条件向前搜索,当搜索到某一步发现原先选择并不优或达不到目标时,就退回一步重新选择。 - 动态规划 - 基本思想也是将待求解问题分解成若干个子问题,先求解并保存这些子问题的解,避免产生大量的重复运算。 @@ -218,7 +219,7 @@ # 第二天A第一个醒来 他将鱼分为5份 扔掉多余的1条 拿走自己的一份 # B第二个醒来 也将鱼分为5份 扔掉多余的1条 拿走自己的一份 # 然后C、D、E依次醒来也按同样的方式分鱼 问他们至少捕了多少条鱼 - fish = 1 + fish = 6 while True: total = fish enough = True @@ -231,7 +232,7 @@ if enough: print(fish) break - fish += 1 + fish += 5 ``` 贪婪法例子:假设小偷有一个背包,最多能装20公斤赃物,他闯入一户人家,发现如下表所示的物品。很显然,他不能把所有物品都装进背包,所以必须确定拿走哪些物品,留下哪些物品。 @@ -555,6 +556,7 @@ ```Python from functools import wraps + from threading import Lock def singleton(cls): @@ -767,6 +769,8 @@ main() ``` + > 说明:上面的代码中使用了Emoji字符来表示扑克牌的四种花色,在某些不支持Emoji字符的系统上可能无法显示。 + - 对象的复制(深复制/深拷贝/深度克隆和浅复制/浅拷贝/影子克隆) - 垃圾回收、循环引用和弱引用 diff --git a/Day16-20/code/root@39.100.102.28 b/Day16-20/code/root@39.100.102.28 new file mode 100644 index 0000000..315679e --- /dev/null +++ b/Day16-20/code/root@39.100.102.28 @@ -0,0 +1,50 @@ +""" +多进程和进程池的使用 +多线程因为GIL的存在不能够发挥CPU的多核特性 +对于计算密集型任务应该考虑使用多进程 +time python3 example22.py +real 0m11.512s +user 0m39.319s +sys 0m0.169s +""" +import concurrent.futures +import math + +PRIMES = [ + 1116281, + 1297337, + 104395303, + 472882027, + 533000389, + 817504243, + 982451653, + 112272535095293, + 112582705942171, + 112272535095293, + 115280095190773, + 115797848077099, + 1099726899285419 +] * 5 + + +def is_prime(n): + """判断素数""" + if n % 2 == 0: + return False + + sqrt_n = int(math.floor(math.sqrt(n))) + for i in range(3, sqrt_n + 1, 2): + if n % i == 0: + return False + return True + + +def main(): + """主函数""" + with concurrent.futures.ProcessPoolExecutor() as executor: + for number, prime in zip(PRIMES, executor.map(is_prime, PRIMES)): + print('%d is prime: %s' % (number, prime)) + + +if __name__ == '__main__': + main() diff --git a/Day31-35/res/andrew-tanenbaum.png b/Day31-35/res/andrew-tanenbaum.png deleted file mode 100644 index 195e6e7..0000000 Binary files a/Day31-35/res/andrew-tanenbaum.png and /dev/null differ diff --git a/Day31-35/res/andrew.jpg b/Day31-35/res/andrew.jpg new file mode 100644 index 0000000..8f001d3 Binary files /dev/null and b/Day31-35/res/andrew.jpg differ diff --git a/Day31-35/res/dennis-ritchie.png b/Day31-35/res/dmr.png similarity index 100% rename from Day31-35/res/dennis-ritchie.png rename to Day31-35/res/dmr.png diff --git a/Day31-35/res/Ken-Thompson.png b/Day31-35/res/ken_old.png similarity index 100% rename from Day31-35/res/Ken-Thompson.png rename to Day31-35/res/ken_old.png diff --git a/Day31-35/res/ken_young.jpg b/Day31-35/res/ken_young.jpg new file mode 100644 index 0000000..46e3009 Binary files /dev/null and b/Day31-35/res/ken_young.jpg differ diff --git a/Day31-35/res/linus-torvalds.png b/Day31-35/res/linus.png similarity index 100% rename from Day31-35/res/linus-torvalds.png rename to Day31-35/res/linus.png diff --git a/Day31-35/res/pdp-11.jpg b/Day31-35/res/pdp-11.jpg new file mode 100644 index 0000000..6b4486b Binary files /dev/null and b/Day31-35/res/pdp-11.jpg differ diff --git a/Day31-35/res/rk05.jpg b/Day31-35/res/rk05.jpg new file mode 100644 index 0000000..a10eaec Binary files /dev/null and b/Day31-35/res/rk05.jpg differ diff --git a/Day31-35/玩转Linux操作系统.md b/Day31-35/玩转Linux操作系统.md index 37e1d79..d3f457c 100644 --- a/Day31-35/玩转Linux操作系统.md +++ b/Day31-35/玩转Linux操作系统.md @@ -1,14 +1,14 @@ ## 玩转Linux操作系统 +> 说明:本文中对Linux命令的讲解都是基于名为CentOS的Linux发行版本,我自己使用的是阿里云服务器,系统版本为CentOS Linux release 7.6.1810。不同的Linux发行版本在Shell命令和工具程序上会有一些差别,但是这些差别是很小的。 + ### 操作系统发展史 -只有硬件没有软件的计算机系统被称之为“裸机”,我们很难用“裸机”来完成计算机日常的工作(如存储和运算),所以必须用特定的软件来控制硬件的工作。最靠近计算机硬件的软件是系统软件,其中最为重要的就是“操作系统”。“操作系统”是控制和管理整个计算机系统的硬件和软件资源,合理的分配资源和调配任务,为系统用户和其他软件提供接口和环境的程序的集合。 +只有硬件没有软件的计算机系统被称之为“裸机”,我们很难用“裸机”来完成计算机日常的工作(如存储和运算),所以必须用特定的软件来控制硬件的工作。最靠近计算机硬件的软件是系统软件,其中最为重要的就是“操作系统”。“操作系统”是控制和管理整个计算机硬件和软件资源、实现资源分配和任务调配、为系统用户以及其他软件提供接口和环境的程序的集合。 #### 没有操作系统(手工操作) -在计算机诞生之初没有操作系统的年代,人们先把程序纸带(或卡片)装上计算机,然后启动输入机把程序和送入计算机,接着通过控制台开关启动程序运行。当程序执行完毕,打印机输出计算的结果,用户卸下并取走纸带(或卡片)。第二个用户上机,重复同样的步骤。在整个过程中用户独占机器,CPU等待手工操作,资源利用率极低。下图是IBM生产的书写Fortran程序的80栏打孔卡,当然这个已经是比较先进的打孔卡了。 - -![](./res/ibm-col80-punched-card.png) +在计算机诞生之初没有操作系统的年代,人们先把程序纸带(或卡片)装上计算机,然后启动输入机把程序送入计算机,接着通过控制台开关启动程序运行。当程序执行完毕,打印机输出计算的结果,用户卸下并取走纸带(或卡片)。第二个用户上机,重复同样的步骤。在整个过程中用户独占机器,CPU等待手工操作,资源利用率极低。 #### 批处理系统 @@ -24,31 +24,35 @@ 2. 1965年:AT&T的贝尔实验室加入GE和MIT的合作计划开始开发MULTICS。 -3. 1969年:Ken Tompson为了玩“Space Travel”游戏用汇编语言在PDP-7上开发了Unics。 +3. 1969年:MULTICS项目失败,Ken Tompson赋闲在家,为了玩“Space Travel”游戏用汇编语言在当时已经被淘汰的PDP-7上开发了Unics。 - ![](./res/Ken-Thompson.png) + ![](./res/ken_young.jpg) ![](./res/pdp-7.png) + > 注:很难想象,Unix这么伟大的系统,居然是一个赋闲在家的程序员(关键是老婆回娘家还带上了孩子)在一台被淘汰的设备上为了玩游戏开发出来的。 + 4. 1970年~1971年:Ken Tompson和Dennis Ritchie用B语言在PDP-11上重写了Unics,并在Brian Kernighan的建议下将其更名为Unix。 + ![](./res/dmr.png) + ![](./res/ken-and-dennis-pdp-11.png) -5. 1972年~1973年:Dennis Ritchie发明了C语言来取代可移植性较差的B语言,并开启了用C语言重写Unix的工作。 + ![](./res/pdp-11.jpg) - ![](./res/dennis-ritchie.png) +5. 1972年~1973年:Dennis Ritchie发明了C语言来取代可移植性较差的B语言,并开启了用C语言重写Unix的工作。 6. 1974年:Unix推出了里程碑意义的第5版,几乎完全用C语言来实现。 7. 1979年:从Unix第7版开始,AT&T发布新的使用条款,将Unix私有化。 -8. 1987年:Andrew S. Tanenbaum教授为了能在课堂上教授学生操作系统运作的细节,决定在不使用任何AT&T的源代码前提下,自行开发与Unix兼容的操作系统,以避免版权上的争议并将其命名为Minix。 +8. 1987年:Andrew S. Tanenbaum教授为了能在课堂上为学生讲解操作系统运作的细节,决定在不使用任何AT&T的源代码前提下,自行开发与Unix兼容的操作系统以避免版权上的争议,该系统被命名为Minix。 - ![](./res/andrew-tanenbaum.png) + ![](./res/andrew.jpg) -9. 1991年:Linus Torvalds就读于芬兰赫尔辛基大学期间,尝试在Minix上做一些开发工作,但因为Minix只是作为教学用途的操作系统,功能并不强大,为了方便在学校的主机的新闻组和邮件系统中读写和下载文件,Linus编写了磁盘驱动程序和文件系统,这些成为了Linux系统内核的雏形。 +9. 1991年:Linus Torvalds就读于芬兰赫尔辛基大学期间,尝试在Minix上做一些开发工作,但因为Minix只是作为教学用途的操作系统,功能并不强大,为了方便在学校的新闻组和邮件系统中读写和下载文件,Linus编写了磁盘驱动程序和文件系统,这些东西形成了Linux系统内核的雏形。 - ![](./res/linus-torvalds.png) + ![](./res/linus.png) 下图是Unix操作系统家族的图谱。 @@ -63,7 +67,7 @@ Linux内核是芬兰人Linus Torvalds开发的,于1991年9月发布。而Linux ### Linux系统优点 1. 通用操作系统,不跟特定的硬件绑定。 -2. 用C语言编写,有可移植性,有内核编程接口。 +2. 用C语言编写,可移植性强,有内核编程接口。 3. 支持多用户和多任务,支持安全的分层文件系统。 4. 大量的实用程序,完善的网络功能以及强大的支持文档。 5. 可靠的安全性和良好的稳定性,对开发者更友好。 @@ -85,7 +89,7 @@ Linux系统的命令通常都是如下所示的格式: 命令名称 [命名参数] [命令对象] ``` -1. 获取登录信息 - **w** / **who** / **last**。 +1. 获取登录信息 - **w** / **who** / **last**/ **lastb**。 ```Shell [root@izwz97tbgo9lkabnat2lo8z ~]# w @@ -98,11 +102,21 @@ Linux系统的命令通常都是如下所示的格式: jackfrued pts/1 2018-04-12 23:26 (182.139.66.250) [root@izwz97tbgo9lkabnat2lo8z ~]# who am i root pts/0 2018-04-12 23:03 (182.139.66.250) + [root@izwz97tbgo9lkabnat2lo8z ~]# who mom likes + root pts/0 2018-04-12 23:03 (182.139.66.250) + [root@izwz97tbgo9lkabnat2lo8z ~]# last + root pts/0 117.136.63.184 Sun May 26 18:57 still logged in + reboot system boot 3.10.0-957.10.1. Mon May 27 02:52 - 19:10 (-7:-42) + root pts/4 117.136.63.184 Sun May 26 18:51 - crash (08:01) + root pts/4 117.136.63.184 Sun May 26 18:49 - 18:49 (00:00) + root pts/3 117.136.63.183 Sun May 26 18:35 - crash (08:17) + root pts/2 117.136.63.183 Sun May 26 18:34 - crash (08:17) + root pts/0 117.136.63.183 Sun May 26 18:10 - crash (08:42) ``` 2. 查看自己使用的Shell - **ps**。 - Shell也被称为“壳”,它是用户与内核交流的翻译官,简单的说就是人与计算机交互的接口。目前很多Linux系统默认的Shell都是bash(Bourne Again SHell),因为它可以使用Tab键进行命令补全、可以保存历史命令、可以方便的配置环境变量以及执行批处理操作等。 + Shell也被称为“壳”或“壳程序”,它是用户与操作系统内核交流的翻译官,简单的说就是人与计算机交互的界面和接口。目前很多Linux系统默认的Shell都是bash(Bourne Again SHell),因为它可以使用tab键进行命令和路径补全、可以保存历史命令、可以方便的配置环境变量以及执行批处理操作。 ```Shell [root@izwz97tbgo9lkabnat2lo8z ~]# ps @@ -111,18 +125,13 @@ Linux系统的命令通常都是如下所示的格式: 3553 pts/0 00:00:00 ps ``` -3. 查看命令的说明 - **whatis**。 +3. 查看命令的说明和位置 - **whatis** / **which** / **whereis**。 ```Shell [root@izwz97tbgo9lkabnat2lo8z ~]# whatis ps ps (1) - report a snapshot of the current processes. [root@izwz97tbgo9lkabnat2lo8z ~]# whatis python python (1) - an interpreted, interactive, object-oriented programming language - ``` - -4. 查看命令的位置 - **which** / **whereis**。 - - ```Shell [root@izwz97tbgo9lkabnat2lo8z ~]# whereis ps ps: /usr/bin/ps /usr/share/man/man1/ps.1.gz [root@izwz97tbgo9lkabnat2lo8z ~]# whereis python @@ -133,7 +142,9 @@ Linux系统的命令通常都是如下所示的格式: /usr/bin/python ``` -5. 查看帮助文档 - **man** / **info** / **apropos**。 +4. 清除屏幕上显示的内容 - **clear**。 + +5. 查看帮助文档 - **man** / **info** / **help** / **apropos**。 ```Shell [root@izwz97tbgo9lkabnat2lo8z ~]# ps --help Usage: @@ -150,47 +161,9 @@ Linux系统的命令通常都是如下所示的格式: ps [options] DESCRIPTION ... - [root@izwz97tbgo9lkabnat2lo8z ~]# info ps - ... ``` -6. 切换用户 - **su**。 - - ```Shell - [root@izwz97tbgo9lkabnat2lo8z ~]# su hellokitty - [hellokitty@izwz97tbgo9lkabnat2lo8z root]$ - ``` - -7. 以管理员身份执行命令 - **sudo**。 - - ```Shell - [jackfrued@izwz97tbgo9lkabnat2lo8z ~]$ ls /root - ls: cannot open directory /root: Permission denied - [jackfrued@izwz97tbgo9lkabnat2lo8z ~]$ sudo ls /root - [sudo] password for jackfrued: - calendar.py code error.txt hehe hello.c index.html myconf result.txt - ``` - - > **说明**:如果希望用户能够以管理员身份执行命令,用户必须被添加到sudoers名单中,该文件在 `/etc`目录下。 - -8. 登入登出相关 - **logout** / **exit** / **adduser** / **userdel** / **passwd** / **ssh**。 - - ```Shell - [root@izwz97tbgo9lkabnat2lo8z ~]# adduser hellokitty - [root@izwz97tbgo9lkabnat2lo8z ~]# passwd hellokitty - Changing password for user jackfrued. - New password: - Retype new password: - passwd: all authentication tokens updated successfully. - [root@izwz97tbgo9lkabnat2lo8z ~]# ssh hellokitty@1.2.3.4 - hellokitty@1.2.3.4's password: - Last login: Thu Apr 12 23:05:32 2018 from 10.12.14.16 - [hellokitty@izwz97tbgo9lkabnat2lo8z ~]$ logout - Connection to 1.2.3.4 closed. - [root@izwz97tbgo9lkabnat2lo8z ~]# - ``` - -9. 查看系统和主机名 - **uname** / **hostname**。 +6. 查看系统和主机名 - **uname** / **hostname**。 ```Shell [root@izwz97tbgo9lkabnat2lo8z ~]# uname @@ -198,30 +171,80 @@ Linux系统的命令通常都是如下所示的格式: [root@izwz97tbgo9lkabnat2lo8z ~]# hostname izwz97tbgo9lkabnat2lo8z [root@iZwz97tbgo9lkabnat2lo8Z ~]# cat /etc/centos-release - CentOS Linux release 7.4.1708 (Core) + CentOS Linux release 7.6.1810 (Core) ``` -10. 重启和关机 - **reboot** / **init 6** / **shutdown** / **init 0**。 + > 说明:`cat`是连接文件内容并打印到标准输出的命令,后面会讲到该命令;`/etc`是Linux系统上的一个非常重要的目录,它保存了很多的配置文件;`centos-release`是该目录下的一个文件,因为我自己使用的Linux发行版本是CentOS 7.6,因此这里会有一个这样的文件。 -11. 查看历史命令 - **history**。 +7. 时间和日期 - **date** / **cal**。 - ```Shell - [root@iZwz97tbgo9lkabnat2lo8Z ~]# history - ... - 452 ls - 453 cd Python-3.6.5/ - 454 clear - 455 history - [root@iZwz97tbgo9lkabnat2lo8Z ~]# !454 - ``` + ```Shell + [root@iZwz97tbgo9lkabnat2lo8Z ~]# date + Wed Jun 20 12:53:19 CST 2018 + [root@iZwz97tbgo9lkabnat2lo8Z ~]# cal + June 2018 + Su Mo Tu We Th Fr Sa + 1 2 + 3 4 5 6 7 8 9 + 10 11 12 13 14 15 16 + 17 18 19 20 21 22 23 + 24 25 26 27 28 29 30 + [root@iZwz97tbgo9lkabnat2lo8Z ~]# cal 5 2017 + May 2017 + Su Mo Tu We Th Fr Sa + 1 2 3 4 5 6 + 7 8 9 10 11 12 13 + 14 15 16 17 18 19 20 + 21 22 23 24 25 26 27 + 28 29 30 31 + ``` - > 说明:查看到历史命令之后,可以用`!历史命令编号`来重新执行该命令;通过`history -c`可以清除历史命令。 +8. 重启和关机 - **reboot** / **shutdown**。 + + ```Shell + [root@iZwz97tbgo9lkabnat2lo8Z ~]# shutdown -h +5 + Shutdown scheduled for Sun 2019-05-26 19:34:27 CST, use 'shutdown -c' to cancel. + [root@izwz97tbgo9lkabnat2lo8z ~]# + Broadcast message from root@izwz97tbgo9lkabnat2lo8z (Sun 2019-05-26 19:29:27 CST): + + The system is going down for power-off at Sun 2019-05-26 19:34:27 CST! + [root@izwz97tbgo9lkabnat2lo8z ~]# shutdown -c + + Broadcast message from root@izwz97tbgo9lkabnat2lo8z (Sun 2019-05-26 19:30:22 CST): + + The system shutdown has been cancelled at Sun 2019-05-26 19:31:22 CST! + [root@izwz97tbgo9lkabnat2lo8z ~]# shutdown -r 23:58 + Shutdown scheduled for Sun 2019-05-26 23:58:00 CST, use 'shutdown -c' to cancel. + [root@izwz97tbgo9lkabnat2lo8z ~]# shutdown -c + + Broadcast message from root@izwz97tbgo9lkabnat2lo8z (Sun 2019-05-26 19:31:06 CST): + + The system shutdown has been cancelled at Sun 2019-05-26 19:32:06 CST! + ``` + + > 说明:在执行`shutdown`命令时会向登录系统的用户发出警告,可以在命令后面跟上警告消息来替换默认的警告消息,也可以在`-h`参数后通过`now`来表示立刻关机。 + +9. 退出登录 - **exit** / **logout**。 + +10. 查看历史命令 - **history**。 + + ```Shell + [root@iZwz97tbgo9lkabnat2lo8Z ~]# history + ... + 452 ls + 453 cd Python-3.6.5/ + 454 clear + 455 history + [root@iZwz97tbgo9lkabnat2lo8Z ~]# !454 + ``` + + > 说明:查看到历史命令之后,可以用`!历史命令编号`来重新执行该命令;通过`history -c`可以清除历史命令。 ### 实用程序 #### 文件和文件夹操作 -1. 创建/删除目录 - **mkdir** / **rmdir**。 +1. 创建/删除空目录 - **mkdir** / **rmdir**。 ```Shell [root@iZwz97tbgo9lkabnat2lo8Z ~]# mkdir abc @@ -239,28 +262,28 @@ Linux系统的命令通常都是如下所示的格式: [root@iZwz97tbgo9lkabnat2lo8Z ~]# rm -rf xyz ``` - - touch命令用于创建空白文件或修改文件时间。在Linux系统中一个文件有三种时间: + - `touch`命令用于创建空白文件或修改文件时间。在Linux系统中一个文件有三种时间: - 更改内容的时间 - mtime。 - 更改权限的时间 - ctime。 - 最后访问时间 - atime。 - - rm的几个重要参数: - - -i:交互式删除,每个删除项都会进行询问。 - - -r:删除目录并递归的删除目录中的文件和目录。 - - -f:强制删除,忽略不存在的文件,没有任何提示。 + - `rm`的几个重要参数: + - `-i`:交互式删除,每个删除项都会进行询问。 + - `-r`:删除目录并递归的删除目录中的文件和目录。 + - `-f`:强制删除,忽略不存在的文件,没有任何提示。 3. 切换和查看当前工作目录 - **cd** / **pwd**。 - > 说明:`cd`命令后面可以跟相对路径(以当前路径作为参照)或绝对路径(以`/`开头)来切换到指定的目录,也可以用`cd ..`来返回上一级目录。 + > 说明:`cd`命令后面可以跟相对路径(以当前路径作为参照)或绝对路径(以`/`开头)来切换到指定的目录,也可以用`cd ..`来返回上一级目录。请大家想一想,如果要返回到上上一级目录应该给`cd`命令加上什么样的参数呢? 4. 查看目录内容 - **ls**。 - - -l:以长格式查看文件和目录。 - - -a:显示以点开头的文件和目录(隐藏文件)。 - - -R:遇到目录要进行递归展开(继续列出目录下面的文件和目录)。 - - -d:只列出目录,不列出其他内容。 - - -S/-t:按大小/时间排序。 + - `-l`:以长格式查看文件和目录。 + - `-a`:显示以点开头的文件和目录(隐藏文件)。 + - `-R`:遇到目录要进行递归展开(继续列出目录下面的文件和目录)。 + - `-d`:只列出目录,不列出其他内容。 + - `-S` / `-t`:按大小/时间排序。 -5. 查看文件内容 - **cat** / **head** / **tail** / **more** / **less**。 +5. 查看文件内容 - **cat** / **tac** / **head** / **tail** / **more** / **less** / **rev** / **od**。 ```Shell [root@iZwz97tbgo9lkabnat2lo8Z ~]# wget http://www.sohu.com/ -O sohu.html @@ -293,6 +316,8 @@ Linux系统的命令通常都是如下所示的格式: ... ``` + > 说明:上面用到了一个名为`wget`的命令,它是一个网络下载器程序,可以从指定的URL下载资源。 + 6. 拷贝/移动文件 - **cp** / **mv**。 ```Shell @@ -306,7 +331,13 @@ Linux系统的命令通常都是如下所示的格式: sohu_index.html ``` -7. 查找文件和查找内容 - **find** / **grep**。 +7. 文件重命名 - **rename**。 + + ```Shell + [root@iZwz97tbgo9lkabnat2lo8Z ~]# rename .htm .html *.htm + ``` + +8. 查找文件和查找内容 - **find** / **grep**。 ```Shell [root@iZwz97tbgo9lkabnat2lo8Z ~]# find / -name "*.html" @@ -329,7 +360,7 @@ Linux系统的命令通常都是如下所示的格式: ``` > 说明:`grep`在搜索字符串时可以使用正则表达式,如果需要使用正则表达式可以用`grep -E`或者直接使用`egrep`。 -8. 链接 - **ln**。 +9. 创建链接和查看链接 - **ln** / **readlink**。 ```Shell [root@iZwz97tbgo9lkabnat2lo8Z ~]# ls -l sohu.html @@ -351,23 +382,28 @@ Linux系统的命令通常都是如下所示的格式: > 说明:链接可以分为硬链接和软链接(符号链接)。硬链接可以认为是一个指向文件数据的指针,就像Python中对象的引用计数,每添加一个硬链接,文件的对应链接数就增加1,只有当文件的链接数为0时,文件所对应的存储空间才有可能被其他文件覆盖。我们平常删除文件时其实并没有删除硬盘上的数据,我们删除的只是一个指针,或者说是数据的一条使用记录,所以类似于“文件粉碎机”之类的软件在“粉碎”文件时除了删除文件指针,还会在文件对应的存储区域填入数据来保证文件无法再恢复。软链接类似于Windows系统下的快捷方式,当软链接链接的文件被删除时,软链接也就失效了。 -9. 压缩/解压缩和归档/解归档 - **gzip** / **gunzip** / **xz** / **tar**。 +10. 压缩/解压缩和归档/解归档 - **gzip** / **gunzip** / **xz**。 + + ```Shell + [root@iZwz97tbgo9lkabnat2lo8Z ~]# wget http://download.redis.io/releases/redis-4.0.10.tar.gz + --2018-06-20 19:29:59-- http://download.redis.io/releases/redis-4.0.10.tar.gz + Resolving download.redis.io (download.redis.io)... 109.74.203.151 + Connecting to download.redis.io (download.redis.io)|109.74.203.151|:80... connected. + HTTP request sent, awaiting response... 200 OK + Length: 1738465 (1.7M) [application/x-gzip] + Saving to: ‘redis-4.0.10.tar.gz’ + 100%[==================================================>] 1,738,465 70.1KB/s in 74s + 2018-06-20 19:31:14 (22.9 KB/s) - ‘redis-4.0.10.tar.gz’ saved [1738465/1738465] + [root@iZwz97tbgo9lkabnat2lo8Z ~]# ls redis* + redis-4.0.10.tar.gz + [root@iZwz97tbgo9lkabnat2lo8Z ~]# gunzip redis-4.0.10.tar.gz + [root@iZwz97tbgo9lkabnat2lo8Z ~]# ls redis* + redis-4.0.10.tar + ``` + +11. 归档和解归档 - **tar**。 ```Shell - [root@iZwz97tbgo9lkabnat2lo8Z ~]# wget http://download.redis.io/releases/redis-4.0.10.tar.gz - --2018-06-20 19:29:59-- http://download.redis.io/releases/redis-4.0.10.tar.gz - Resolving download.redis.io (download.redis.io)... 109.74.203.151 - Connecting to download.redis.io (download.redis.io)|109.74.203.151|:80... connected. - HTTP request sent, awaiting response... 200 OK - Length: 1738465 (1.7M) [application/x-gzip] - Saving to: ‘redis-4.0.10.tar.gz’ - 100%[==================================================>] 1,738,465 70.1KB/s in 74s - 2018-06-20 19:31:14 (22.9 KB/s) - ‘redis-4.0.10.tar.gz’ saved [1738465/1738465] - [root@iZwz97tbgo9lkabnat2lo8Z ~]# ls redis* - redis-4.0.10.tar.gz - [root@iZwz97tbgo9lkabnat2lo8Z ~]# gunzip redis-4.0.10.tar.gz - [root@iZwz97tbgo9lkabnat2lo8Z ~]# ls redis* - redis-4.0.10.tar [root@iZwz97tbgo9lkabnat2lo8Z ~]# tar -xvf redis-4.0.10.tar redis-4.0.10/ redis-4.0.10/.gitignore @@ -383,57 +419,76 @@ Linux系统的命令通常都是如下所示的格式: redis-4.0.10/deps/Makefile redis-4.0.10/deps/README.md ... - [root@iZwz97tbgo9lkabnat2lo8Z ~]# ls redis* - redis-4.0.10.tar - redis-4.0.10: - 00-RELEASENOTES COPYING Makefile redis.conf runtest-sentinel tests - BUGS deps MANIFESTO runtest sentinel.conf utils - CONTRIBUTING INSTALL README.md runtest-cluster src ``` -10. 其他工具 - **sort** / **uniq** / **diff** / **tr** / **cut** / **paste** / **file** / **wc**。 + > 说明:归档(也称为创建归档)和解归档都使用`tar`命令,通常创建归档需要`-cvf`三个参数,其中`c`表示创建(create),`v`表示显示创建归档详情(verbose),`f`表示指定归档的文件(file);解归档需要加上`-xvf`参数,其中`x`表示抽取(extract),其他两个参数跟创建归档相同。 - ```Shell - [root@iZwz97tbgo9lkabnat2lo8Z ~]# cat foo.txt - grape - apple - pitaya - [root@iZwz97tbgo9lkabnat2lo8Z ~]# cat bar.txt - 100 - 200 - 300 - 400 - [root@iZwz97tbgo9lkabnat2lo8Z ~]# paste foo.txt bar.txt - grape 100 - apple 200 - pitaya 300 - 400 - [root@iZwz97tbgo9lkabnat2lo8Z ~]# paste foo.txt bar.txt > hello.txt - [root@iZwz97tbgo9lkabnat2lo8Z ~]# cut -b 4-8 hello.txt - pe 10 - le 20 - aya 3 - 0 - [root@iZwz97tbgo9lkabnat2lo8Z ~]# cat hello.txt | tr '\t' ',' - grape,100 - apple,200 - pitaya,300 - ,400 - [root@iZwz97tbgo9lkabnat2lo8Z ~]# wget https://www.baidu.com/img/bd_logo1.png - --2018-06-20 18:46:53-- https://www.baidu.com/img/bd_logo1.png - Resolving www.baidu.com (www.baidu.com)... 220.181.111.188, 220.181.112.244 - Connecting to www.baidu.com (www.baidu.com)|220.181.111.188|:443... connected. - HTTP request sent, awaiting response... 200 OK - Length: 7877 (7.7K) [image/png] - Saving to: ‘bd_logo1.png’ - 100%[==================================================>] 7,877 --.-K/s in 0s - 2018-06-20 18:46:53 (118 MB/s) - ‘bd_logo1.png’ saved [7877/7877][root@iZwz97tbgo9lkabnat2lo8Z ~]# file bd_logo1.png - bd_logo1.png: PNG image data, 540 x 258, 8-bit colormap, non-interlaced - [root@iZwz97tbgo9lkabnat2lo8Z ~]# wc sohu.html - 2979 6355 212527 sohu.html - [root@iZwz97tbgo9lkabnat2lo8Z ~]# wc -l sohu.html - 2979 sohu.html - ``` +12. 将标准输入转成命令行参数 - **xargs**。 + + 下面的命令会将查找当前路径下的html文件,然后通过`xargs`将这些文件作为参数传给`rm`命令,实现查找并删除文件的操作。 + + ```Shell + [root@iZwz97tbgo9lkabnat2lo8Z ~]# find . -type f -name "*.html" | xargs rm -f + ``` + + 下面的命令将a.txt文件中的多行内容变成一行输出到b.txt文件中,其中`<`表示从a.txt中读取输入,`>`表示将命令的执行结果输出到b.txt中。 + + ```Shell + [root@iZwz97tbgo9lkabnat2lo8Z ~]# xargs < a.txt > b.txt + ``` + + > 说明:这个命令就像上面演示的那样常在管道(实现进程间通信的一种方式)和重定向(重新指定输入输出的位置)操作中用到,后面的内容中会讲到管道操作和输入输出重定向操作。 + +13. 显示文件或目录 - **basename** / **dirname**。 + +14. 其他相关工具。 + + - **sort** - 对内容排序 + - **uniq** - 去掉相邻重复内容 + - **tr** - 替换指定内容为新内容 + - **cut** / **paste** - 剪切/黏贴内容 + - **split** - 拆分文件 + - **file** - 判断文件类型 + - **wc** - 统计文件行数、单词数、字节数 + - **iconv** - 编码转换 + + ```Shell + [root@iZwz97tbgo9lkabnat2lo8Z ~]# cat foo.txt + grape + apple + pitaya + [root@iZwz97tbgo9lkabnat2lo8Z ~]# cat bar.txt + 100 + 200 + 300 + 400 + [root@iZwz97tbgo9lkabnat2lo8Z ~]# paste foo.txt bar.txt + grape 100 + apple 200 + pitaya 300 + 400 + [root@iZwz97tbgo9lkabnat2lo8Z ~]# paste foo.txt bar.txt > hello.txt + [root@iZwz97tbgo9lkabnat2lo8Z ~]# cut -b 4-8 hello.txt + pe 10 + le 20 + aya 3 + 0 + [root@iZwz97tbgo9lkabnat2lo8Z ~]# cat hello.txt | tr '\t' ',' + grape,100 + apple,200 + pitaya,300 + ,400 + [root@izwz97tbgo9lkabnat2lo8z ~]# split -l 100 sohu.html hello + [root@iZwz97tbgo9lkabnat2lo8Z ~]# wget https://www.baidu.com/img/bd_logo1.png + [root@iZwz97tbgo9lkabnat2lo8Z ~]# file bd_logo1.png + bd_logo1.png: PNG image data, 540 x 258, 8-bit colormap, non-interlaced + [root@iZwz97tbgo9lkabnat2lo8Z ~]# wc sohu.html + 2979 6355 212527 sohu.html + [root@iZwz97tbgo9lkabnat2lo8Z ~]# wc -l sohu.html + 2979 sohu.html + [root@iZwz97tbgo9lkabnat2lo8Z ~]# wget http://www.qq.com -O qq.html + [root@iZwz97tbgo9lkabnat2lo8Z ~]# iconv -f gb2312 -t utf-8 qq.html + ``` #### 管道和重定向 @@ -501,6 +556,14 @@ Linux系统的命令通常都是如下所示的格式: I will show you some code. ``` +4. 多重定向 - **tee**。 + + 下面的命令除了在终端显示命令`ls`的结果之外,还会追加输出到`ls.txt`文件中。 + + ```Shell + [root@iZwz97tbgo9lkabnat2lo8Z ~]# ls | tee -a ls.txt + ``` + #### 别名 1. **alias** @@ -523,35 +586,256 @@ Linux系统的命令通常都是如下所示的格式: -bash: frm: command not found ``` -#### 其他程序 +#### 文本处理 -1. 时间和日期 - **date** / **cal**。 +1. 字符流编辑器 - **sed**。 + + sed是操作、过滤和转换文本内容的工具。假设有一个名为fruit.txt的文件,内容如下所示。 ```Shell - [root@iZwz97tbgo9lkabnat2lo8Z ~]# date - Wed Jun 20 12:53:19 CST 2018 - [root@iZwz97tbgo9lkabnat2lo8Z ~]# cal - June 2018 - Su Mo Tu We Th Fr Sa - 1 2 - 3 4 5 6 7 8 9 - 10 11 12 13 14 15 16 - 17 18 19 20 21 22 23 - 24 25 26 27 28 29 30 - [root@iZwz97tbgo9lkabnat2lo8Z ~]# cal 5 2017 - May 2017 - Su Mo Tu We Th Fr Sa - 1 2 3 4 5 6 - 7 8 9 10 11 12 13 - 14 15 16 17 18 19 20 - 21 22 23 24 25 26 27 - 28 29 30 31 + [root@izwz97tbgo9lkabnat2lo8z ~]# cat -n fruit.txt + 1 banana + 2 grape + 3 apple + 4 watermelon + 5 orange ``` -2. 录制操作脚本 - **script**。 + 接下来,我们在第2行后面添加一个pitaya。 -3. 给用户发送消息 - **mesg** / **write** / **wall** / **mail**。 + ```Shell + [root@izwz97tbgo9lkabnat2lo8z ~]# sed '2a pitaya' fruit.txt + banana + grape + pitaya + apple + watermelon + orange + ``` + > 注意:刚才的命令和之前我们讲过的很多命令一样并没有改变fruit.txt文件,而是将添加了新行的内容输出到终端中,如果想保存到fruit.txt中,可以使用输出重定向操作。 + + 在第2行前面插入一个waxberry。 + + ```Shell + [root@izwz97tbgo9lkabnat2lo8z ~]# sed '2i waxberry' fruit.txt + banana + waxberry + grape + apple + watermelon + orange + ``` + + 删除第3行。 + + ```Shell + [root@izwz97tbgo9lkabnat2lo8z ~]# sed '3d' fruit.txt + banana + grape + watermelon + orange + ``` + + 删除第2行到第4行。 + + ```Shell + [root@izwz97tbgo9lkabnat2lo8z ~]# sed '2,4d' fruit.txt + banana + orange + ``` + + 将文本中的字符a替换为@。 + + ```Shell + [root@izwz97tbgo9lkabnat2lo8z ~]# sed 's#a#@#' fruit.txt + b@nana + gr@pe + @pple + w@termelon + or@nge + ``` + + 将文本中的字符a替换为@,使用全局模式。 + + ```Shell + [root@izwz97tbgo9lkabnat2lo8z ~]# sed 's#a#@#g' fruit.txt + b@n@n@ + gr@pe + @pple + w@termelon + or@nge + ``` + +2. 模式匹配和处理语言 - **awk**。 + + awk是一种编程语言,也是Linux系统中处理文本最为强大的工具,它的作者之一和现在的维护者就是之前提到过的Brian Kernighan(ken和dmr最亲密的伙伴)。通过该命令可以从文本中提取出指定的列、用正则表达式从文本中取出我们想要的内容、显示指定的行以及进行统计和运算,总之它非常强大。 + + 假设有一个名为fruit2.txt的文件,内容如下所示。 + + ```Shell + [root@izwz97tbgo9lkabnat2lo8z ~]# cat fruit2.txt + 1 banana 120 + 2 grape 500 + 3 apple 1230 + 4 watermelon 80 + 5 orange 400 + ``` + + 显示文件的第3行。 + + ```Shell + [root@izwz97tbgo9lkabnat2lo8z ~]# awk 'NR==3' fruit2.txt + 3 apple 1230 + ``` + + 显示文件的第2列。 + + ```Shell + [root@izwz97tbgo9lkabnat2lo8z ~]# awk '{print $2}' fruit2.txt + banana + grape + apple + watermelon + orange + ``` + + 显示文件的最后一列。 + + ```Shell + [root@izwz97tbgo9lkabnat2lo8z ~]# awk '{print $NF}' fruit2.txt + 120 + 500 + 1230 + 80 + 400 + ``` + + 输出末尾数字大于等于300的行。 + + ```Shell + [root@izwz97tbgo9lkabnat2lo8z ~]# awk '{if($3 >= 300) {print $0}}' fruit2.txt + 2 grape 500 + 3 apple 1230 + 5 orange 400 + ``` + + 上面展示的只是awk命令的冰山一角,更多的内容留给读者自己在实践中去探索。 + +### 用户管理 + +1. 创建和删除用户 - **useradd** / **userdel**。 + + ```Shell + [root@izwz97tbgo9lkabnat2lo8z home]# useradd hellokitty + [root@izwz97tbgo9lkabnat2lo8z home]# userdel hellokitty + ``` + + - `-d` - 创建用户时为用户指定用户主目录 + - `-g` - 创建用户时指定用户所属的用户组 + +2. 创建和删除用户组 - **groupadd** / **groupdel**。 + + > 说明:用户组主要是为了方便对一个组里面所有用户的管理。 + +3. 修改密码 - **passwd**。 + + ```Shell + [root@izwz97tbgo9lkabnat2lo8z ~]# passwd hellokitty + New password: + Retype new password: + passwd: all authentication tokens updated successfully. + ``` + + > 说明:输入密码和确认密码没有回显且必须一气呵成的输入完成(不能使用退格键),密码和确认密码需要一致。如果使用`passwd`命令时没有指定命令作用的对象,则表示要修改当前用户的密码。如果想批量修改用户密码,可以使用`chpasswd`命令。 + + - `-l` / `-u` - 锁定/解锁用户。 + - `-d` - 清除用户密码。 + - `-e` - 设置密码立即过期,用户登录时会强制要求修改密码。 + - `-i` - 设置密码过期多少天以后禁用该用户。 + +4. 查看和修改密码有效期 - **chage**。 + + 设置hellokitty用户100天后必须修改密码,过期前15天通知该用户,过期后15天禁用该用户。 + + ```Shell + chage -M 100 -W 15 -I 15 hellokitty + ``` + +5. 切换用户 - **su**。 + + ```Shell + [root@izwz97tbgo9lkabnat2lo8z ~]# su hellokitty + [hellokitty@izwz97tbgo9lkabnat2lo8z root]$ + ``` + +6. 以管理员身份执行命令 - **sudo**。 + + ```Shell + [hellokitty@izwz97tbgo9lkabnat2lo8z ~]$ ls /root + ls: cannot open directory /root: Permission denied + [hellokitty@izwz97tbgo9lkabnat2lo8z ~]$ sudo ls /root + [sudo] password for hellokitty: + ``` + + > **说明**:如果希望用户能够以管理员身份执行命令,用户必须要出现在sudoers名单中,sudoers文件在 `/etc`目录下,如果希望直接编辑该文件也可以使用下面的命令。 + +7. 编辑sudoers文件 - **visudo**。 + + 这里使用的编辑器是vi,关于vi的知识在后面有讲解。该文件的部分内容如下所示: + + ``` + ## Allow root to run any commands anywhere + root ALL=(ALL) ALL + + ## Allows members of the 'sys' group to run networking, software, + ## service management apps and more. + # %sys ALL = NETWORKING, SOFTWARE, SERVICES, STORAGE, DELEGATING, PROCESSES, LOCATE, DRIVERS + ## Allows people in group wheel to run all commands + %wheel ALL=(ALL) ALL + + ## Same thing without a password + # %wheel ALL=(ALL) NOPASSWD: ALL + + ## Allows members of the users group to mount and unmount the + ## cdrom as root + # %users ALL=/sbin/mount /mnt/cdrom, /sbin/umount /mnt/cdrom + + ## Allows members of the users group to shutdown this system + # %users localhost=/sbin/shutdown -h now + ``` + +8. 显示用户与用户组的信息 - **id**。 + +9. 给其他用户发消息 -**write** / **wall**。 + + 发送方: + + ```Shell + [root@izwz97tbgo9lkabnat2lo8z ~]# write hellokitty + Dinner is on me. + Call me at 6pm. + ``` + + 接收方: + + ```Shell + [hellokitty@izwz97tbgo9lkabnat2lo8z ~]$ + Message from root@izwz97tbgo9lkabnat2lo8z on pts/0 at 17:41 ... + Dinner is on me. + Call me at 6pm. + EOF + ``` + +10. 查看/设置是否接收其他用户发送的消息 - **mesg**。 + + ```Shell + [hellokitty@izwz97tbgo9lkabnat2lo8z ~]$ mesg + is y + [hellokitty@izwz97tbgo9lkabnat2lo8z ~]$ mesg n + [hellokitty@izwz97tbgo9lkabnat2lo8z ~]$ mesg + is n + ``` ### 文件系统 @@ -623,6 +907,8 @@ Linux系统的命令通常都是如下所示的格式: ... ``` +3. **chgrp** - 改变用户组。 + #### 磁盘管理 1. 列出文件系统的磁盘使用状况 - **df**。 @@ -656,11 +942,27 @@ Linux系统的命令通常都是如下所示的格式: I/O size (minimum/optimal): 512 bytes / 512 bytes ``` -3. 格式化文件系统 - **mkfs**。 +3. 磁盘分区工具 - **parted**。 -4. 文件系统检查 - **fsck**。 +4. 格式化文件系统 - **mkfs**。 -5. 挂载/卸载 - **mount** / **umount**。 + ```Shell + [hellokitty@izwz97tbgo9lkabnat2lo8z ~]$ mkfs -t ext4 -v /dev/sdb + ``` + + - `-t` - 指定文件系统的类型。 + - `-c` - 创建文件系统时检查磁盘损坏情况。 + - `-v` - 显示详细信息。 + +5. 文件系统检查 - **fsck**。 + +6. 转换或拷贝文件 - **dd**。 + +7. 挂载/卸载 - **mount** / **umount**。 + +8. 创建/激活/关闭交换分区 - **mkswap** / **swapon** / **swapoff**。 + +> 说明:执行上面这些命令会带有一定的风险,如果不清楚这些命令的用法,最好不用随意使用,在使用的过程中,最好对照参考资料进行操作,并在操作前确认是否要这么做。 ### 编辑器 - vim @@ -708,7 +1010,7 @@ Linux系统的命令通常都是如下所示的格式: - 设置启用/关闭搜索结果高亮:`set hls` / `set nohls` - > 说明:如果希望上面的这些设定在每次启动vim时都能生效,需要将这些设定写到用户主目录下的.vimrc文件中。 + > 说明:如果希望上面的这些设定在每次启动vim时都能自动生效,需要将这些设定写到用户主目录下的.vimrc文件中。 8. 高级技巧 @@ -754,7 +1056,7 @@ Linux系统的命令通常都是如下所示的格式: - 通过`@a`(`a`是刚才使用的寄存器的名字)播放宏,如果要多次执行宏可以在前面加数字,例如`100@a`表示将宏播放100次。 - - 可以试一试下面的例子来体验录制宏的操作,该例子来源于[Harttle Land网站](https://harttle.land/tags.html#Vim),该网站上提供了很多关于vim的使用技巧,有兴趣的可以去了解一下。 + - 可以试一试下面的例子来体验录制宏的操作,该例子来源于[Harttle Land网站](https://harttle.land/tags.html#Vim),该网站上提供了很多关于vim的使用技巧,有兴趣的可以了解一下。 ![](./res/vim-macro.png) @@ -816,11 +1118,10 @@ nginx version: nginx/1.12.2 移除Nginx。 ```Shell -[root@iZwz97tbgo9lkabnat2lo8Z ~]# nginx -s stop [root@iZwz97tbgo9lkabnat2lo8Z ~]# yum -y remove nginx ``` -下面以MySQL为例,演示如何使用rpm安装软件。要安装MySQL需要先到[MySQL官方网站](https://www.mysql.com/)下载对应的[RPM文件](https://dev.mysql.com/downloads/mysql/),当然要选择和你使用的Linux系统对应的版本。MySQL现在是Oracle公司旗下的产品,在MySQL被收购后,MySQL的作者重新制作了一个MySQL的分支MariaDB,可以通过yum进行安装。如果要安装MySQL需要先通过yum删除`mariadb-libs`这个可能会跟MySQL底层库冲突的库,然后还需要安装一个名为`libaio`的依赖库。 +下面以MySQL为例,演示如何使用rpm安装软件。要安装MySQL需要先到[MySQL官方网站](https://www.mysql.com/)下载对应的[RPM文件](https://dev.mysql.com/downloads/mysql/),当然要选择和你使用的Linux系统对应的版本。MySQL现在是Oracle公司旗下的产品,在MySQL被收购后,MySQL的作者重新制作了一个MySQL的分支MariaDB,可以通过yum进行安装。 ```Shell [root@iZwz97tbgo9lkabnat2lo8Z mysql]# ls @@ -830,13 +1131,17 @@ mysql-community-libs-5.7.22-1.el7.x86_64.rpm mysql-community-server-5.7.22-1.el7.x86_64.rpm [root@iZwz97tbgo9lkabnat2lo8Z mysql]# yum -y remove mariadb-libs [root@iZwz97tbgo9lkabnat2lo8Z mysql]# yum -y install libaio -[root@iZwz97tbgo9lkabnat2lo8Z mysql]# ls | xargs rpm -ivh -warning: mysql-community-client-5.7.22-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY -Preparing... ################################# [100%] +[root@iZwz97tbgo9lkabnat2lo8Z mysql]#rpm -ivh mysql-community-common-5.7.26-1.el7.x86_64.rpm +... +[root@iZwz97tbgo9lkabnat2lo8Z mysql]#rpm -ivh mysql-community-libs-5.7.26-1.el7.x86_64.rpm +... +[root@iZwz97tbgo9lkabnat2lo8Z mysql]#rpm -ivh mysql-community-client-5.7.26-1.el7.x86_64.rpm +... +[root@iZwz97tbgo9lkabnat2lo8Z mysql]#rpm -ivh mysql-community-server-5.7.26-1.el7.x86_64.rpm ... ``` -> 说明:由于MySQL和[MariaDB](https://mariadb.org/)的底层依赖库是有冲突的,所以上面我们首先用`yum`移除了名为mariadb-libs的依赖库并安装了名为libaio的依赖库。由于我们将安装MySQL所需的rpm文件放在一个独立的目录中,所以可以通过`ls`命令查看到安装文件并用`xargs`将`ls`的输出作为参数交给`rpm -ivh`来进行安装。关于MySQL和MariaDB之间的关系,可以阅读[维基百科](https://zh.wikipedia.org/wiki/MariaDB)上关于MariaDB的介绍。 +> 说明:由于MySQL和[MariaDB](https://mariadb.org/)的底层依赖库是有冲突的,所以上面我们首先用`yum`移除了名为mariadb-libs的依赖库并安装了名为libaio支持异步I/O操作的依赖库。关于MySQL和MariaDB之间的关系,可以阅读[维基百科](https://zh.wikipedia.org/wiki/MariaDB)上关于MariaDB的介绍。 移除安装的MySQL。 @@ -921,7 +1226,7 @@ build environment: [root@iZwz97tbgo9lkabnat2lo8Z ~]# ./configure --prefix=/usr/local/python36 --enable-optimizations [root@iZwz97tbgo9lkabnat2lo8Z ~]# yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel [root@iZwz97tbgo9lkabnat2lo8Z ~]# make && make install - ... 配置环境变量 ... + ... [root@iZwz97tbgo9lkabnat2lo8Z ~]# ln -s /usr/local/python36/bin/python3.6 /usr/bin/python3 [root@iZwz97tbgo9lkabnat2lo8Z ~]# python3 --version Python 3.6.5 @@ -929,6 +1234,8 @@ build environment: [root@iZwz97tbgo9lkabnat2lo8Z ~]# pip3 --version ``` + > 说明:上面在安装好Python之后还需要注册PATH环境变量,将Python安装路径下bin文件夹的绝对路径注册到PATH环境变量中。注册环境变量可以修改用户主目录下的.bash_profile或者/etc目录下的profile文件,二者的区别在于前者相当于是用户环境变量,而后者相当于是系统环境变量。 + 2. 安装Redis-3.2.12。 ```Shell @@ -945,31 +1252,33 @@ build environment: ### 配置服务 -1. 启动服务。 +我们可以Linux系统下安装和配置各种服务,也就是说我们可以把Linux系统打造成数据库服务器、Web服务器、缓存服务器、文件服务器、消息队列服务器等等。Linux下的大多数服务都被设置为守护进程(驻留在系统后台运行,但不会因为服务还在运行而导致Linux无法停止运行),所以我们安装的服务通常名字后面都有一个字母`d`,它是英文单词`daemon`的缩写,例如:防火墙服务叫firewalld,我们之前安装的MySQL服务叫mysqld,Apache服务器叫httpd等。在安装好服务之后,可以使用`systemctl`命令或`service`命令来完成对服务的启动、停止等操作,具体操作如下所示。 + +1. 启动防火墙服务。 ```Shell [root@iZwz97tbgo9lkabnat2lo8Z ~]# systemctl start firewalld ``` -2. 终止服务。 +2. 终止防火墙服务。 ```Shell [root@iZwz97tbgo9lkabnat2lo8Z ~]# systemctl stop firewalld ``` -3. 重启服务。 +3. 重启防火墙服务。 ```Shell [root@iZwz97tbgo9lkabnat2lo8Z ~]# systemctl restart firewalld ``` -4. 查看服务。 +4. 查看防火墙服务状态。 ```Shell [root@iZwz97tbgo9lkabnat2lo8Z ~]# systemctl status firewalld ``` -5. 设置是否开机自启。 +5. 设置/禁用防火墙服务开机自启。 ```Shell [root@iZwz97tbgo9lkabnat2lo8Z ~]# systemctl enable firewalld @@ -982,16 +1291,44 @@ build environment: ### 计划任务 -1. **crontab**命令。 +1. 在指定的时间执行命令 + + - **at** - 将任务排队,在指定的时间执行。 + - **atq** - 查看待执行的任务队列。 + - **atrm** - 从队列中删除待执行的任务。 + + 指定3天以后下午5点要执行的任务。 + + ```Shell + [hellokitty@izwz97tbgo9lkabnat2lo8z ~]$ at 5pm+3days + at> rm -f /root/*.html + at> + job 9 at Wed Jun 5 17:00:00 2019 + ``` + + 查看待执行的任务队列。 + + ```Shell + [hellokitty@izwz97tbgo9lkabnat2lo8z ~]$ atq + 9 Wed Jun 5 17:00:00 2019 a hellokitty + ``` + + 从队列中删除指定的任务。 + + ```Shell + [hellokitty@izwz97tbgo9lkabnat2lo8z ~]$ atrm 9 + ``` + +2. 计划任务表 - **crontab**。 ```Shell [root@iZwz97tbgo9lkabnat2lo8Z ~]# crontab -e * * * * * echo "hello, world!" >> /root/hello.txt 59 23 * * * rm -f /root/*.log ``` - > 说明:输入`crontab -e`命令会打开vim来编辑Cron表达式并指定触发的任务,上面我们定制了两个计划任务,一个是每分钟向/root目录下的hello.txt中追加输出`hello, world!`;另一个是每天23时59分执行删除/root目录下以log为后缀名的文件。如果不知道Cron表达式如何书写,可以参照/etc/crontab文件中的提示(下面会讲到)或者用谷歌或百度搜索一下,也可以使用Cron表达式在线生成器来生成Cron表达式。 + > 说明:输入`crontab -e`命令会打开vim来编辑Cron表达式并指定触发的任务,上面我们定制了两个计划任务,一个是每分钟向/root目录下的hello.txt中追加输出`hello, world!`;另一个是每天23时59分执行删除/root目录下以log为后缀名的文件。如果不知道Cron表达式如何书写,可以参照/etc/crontab文件中的提示(下面会讲到)或者用谷歌搜索一下,也可以使用Cron表达式在线生成器来生成Cron表达式。 -2. crontab相关文件。 + 和crontab相关的文件在`/etc`目录下,通过修改`/etc`目录下的crontab文件也能够定制计划任务。 ```Shell [root@iZwz97tbgo9lkabnat2lo8Z ~]# cd /etc @@ -1021,19 +1358,30 @@ build environment: 14 # * * * * * user-name command to be executed ``` - 通过修改`/etc`目录下的crontab文件也能够定制计划任务。 ### 网络访问和管理 1. 安全远程连接 - **ssh**。 + ```Shell + [hellokitty@izwz97tbgo9lkabnat2lo8z ~]$ ssh root@120.77.222.217 + The authenticity of host '120.77.222.217 (120.77.222.217)' can't be established. + ECDSA key fingerprint is SHA256:BhUhykv+FvnIL03I9cLRpWpaCxI91m9n7zBWrcXRa8w. + ECDSA key fingerprint is MD5:cc:85:e9:f0:d7:07:1a:26:41:92:77:6b:7f:a0:92:65. + Are you sure you want to continue connecting (yes/no)? yes + Warning: Permanently added '120.77.222.217' (ECDSA) to the list of known hosts. + root@120.77.222.217's password: + ``` + 2. 通过网络获取资源 - **wget**。 - -b 后台下载模式 - -O 下载到指定的目录 - -r 递归下载 -3. 显示/操作网络配置(旧) - **ifconfig**。 +3. 发送和接收邮件 - **mail**。 + +4. 网络配置工具(旧) - **ifconfig**。 ```Shell [root@iZwz97tbgo9lkabnat2lo8Z ~]# ifconfig eth0 @@ -1046,7 +1394,7 @@ build environment: TX errors 0 dropped 0 overruns 0 carrier 0 collisions ``` -4. 显示/操作网络配置(新) - **ip**。 +5. 网络配置工具(新) - **ip**。 ```Shell [root@iZwz97tbgo9lkabnat2lo8Z ~]# ip address @@ -1060,7 +1408,7 @@ build environment: valid_lft forever preferred_lft forever ``` -5. 网络可达性检查 - **ping**。 +6. 网络可达性检查 - **ping**。 ```Shell [root@iZwz97tbgo9lkabnat2lo8Z ~]# ping www.baidu.com -c 3 @@ -1073,48 +1421,56 @@ build environment: rtt min/avg/max/mdev = 36.392/36.406/36.427/0.156 ms ``` -6. 查看网络服务和端口 - **netstat**。 +7. 显示或管理路由表 - **route**。 + +8. 查看网络服务和端口 - **netstat** / **ss**。 ```Shell [root@iZwz97tbgo9lkabnat2lo8Z ~]# netstat -nap | grep nginx ``` -7. 安全文件拷贝 - **scp**。 +9. 网络监听抓包 - **tcpdump**。 + +10. 安全文件拷贝 - **scp**。 ```Shell [root@iZwz97tbgo9lkabnat2lo8Z ~]# scp root@1.2.3.4:/root/guido.jpg hellokitty@4.3.2.1:/home/hellokitty/pic.jpg ``` -8. 安全文件传输 - **sftp**。 +11. 文件同步工具 - **rsync**。 - ```Shell - [root@iZwz97tbgo9lkabnat2lo8Z ~]# sftp root@120.77.222.217 - root@120.77.222.217's password: - Connected to 120.77.222.217. - sftp> - ``` + > 说明:使用`rsync`可以实现文件的自动同步,这个对于文件服务器来说相当重要。关于这个命令的用法,我们在后面讲项目部署的时候为大家详细说明。 - - `help`:显示帮助信息。 +12. 安全文件传输 - **sftp**。 - - `ls`/`lls`:显示远端/本地目录列表。 + ```Shell + [root@iZwz97tbgo9lkabnat2lo8Z ~]# sftp root@120.77.222.217 + root@120.77.222.217's password: + Connected to 120.77.222.217. + sftp> + ``` - - `cd`/`lcd`:切换远端/本地路径。 + - `help`:显示帮助信息。 - - `mkdir`/`lmkdir`:创建远端/本地目录。 + - `ls`/`lls`:显示远端/本地目录列表。 - - `pwd`/`lpwd`:显示远端/本地当前工作目录。 + - `cd`/`lcd`:切换远端/本地路径。 - - `get`:下载文件。 + - `mkdir`/`lmkdir`:创建远端/本地目录。 - - `put`:上传文件。 + - `pwd`/`lpwd`:显示远端/本地当前工作目录。 - - `rm`:删除远端文件。 + - `get`:下载文件。 - - `bye`/`exit`/`quit`:退出sftp。 + - `put`:上传文件。 + + - `rm`:删除远端文件。 + + - `bye`/`exit`/`quit`:退出sftp。 ### 进程管理 -1. **ps** - 查询进程。 +1. 查看进程 - **ps**。 ```Shell [root@iZwz97tbgo9lkabnat2lo8Z ~]# ps -ef @@ -1127,9 +1483,56 @@ build environment: mysql 25257 1 0 Jun25 ? 00:00:39 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid ``` -2. **kill** - 终止进程。 +2. 显示进程状态树 - **pstree**。 + + ```Shell + [root@izwz97tbgo9lkabnat2lo8z ~]# pstree + systemd─┬─AliYunDun───18*[{AliYunDun}] + ├─AliYunDunUpdate───3*[{AliYunDunUpdate}] + ├─2*[agetty] + ├─aliyun-service───2*[{aliyun-service}] + ├─atd + ├─auditd───{auditd} + ├─dbus-daemon + ├─dhclient + ├─irqbalance + ├─lvmetad + ├─mysqld───28*[{mysqld}] + ├─nginx───2*[nginx] + ├─ntpd + ├─polkitd───6*[{polkitd}] + ├─rsyslogd───2*[{rsyslogd}] + ├─sshd───sshd───bash───pstree + ├─systemd-journal + ├─systemd-logind + ├─systemd-udevd + └─tuned───4*[{tuned}] + ``` + +3. 查找与指定条件匹配的进程 - **pgrep**。 ```Shell + [hellokitty@izwz97tbgo9lkabnat2lo8z ~]$ pgrep mysqld + 3584 + ``` + +4. 通过进程号终止进程 - **kill**。 + + ```Shell + [hellokitty@izwz97tbgo9lkabnat2lo8z ~]$ kill -l + 1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP + 6) SIGABRT 7) SIGBUS 8) SIGFPE 9) SIGKILL 10) SIGUSR1 + 11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) SIGTERM + 16) SIGSTKFLT 17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP + 21) SIGTTIN 22) SIGTTOU 23) SIGURG 24) SIGXCPU 25) SIGXFSZ + 26) SIGVTALRM 27) SIGPROF 28) SIGWINCH 29) SIGIO 30) SIGPWR + 31) SIGSYS 34) SIGRTMIN 35) SIGRTMIN+1 36) SIGRTMIN+2 37) SIGRTMIN+3 + 38) SIGRTMIN+4 39) SIGRTMIN+5 40) SIGRTMIN+6 41) SIGRTMIN+7 42) SIGRTMIN+8 + 43) SIGRTMIN+9 44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13 + 48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12 + 53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9 56) SIGRTMAX-8 57) SIGRTMAX-7 + 58) SIGRTMAX-6 59) SIGRTMAX-5 60) SIGRTMAX-4 61) SIGRTMAX-3 62) SIGRTMAX-2 + 63) SIGRTMAX-1 64) SIGRTMAX [root@iZwz97tbgo9lkabnat2lo8Z ~]# kill 1234 [root@iZwz97tbgo9lkabnat2lo8Z ~]# kill -9 1234 ``` @@ -1140,10 +1543,26 @@ build environment: ps -ef | grep redis | grep -v grep | awk '{print $2}' | xargs kill ``` -3. 将进程置于后台运行。 +5. 通过进程名终止进程 - **killall** / **pkill**。 - - `Ctrl+Z` - - `&` + 结束名为mysqld的进程。 + + ```Shell + [root@izwz97tbgo9lkabnat2lo8z ~]# pkill mysqld + ``` + + 结束hellokitty用户的所有进程。 + + ```Shell + [root@izwz97tbgo9lkabnat2lo8z ~]# pkill -u hellokitty + ``` + + > 说明:这样的操作会让hellokitty用户和服务器断开连接。 + +6. 将进程置于后台运行。 + + - `Ctrl+Z` - 快捷键,用于停止进程并置于后台。 + - `&` - 将进程置于后台运行。 ```Shell [root@iZwz97tbgo9lkabnat2lo8Z ~]# mongod & @@ -1153,7 +1572,7 @@ build environment: [4]+ Stopped redis-server ``` -4. **jobs** - 查询后台进程。 +7. 查询后台进程 - **jobs**。 ```Shell [root@iZwz97tbgo9lkabnat2lo8Z ~]# jobs @@ -1162,7 +1581,7 @@ build environment: [4]+ Stopped redis-server ``` -5. **bg** - 让进程在后台继续运行。 +8. 让进程在后台继续运行 - **bg**。 ```Shell [root@iZwz97tbgo9lkabnat2lo8Z ~]# bg %4 @@ -1173,37 +1592,92 @@ build environment: [4]- Running redis-server & ``` -6. **fg** - 将后台进程置于前台。 +9. 将后台进程置于前台 - **fg**。 ```Shell [root@iZwz97tbgo9lkabnat2lo8Z ~]# fg %4 redis-server - ^C5554:signal-handler (1530025281) Received SIGINT scheduling shutdown... - 5554:M 26 Jun 23:01:21.413 # User requested shutdown... - 5554:M 26 Jun 23:01:21.413 * Saving the final RDB snapshot before exiting. - 5554:M 26 Jun 23:01:21.415 * DB saved on disk - 5554:M 26 Jun 23:01:21.415 # Redis is now ready to exit, bye bye... ``` > 说明:置于前台的进程可以使用`Ctrl+C`来终止它。 -7. **top** - 进程监控。 +10. 调整程序/进程运行时优先级 - **nice** / **renice**。 - ```Shell - [root@iZwz97tbgo9lkabnat2lo8Z ~]# top - top - 23:04:23 up 3 days, 14:10, 1 user, load average: 0.00, 0.01, 0.05 - Tasks: 65 total, 1 running, 64 sleeping, 0 stopped, 0 zombie - %Cpu(s): 0.3 us, 0.3 sy, 0.0 ni, 99.3 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st - KiB Mem : 1016168 total, 191060 free, 324700 used, 500408 buff/cache - KiB Swap: 0 total, 0 free, 0 used. 530944 avail Mem - ... - ``` +11. 用户登出后进程继续工作 - **nohup**。 -### 系统性能 + ```Shell + [root@izwz97tbgo9lkabnat2lo8z ~]# nohup ping www.baidu.com > result.txt & + ``` -1. 查看系统活动信息 - **sar**。 +12. 跟踪进程系统调用情况 - **strace**。 -2. 查看内存使用情况 - **free**。 + ```Shell + [root@izwz97tbgo9lkabnat2lo8z ~]# pgrep mysqld + 8803 + [root@izwz97tbgo9lkabnat2lo8z ~]# strace -c -p 8803 + strace: Process 8803 attached + ^Cstrace: Process 8803 detached + % time seconds usecs/call calls errors syscall + ------ ----------- ----------- --------- --------- ---------------- + 99.18 0.005719 5719 1 restart_syscall + 0.49 0.000028 28 1 mprotect + 0.24 0.000014 14 1 clone + 0.05 0.000003 3 1 mmap + 0.03 0.000002 2 1 accept + ------ ----------- ----------- --------- --------- ---------------- + 100.00 0.005766 5 total + ``` + + > 说明:这个命令的用法和参数都比较复杂,建议大家在真正用到这个命令的时候再根据实际需要进行了解。 + +13. 查看当前运行级别 - **runlevel**。 + + ```Shell + [root@izwz97tbgo9lkabnat2lo8z ~]# runlevel + N 3 + ``` + +14. 实时监控进程占用资源状况 - **top**。 + + ```Shell + [root@iZwz97tbgo9lkabnat2lo8Z ~]# top + top - 23:04:23 up 3 days, 14:10, 1 user, load average: 0.00, 0.01, 0.05 + Tasks: 65 total, 1 running, 64 sleeping, 0 stopped, 0 zombie + %Cpu(s): 0.3 us, 0.3 sy, 0.0 ni, 99.3 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st + KiB Mem : 1016168 total, 191060 free, 324700 used, 500408 buff/cache + KiB Swap: 0 total, 0 free, 0 used. 530944 avail Mem + ... + ``` + + - `-c` - 显示进程的整个路径。 + - `-d` - 指定两次刷屏之间的间隔时间(秒为单位)。 + - `-i` - 不显示闲置进程或僵尸进程。 + - `-p` - 显示指定进程的信息。 + +### 系统诊断 + +1. 系统启动异常诊断 - **dmesg**。 + +2. 查看系统活动信息 - **sar**。 + + ```Shell + [root@izwz97tbgo9lkabnat2lo8z ~]# sar -u -r 5 10 + Linux 3.10.0-957.10.1.el7.x86_64 (izwz97tbgo9lkabnat2lo8z) 06/02/2019 _x86_64_ (2 CPU) + + 06:48:30 PM CPU %user %nice %system %iowait %steal %idle + 06:48:35 PM all 0.10 0.00 0.10 0.00 0.00 99.80 + + 06:48:30 PM kbmemfree kbmemused %memused kbbuffers kbcached kbcommit %commit kbactive kbinact kbdirty + 06:48:35 PM 1772012 2108392 54.33 102816 1634528 784940 20.23 793328 1164704 0 + ``` + + - `-A` - 显示所有设备(CPU、内存、磁盘)的运行状况。 + - `-u` - 显示所有CPU的负载情况。 + - `-d` - 显示所有磁盘的使用情况。 + - `-r` - 显示内存的使用情况。 + - `-n` - 显示网络运行状态。 + +3. 查看内存使用情况 - **free**。 ```Shell [root@iZwz97tbgo9lkabnat2lo8Z ~]# free @@ -1212,7 +1686,26 @@ build environment: Swap: 0 0 0 ``` -3. 查看进程使用内存状况 - **pmap**。 +4. 虚拟内存统计 - **vmstat**。 + + ```Shell + [root@iZ8vba0s66jjlfmo601w4xZ ~]# vmstat + procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu----- + r b swpd free buff cache si so bi bo in cs us sy id wa st + 2 0 0 204020 79036 667532 0 0 5 18 101 58 1 0 99 0 0 + ``` + +5. CPU信息统计 - **mpstat**。 + + ```Shell + [root@iZ8vba0s66jjlfmo601w4xZ ~]# mpstat + Linux 3.10.0-957.5.1.el7.x86_64 (iZ8vba0s66jjlfmo601w4xZ) 05/30/2019 _x86_64_ (1 CPU) + + 01:51:54 AM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle + 01:51:54 AM all 0.71 0.00 0.17 0.04 0.00 0.00 0.00 0.00 0.00 99.07 + ``` + +6. 查看进程使用内存状况 - **pmap**。 ```Shell [root@iZwz97tbgo9lkabnat2lo8Z ~]# ps @@ -1231,7 +1724,7 @@ build environment: ... ``` -4. 报告设备CPU和I/O统计信息 - **iostat**。 +7. 报告设备CPU和I/O统计信息 - **iostat**。 ```Shell [root@iZwz97tbgo9lkabnat2lo8Z ~]# iostat @@ -1243,3 +1736,79 @@ build environment: vdb 0.00 0.01 0.00 2088 0 ``` +8. 显示所有PCI设备 - **lspci**。 + + ```Shell + [root@izwz97tbgo9lkabnat2lo8z ~]# lspci + 00:00.0 Host bridge: Intel Corporation 440FX - 82441FX PMC [Natoma] (rev 02) + 00:01.0 ISA bridge: Intel Corporation 82371SB PIIX3 ISA [Natoma/Triton II] + 00:01.1 IDE interface: Intel Corporation 82371SB PIIX3 IDE [Natoma/Triton II] + 00:01.2 USB controller: Intel Corporation 82371SB PIIX3 USB [Natoma/Triton II] (rev 01) + 00:01.3 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 03) + 00:02.0 VGA compatible controller: Cirrus Logic GD 5446 + 00:03.0 Ethernet controller: Red Hat, Inc. Virtio network device + 00:04.0 Communication controller: Red Hat, Inc. Virtio console + 00:05.0 SCSI storage controller: Red Hat, Inc. Virtio block device + 00:06.0 SCSI storage controller: Red Hat, Inc. Virtio block device + 00:07.0 Unclassified device [00ff]: Red Hat, Inc. Virtio memory balloon + ``` + +9. 显示进程间通信设施的状态 - **ipcs**。 + + ```Shell + [root@iZ8vba0s66jjlfmo601w4xZ ~]# ipcs + + ------ Message Queues -------- + key msqid owner perms used-bytes messages + + ------ Shared Memory Segments -------- + key shmid owner perms bytes nattch status + + ------ Semaphore Arrays -------- + key semid owner perms nsems + ``` + +### 相关资源 + +1. Linux命令行常用快捷键 + + | 快捷键 | 功能说明 | + | ---------- | -------------------------------------------- | + | tab | 自动补全命令或路径 | + | Ctrl+a | 将光标移动到命令行行首 | + | Ctrl+e | 将光标移动到命令行行尾 | + | Ctrl+f | 将光标向右移动一个字符 | + | Ctrl+b | 将光标向左移动一个字符 | + | Ctrl+k | 剪切从光标到行尾的字符 | + | Ctrl+u | 剪切从光标到行首的字符 | + | Ctrl+w | 剪切光标前面的一个单词 | + | Ctrl+y | 复制剪切命名剪切的内容 | + | Ctrl+c | 中断正在执行的任务 | + | Ctrl+h | 删除光标前面的一个字符 | + | Ctrl+d | 退出当前命令行 | + | Ctrl+r | 搜索历史命令 | + | Ctrl+g | 退出历史命令搜索 | + | Ctrl+l | 清除屏幕上所有内容在屏幕的最上方开启一个新行 | + | Ctrl+s | 锁定终端使之暂时无法输入内容 | + | Ctrl+q | 退出终端锁定 | + | Ctrl+z | 将正在终端执行的任务停下来放到后台 | + | !! | 执行上一条命令 | + | !数字 | 执行数字对应的历史命令 | + | !字母 | 执行最近的以字母打头的命令 | + | !$ / Esc+. | 获得上一条命令最后一个参数 | + | Esc+b | 移动到当前单词的开头 | + | Esc+f | 移动到当前单词的结尾 | + +2. man查阅命令手册的内容说明 + + | 手册中的标题 | 功能说明 | + | ------------ | ------------------------------------------------------------ | + | NAME | 命令的说明和介绍 | + | SYNOPSIS | 使用该命令的基本语法 | + | DESCRIPTION | 使用该命令的详细描述,各个参数的作用,有时候这些信息会出现在OPTIONS中 | + | OPTIONS | 命令相关参数选项的说明 | + | EXAMPLES | 使用该命令的参考例子 | + | EXIT STATUS | 命令结束的退出状态码,通常0表示成功执行 | + | SEE ALSO | 和命令相关的其他命令或信息 | + | BUGS | 和命令相关的缺陷的描述 | + | AUTHOR | 该命令的作者介绍 | diff --git a/Day36-40/NoSQL入门.md b/Day36-40/NoSQL入门.md index 0d6808d..3a42f07 100644 --- a/Day36-40/NoSQL入门.md +++ b/Day36-40/NoSQL入门.md @@ -489,7 +489,7 @@ connecting to: mongodb://172.18.61.250:27017/ 使用MongoDB可以非常方便的配置数据复制,通过冗余数据来实现数据的高可用以及灾难恢复,也可以通过数据分片来应对数据量迅速增长的需求。关于MongoDB更多的操作可以查阅[官方文档](https://mongodb-documentation.readthedocs.io/en/latest/) ,同时推荐大家阅读Kristina Chodorow写的[《MongoDB权威指南》](http://www.ituring.com.cn/book/1172)。 -####在Python程序中操作MongoDB +#### 在Python程序中操作MongoDB 可以通过pip安装pymongo来实现对MongoDB的操作。 diff --git a/Day36-40/code/SRS_create_and_init.sql b/Day36-40/code/SRS_create_and_init.sql index 17ad397..301c7bc 100644 --- a/Day36-40/code/SRS_create_and_init.sql +++ b/Day36-40/code/SRS_create_and_init.sql @@ -216,7 +216,7 @@ select stuname as 姓名, year(now())-year(stubirth) as 年龄 from tb_student w ); -- 查询选了两门以上的课程的学生姓名(子查询/分组条件/集合运算) -select stuname from tb_student where stuid=( +select stuname from tb_student where stuid in ( select stuid from tb_score group by stuid having count(stuid)>2 ) diff --git a/Day36-40/code/fangtx_create.sql b/Day36-40/code/fangtx_create.sql new file mode 100644 index 0000000..28cf714 --- /dev/null +++ b/Day36-40/code/fangtx_create.sql @@ -0,0 +1,253 @@ +drop database if exists fangtx; + +create database fangtx default charset utf8 collate utf8_bin; + +use fangtx; + +/* 创建用户表 */ +create table `tb_user` +( + `userid` int auto_increment comment '编号', + `username` varchar(20) not null comment '用户名', + `password` char(32) not null comment '用户口令', + `realname` varchar(20) not null comment '真实姓名', + `sex` bool default 1 comment '性别', + `tel` varchar(20) not null comment '手机号', + `email` varchar(255) default '' comment '邮箱', + `regdate` datetime default now() comment '注册日期', + `point` int default 0 comment '积分', + `lastvisit` datetime default now() comment '最后访问时间', + `is_authenticated` bit default 0 comment '是否认证', + primary key (`userid`) +); + +/* 创建地区表 */ +create table `tb_district` +( + `distid` int not null comment '编号', + `pid` int comment '父级行政单位', + `name` varchar(255) not null comment '名称', + `ishot` bool default 0 comment '是否为热门城市', + `intro` varchar(255) default '' comment '介绍', + primary key (distid) +); + +/* 创建经理人表 */ +create table `tb_agent` +( + `agentid` int not null auto_increment comment '编号', + `name` varchar(255) not null comment '姓名', + `tel` varchar(20) not null comment '电话', + `servstar` int not null default 0 comment '满意度星级', + `realstar` int not null default 0 comment '真实度星级', + `profstar` int not null default 0 comment '专业度星级', + `certificated` bool not null default 0 comment '是否持有专业认证', + primary key (`agentid`) +); + +/* 创建用户登录日志表 */ +create table `tb_login_log` +( + `logid` bigint auto_increment comment '编号', + `userid` int not null comment '用户', + `ipaddr` varchar(255) not null comment 'IP地址', + `logdate` datetime default now() comment '登录时间日期', + `devcode` varchar(255) default '' comment '设备代码', + primary key (`logid`) +); + +/* 创建楼盘表 */ +create table `tb_estate` +( + `estateid` int not null auto_increment comment '编号', + `distid` int not null comment '所在三级行政区域', + `name` varchar(255) not null comment '名称', + `hot` int default 0 comment '热度', + `intro` varchar(511) default '' comment '介绍', + primary key (`estateid`) +); + +/* 创建经理人楼盘中间表 */ +create table `tb_agent_estate` +( + `agent_estate_id` int not null auto_increment comment '编号', + `agentid` int not null comment '经理人', + `estateid` int not null comment '楼盘', + primary key (`agent_estate_id`) +); + +/* 创建户型表 */ +create table `tb_house_type` +( + `typeid` int comment '编号', + `name` varchar(255) not null comment '名称', + primary key (`typeid`) +); + +/* 创建房源信息表 */ +create table `tb_house_info` +( + `houseid` int not null auto_increment comment '编号', + `title` varchar(50) not null comment '标题', + `area` int not null comment '面积', + `floor` int not null comment '楼层', + `totalfloor` int not null comment '总楼层', + `direction` varchar(10) not null comment '朝向', + `price` int not null comment '价格', + `priceunit` varchar(10) not null comment '价格单位', + `detail` varchar(511) default '' comment '详情', + `mainphoto` varchar(255) not null comment '主图', + `pubdate` date not null comment '发布日期', + `street` varchar(255) not null comment '街道', + `hassubway` bool default 0 comment '是否有地铁', + `isshared` bool default 0 comment '是否支持合租', + `hasagentfees` bool default 0 comment '是否有中介费', + `typeid` int not null comment '户型', + `userid` int not null comment '发布用户', + `distid2` int not null comment '所在二级行政区域', + `distid3` int not null comment '所在三级行政区域', + `estateid` int comment '楼盘', + `agentid` int comment '经理人', + primary key (`houseid`) +); + +/* 创建房源照片表 */ +create table `tb_house_photo` +( + `photoid` int not null auto_increment comment '编号', + `houseid` int not null comment '房源', + `path` varchar(255) not null comment '资源路径', + primary key (`photoid`) +); + +/* 创建标签表 */ +create table `tb_tag` +( + `tagid` int auto_increment comment '编号', + `content` varchar(20) not null comment '内容', + primary key (`tagid`) +); + +/* 创建房源标签中间表 */ +create table `tb_house_tag` +( + `house_tag_id` int auto_increment comment '编号', + `houseid` int not null comment '房源', + `tagid` int not null comment '标签', + primary key (`house_tag_id`) +); + + +/* 创建用户浏览历史记录表 */ +create table `tb_record` +( + `recordid` bigint auto_increment comment '编号', + `userid` int not null comment '用户', + `houseid` int not null comment '房源', + `recorddate` datetime not null comment '浏览时间日期', + primary key (`recordid`) +); + +/* 创建用户令牌表 */ +create table `tb_user_token` +( + `tokenid` int auto_increment comment '编号', + `token` char(32) not null comment '令牌', + `userid` int not null comment '用户', + primary key (`tokenid`) +); + +/* 创建角色表 */ +create table `tb_role` +( + `roleid` int auto_increment comment '编号', + `rolename` varchar(255) not null comment '角色名', + primary key (`roleid`) +); + +/* 创建权限表 */ +create table `tb_privilege` +( + `privid` int auto_increment comment '编号', + `method` varchar(15) not null comment '请求方法', + `url` varchar(1024) not null comment '资源的URL', + PRIMARY KEY (`privid`) +); + +/* 创建用户角色中间表 */ +create table `tb_user_role` +( + `urid` int auto_increment comment '编号', + `userid` int not null comment '用户', + `roleid` int not null comment '角色', + primary key (`urid`) +); + +/* 创建角色权限中间表 */ +create table `tb_role_privilege` +( + `rpid` int auto_increment comment '编号', + `roleid` int not null comment '角色', + `privid` int not null comment '权限', + primary key (`rpid`) +); + +create unique index `uni_idx_agent_estate` on `tb_agent_estate` (`agentid`, `estateid`); + +create unique index `uni_idx_record` on `tb_record` (`userid`, `houseid`); + +create unique index `uni_idx_userid` on `tb_user_token` (`userid`); + +create unique index `uni_idx_username` on `tb_user` (`username`); + +create unique index `uni_idx_tel` on `tb_user` (`tel`); + +create unique index `uni_idx_email` on `tb_user` (`email`); + +create unique index `uni_idx_house_tag` on `tb_house_tag` (`houseid`, `tagid`); + +alter table `tb_agent_estate` add constraint `fk_agent_estate_agentid` foreign key (`agentid`) references `tb_agent` (`agentid`); + +alter table `tb_agent_estate` add constraint `fk_agent_estate_estateid` foreign key (`estateid`) references `tb_estate` (`estateid`); + +alter table `tb_district` add constraint `fk_district_pid` foreign key (`pid`) references `tb_district` (`distid`); + +alter table `tb_estate` add constraint `fk_estate_distid` foreign key (`distid`) references `tb_district` (`distid`); + +alter table `tb_house_info` add constraint `fk_house_info_agentid` foreign key (`agentid`) references tb_agent (`agentid`); + +alter table `tb_house_info` add constraint `fk_house_info_distid2` foreign key (`distid2`) references tb_district (`distid`); + +alter table `tb_house_info` add constraint `fk_house_info_distid3` foreign key (`distid3`) references tb_district (`distid`); + +alter table `tb_house_info` add constraint `fk_house_info_estateid` foreign key (`estateid`) references tb_estate (`estateid`); + +alter table `tb_house_info` add constraint `fk_house_info_typeid` foreign key (`typeid`) references tb_house_type (`typeid`); + +alter table `tb_house_info` add constraint `fk_house_info_userid` foreign key (`userid`) references tb_user (`userid`); + +alter table `tb_house_photo` add constraint `fk_house_photo_houseid` foreign key (`houseid`) references `tb_house_info` (`houseid`); + +alter table `tb_house_tag` add constraint `fk_house_tag_houseid` foreign key (`houseid`) references `tb_house_info` (`houseid`); + +alter table `tb_house_tag` add constraint `fk_house_tag_tagid` foreign key (`tagid`) references `tb_tag` (`tagid`); + +alter table `tb_login_log` add constraint `fk_login_log_userid` foreign key (`userid`) references `tb_user` (`userid`); + +alter table `tb_record` add constraint `fk_record_houseid` foreign key (`houseid`) references `tb_house_info` (`houseid`); + +alter table `tb_record` add constraint `fk_record_userid` foreign key (`userid`) references `tb_user` (`userid`); + +alter table `tb_user_token` add constraint `fk_token_userid` foreign key (`userid`) references `tb_user` (`userid`); + +alter table `tb_user_role` add constraint `uni_user_role` unique (`userid`, `roleid`); + +alter table `tb_role_privilege` add constraint `uni_role_priv` unique (`roleid`, `privid`); + +alter table `tb_role_privilege` add constraint `fk_role_privilege_privid` foreign key (`privid`) references `tb_privilege` (`privid`); + +alter table `tb_role_privilege` add constraint `fk_role_privilege_roleid` foreign key (`roleid`) references `tb_role` (`roleid`); + +alter table `tb_user_role` add constraint `fk_user_role_roleid` foreign key (`roleid`) references `tb_role` (`roleid`); + +alter table `tb_user_role` add constraint `fk_user_role_userid` foreign key (`userid`) references `tb_user` (`userid`); diff --git a/Day36-40/code/fangtx_init.sql b/Day36-40/code/fangtx_init.sql new file mode 100644 index 0000000..b597f2d --- /dev/null +++ b/Day36-40/code/fangtx_init.sql @@ -0,0 +1,3358 @@ +use fangtx; + +-- 插入地区数据 +insert into `tb_district` (`distid`, `name`, `pid`) values +('110000', '北京市', null), +('110100', '北京市', '110000'), +('110101', '东城区', '110100'), +('110102', '西城区', '110100'), +('110105', '朝阳区', '110100'), +('110106', '丰台区', '110100'), +('110107', '石景山区', '110100'), +('110108', '海淀区', '110100'), +('110109', '门头沟区', '110100'), +('110111', '房山区', '110100'), +('110112', '通州区', '110100'), +('110113', '顺义区', '110100'), +('110114', '昌平区', '110100'), +('110115', '大兴区', '110100'), +('110116', '怀柔区', '110100'), +('110117', '平谷区', '110100'), +('110118', '密云区', '110100'), +('110119', '延庆区', '110100'), +('120000', '天津市', null), +('120100', '天津市', '120000'), +('120101', '和平区', '120100'), +('120102', '河东区', '120100'), +('120103', '河西区', '120100'), +('120104', '南开区', '120100'), +('120105', '河北区', '120100'), +('120106', '红桥区', '120100'), +('120110', '东丽区', '120100'), +('120111', '西青区', '120100'), +('120112', '津南区', '120100'), +('120113', '北辰区', '120100'), +('120114', '武清区', '120100'), +('120115', '宝坻区', '120100'), +('120116', '滨海新区', '120100'), +('120117', '宁河区', '120100'), +('120118', '静海区', '120100'), +('120119', '蓟州区', '120100'), +('130000', '河北省', null), +('130100', '石家庄市', '130000'), +('130102', '长安区', '130100'), +('130104', '桥西区', '130100'), +('130105', '新华区', '130100'), +('130107', '井陉矿区', '130100'), +('130108', '裕华区', '130100'), +('130109', '藁城区', '130100'), +('130110', '鹿泉区', '130100'), +('130111', '栾城区', '130100'), +('130121', '井陉县', '130100'), +('130123', '正定县', '130100'), +('130125', '行唐县', '130100'), +('130126', '灵寿县', '130100'), +('130127', '高邑县', '130100'), +('130128', '深泽县', '130100'), +('130129', '赞皇县', '130100'), +('130130', '无极县', '130100'), +('130131', '平山县', '130100'), +('130132', '元氏县', '130100'), +('130133', '赵县', '130100'), +('130183', '晋州市', '130100'), +('130184', '新乐市', '130100'), +('130200', '唐山市', '130000'), +('130202', '路南区', '130200'), +('130203', '路北区', '130200'), +('130204', '古冶区', '130200'), +('130205', '开平区', '130200'), +('130207', '丰南区', '130200'), +('130208', '丰润区', '130200'), +('130209', '曹妃甸区', '130200'), +('130223', '滦县', '130200'), +('130224', '滦南县', '130200'), +('130225', '乐亭县', '130200'), +('130227', '迁西县', '130200'), +('130229', '玉田县', '130200'), +('130281', '遵化市', '130200'), +('130283', '迁安市', '130200'), +('130300', '秦皇岛市', '130000'), +('130302', '海港区', '130300'), +('130303', '山海关区', '130300'), +('130304', '北戴河区', '130300'), +('130306', '抚宁区', '130300'), +('130321', '青龙满族自治县', '130300'), +('130322', '昌黎县', '130300'), +('130324', '卢龙县', '130300'), +('130400', '邯郸市', '130000'), +('130402', '邯山区', '130400'), +('130403', '丛台区', '130400'), +('130404', '复兴区', '130400'), +('130406', '峰峰矿区', '130400'), +('130421', '邯郸县', '130400'), +('130423', '临漳县', '130400'), +('130424', '成安县', '130400'), +('130425', '大名县', '130400'), +('130426', '涉县', '130400'), +('130427', '磁县', '130400'), +('130428', '肥乡县', '130400'), +('130429', '永年县', '130400'), +('130430', '邱县', '130400'), +('130431', '鸡泽县', '130400'), +('130432', '广平县', '130400'), +('130433', '馆陶县', '130400'), +('130434', '魏县', '130400'), +('130435', '曲周县', '130400'), +('130481', '武安市', '130400'), +('130500', '邢台市', '130000'), +('130502', '桥东区', '130500'), +('130503', '桥西区', '130500'), +('130521', '邢台县', '130500'), +('130522', '临城县', '130500'), +('130523', '内丘县', '130500'), +('130524', '柏乡县', '130500'), +('130525', '隆尧县', '130500'), +('130526', '任县', '130500'), +('130527', '南和县', '130500'), +('130528', '宁晋县', '130500'), +('130529', '巨鹿县', '130500'), +('130530', '新河县', '130500'), +('130531', '广宗县', '130500'), +('130532', '平乡县', '130500'), +('130533', '威县', '130500'), +('130534', '清河县', '130500'), +('130535', '临西县', '130500'), +('130581', '南宫市', '130500'), +('130582', '沙河市', '130500'), +('130600', '保定市', '130000'), +('130602', '竞秀区', '130600'), +('130606', '莲池区', '130600'), +('130607', '满城区', '130600'), +('130608', '清苑区', '130600'), +('130609', '徐水区', '130600'), +('130623', '涞水县', '130600'), +('130624', '阜平县', '130600'), +('130626', '定兴县', '130600'), +('130627', '唐县', '130600'), +('130628', '高阳县', '130600'), +('130629', '容城县', '130600'), +('130630', '涞源县', '130600'), +('130631', '望都县', '130600'), +('130632', '安新县', '130600'), +('130633', '易县', '130600'), +('130634', '曲阳县', '130600'), +('130635', '蠡县', '130600'), +('130636', '顺平县', '130600'), +('130637', '博野县', '130600'), +('130638', '雄县', '130600'), +('130681', '涿州市', '130600'), +('130683', '安国市', '130600'), +('130684', '高碑店市', '130600'), +('130700', '张家口市', '130000'), +('130702', '桥东区', '130700'), +('130703', '桥西区', '130700'), +('130705', '宣化区', '130700'), +('130706', '下花园区', '130700'), +('130708', '万全区', '130700'), +('130709', '崇礼区', '130700'), +('130722', '张北县', '130700'), +('130723', '康保县', '130700'), +('130724', '沽源县', '130700'), +('130725', '尚义县', '130700'), +('130726', '蔚县', '130700'), +('130727', '阳原县', '130700'), +('130728', '怀安县', '130700'), +('130730', '怀来县', '130700'), +('130731', '涿鹿县', '130700'), +('130732', '赤城县', '130700'), +('130800', '承德市', '130000'), +('130802', '双桥区', '130800'), +('130803', '双滦区', '130800'), +('130804', '鹰手营子矿区', '130800'), +('130821', '承德县', '130800'), +('130822', '兴隆县', '130800'), +('130823', '平泉县', '130800'), +('130824', '滦平县', '130800'), +('130825', '隆化县', '130800'), +('130826', '丰宁满族自治县', '130800'), +('130827', '宽城满族自治县', '130800'), +('130828', '围场满族蒙古族自治县', '130800'), +('130900', '沧州市', '130000'), +('130902', '新华区', '130900'), +('130903', '运河区', '130900'), +('130921', '沧县', '130900'), +('130922', '青县', '130900'), +('130923', '东光县', '130900'), +('130924', '海兴县', '130900'), +('130925', '盐山县', '130900'), +('130926', '肃宁县', '130900'), +('130927', '南皮县', '130900'), +('130928', '吴桥县', '130900'), +('130929', '献县', '130900'), +('130930', '孟村回族自治县', '130900'), +('130981', '泊头市', '130900'), +('130982', '任丘市', '130900'), +('130983', '黄骅市', '130900'), +('130984', '河间市', '130900'), +('131000', '廊坊市', '130000'), +('131002', '安次区', '131000'), +('131003', '广阳区', '131000'), +('131022', '固安县', '131000'), +('131023', '永清县', '131000'), +('131024', '香河县', '131000'), +('131025', '大城县', '131000'), +('131026', '文安县', '131000'), +('131028', '大厂回族自治县', '131000'), +('131081', '霸州市', '131000'), +('131082', '三河市', '131000'), +('131100', '衡水市', '130000'), +('131102', '桃城区', '131100'), +('131103', '冀州区', '131100'), +('131121', '枣强县', '131100'), +('131122', '武邑县', '131100'), +('131123', '武强县', '131100'), +('131124', '饶阳县', '131100'), +('131125', '安平县', '131100'), +('131126', '故城县', '131100'), +('131127', '景县', '131100'), +('131128', '阜城县', '131100'), +('131182', '深州市', '131100'), +('139000', '省直辖县级行政区划', '130000'), +('139001', '定州市', '139000'), +('139002', '辛集市', '139000'), +('140000', '山西省', null), +('140100', '太原市', '140000'), +('140105', '小店区', '140100'), +('140106', '迎泽区', '140100'), +('140107', '杏花岭区', '140100'), +('140108', '尖草坪区', '140100'), +('140109', '万柏林区', '140100'), +('140110', '晋源区', '140100'), +('140121', '清徐县', '140100'), +('140122', '阳曲县', '140100'), +('140123', '娄烦县', '140100'), +('140181', '古交市', '140100'), +('140200', '大同市', '140000'), +('140202', '城区', '140200'), +('140203', '矿区', '140200'), +('140211', '南郊区', '140200'), +('140212', '新荣区', '140200'), +('140221', '阳高县', '140200'), +('140222', '天镇县', '140200'), +('140223', '广灵县', '140200'), +('140224', '灵丘县', '140200'), +('140225', '浑源县', '140200'), +('140226', '左云县', '140200'), +('140227', '大同县', '140200'), +('140300', '阳泉市', '140000'), +('140302', '城区', '140300'), +('140303', '矿区', '140300'), +('140311', '郊区', '140300'), +('140321', '平定县', '140300'), +('140322', '盂县', '140300'), +('140400', '长治市', '140000'), +('140402', '城区', '140400'), +('140411', '郊区', '140400'), +('140421', '长治县', '140400'), +('140423', '襄垣县', '140400'), +('140424', '屯留县', '140400'), +('140425', '平顺县', '140400'), +('140426', '黎城县', '140400'), +('140427', '壶关县', '140400'), +('140428', '长子县', '140400'), +('140429', '武乡县', '140400'), +('140430', '沁县', '140400'), +('140431', '沁源县', '140400'), +('140481', '潞城市', '140400'), +('140500', '晋城市', '140000'), +('140502', '城区', '140500'), +('140521', '沁水县', '140500'), +('140522', '阳城县', '140500'), +('140524', '陵川县', '140500'), +('140525', '泽州县', '140500'), +('140581', '高平市', '140500'), +('140600', '朔州市', '140000'), +('140602', '朔城区', '140600'), +('140603', '平鲁区', '140600'), +('140621', '山阴县', '140600'), +('140622', '应县', '140600'), +('140623', '右玉县', '140600'), +('140624', '怀仁县', '140600'), +('140700', '晋中市', '140000'), +('140702', '榆次区', '140700'), +('140721', '榆社县', '140700'), +('140722', '左权县', '140700'), +('140723', '和顺县', '140700'), +('140724', '昔阳县', '140700'), +('140725', '寿阳县', '140700'), +('140726', '太谷县', '140700'), +('140727', '祁县', '140700'), +('140728', '平遥县', '140700'), +('140729', '灵石县', '140700'), +('140781', '介休市', '140700'), +('140800', '运城市', '140000'), +('140802', '盐湖区', '140800'), +('140821', '临猗县', '140800'), +('140822', '万荣县', '140800'), +('140823', '闻喜县', '140800'), +('140824', '稷山县', '140800'), +('140825', '新绛县', '140800'), +('140826', '绛县', '140800'), +('140827', '垣曲县', '140800'), +('140828', '夏县', '140800'), +('140829', '平陆县', '140800'), +('140830', '芮城县', '140800'), +('140881', '永济市', '140800'), +('140882', '河津市', '140800'), +('140900', '忻州市', '140000'), +('140902', '忻府区', '140900'), +('140921', '定襄县', '140900'), +('140922', '五台县', '140900'), +('140923', '代县', '140900'), +('140924', '繁峙县', '140900'), +('140925', '宁武县', '140900'), +('140926', '静乐县', '140900'), +('140927', '神池县', '140900'), +('140928', '五寨县', '140900'), +('140929', '岢岚县', '140900'), +('140930', '河曲县', '140900'), +('140931', '保德县', '140900'), +('140932', '偏关县', '140900'), +('140981', '原平市', '140900'), +('141000', '临汾市', '140000'), +('141002', '尧都区', '141000'), +('141021', '曲沃县', '141000'), +('141022', '翼城县', '141000'), +('141023', '襄汾县', '141000'), +('141024', '洪洞县', '141000'), +('141025', '古县', '141000'), +('141026', '安泽县', '141000'), +('141027', '浮山县', '141000'), +('141028', '吉县', '141000'), +('141029', '乡宁县', '141000'), +('141030', '大宁县', '141000'), +('141031', '隰县', '141000'), +('141032', '永和县', '141000'), +('141033', '蒲县', '141000'), +('141034', '汾西县', '141000'), +('141081', '侯马市', '141000'), +('141082', '霍州市', '141000'), +('141100', '吕梁市', '140000'), +('141102', '离石区', '141100'), +('141121', '文水县', '141100'), +('141122', '交城县', '141100'), +('141123', '兴县', '141100'), +('141124', '临县', '141100'), +('141125', '柳林县', '141100'), +('141126', '石楼县', '141100'), +('141127', '岚县', '141100'), +('141128', '方山县', '141100'), +('141129', '中阳县', '141100'), +('141130', '交口县', '141100'), +('141181', '孝义市', '141100'), +('141182', '汾阳市', '141100'), +('150000', '内蒙古自治区', null), +('150100', '呼和浩特市', '150000'), +('150102', '新城区', '150100'), +('150103', '回民区', '150100'), +('150104', '玉泉区', '150100'), +('150105', '赛罕区', '150100'), +('150121', '土默特左旗', '150100'), +('150122', '托克托县', '150100'), +('150123', '和林格尔县', '150100'), +('150124', '清水河县', '150100'), +('150125', '武川县', '150100'), +('150200', '包头市', '150000'), +('150202', '东河区', '150200'), +('150203', '昆都仑区', '150200'), +('150204', '青山区', '150200'), +('150205', '石拐区', '150200'), +('150206', '白云鄂博矿区', '150200'), +('150207', '九原区', '150200'), +('150221', '土默特右旗', '150200'), +('150222', '固阳县', '150200'), +('150223', '达尔罕茂明安联合旗', '150200'), +('150300', '乌海市', '150000'), +('150302', '海勃湾区', '150300'), +('150303', '海南区', '150300'), +('150304', '乌达区', '150300'), +('150400', '赤峰市', '150000'), +('150402', '红山区', '150400'), +('150403', '元宝山区', '150400'), +('150404', '松山区', '150400'), +('150421', '阿鲁科尔沁旗', '150400'), +('150422', '巴林左旗', '150400'), +('150423', '巴林右旗', '150400'), +('150424', '林西县', '150400'), +('150425', '克什克腾旗', '150400'), +('150426', '翁牛特旗', '150400'), +('150428', '喀喇沁旗', '150400'), +('150429', '宁城县', '150400'), +('150430', '敖汉旗', '150400'), +('150500', '通辽市', '150000'), +('150502', '科尔沁区', '150500'), +('150521', '科尔沁左翼中旗', '150500'), +('150522', '科尔沁左翼后旗', '150500'), +('150523', '开鲁县', '150500'), +('150524', '库伦旗', '150500'), +('150525', '奈曼旗', '150500'), +('150526', '扎鲁特旗', '150500'), +('150581', '霍林郭勒市', '150500'), +('150600', '鄂尔多斯市', '150000'), +('150602', '东胜区', '150600'), +('150603', '康巴什区', '150600'), +('150621', '达拉特旗', '150600'), +('150622', '准格尔旗', '150600'), +('150623', '鄂托克前旗', '150600'), +('150624', '鄂托克旗', '150600'), +('150625', '杭锦旗', '150600'), +('150626', '乌审旗', '150600'), +('150627', '伊金霍洛旗', '150600'), +('150700', '呼伦贝尔市', '150000'), +('150702', '海拉尔区', '150700'), +('150703', '扎赉诺尔区', '150700'), +('150721', '阿荣旗', '150700'), +('150722', '莫力达瓦达斡尔族自治旗', '150700'), +('150723', '鄂伦春自治旗', '150700'), +('150724', '鄂温克族自治旗', '150700'), +('150725', '陈巴尔虎旗', '150700'), +('150726', '新巴尔虎左旗', '150700'), +('150727', '新巴尔虎右旗', '150700'), +('150781', '满洲里市', '150700'), +('150782', '牙克石市', '150700'), +('150783', '扎兰屯市', '150700'), +('150784', '额尔古纳市', '150700'), +('150785', '根河市', '150700'), +('150800', '巴彦淖尔市', '150000'), +('150802', '临河区', '150800'), +('150821', '五原县', '150800'), +('150822', '磴口县', '150800'), +('150823', '乌拉特前旗', '150800'), +('150824', '乌拉特中旗', '150800'), +('150825', '乌拉特后旗', '150800'), +('150826', '杭锦后旗', '150800'), +('150900', '乌兰察布市', '150000'), +('150902', '集宁区', '150900'), +('150921', '卓资县', '150900'), +('150922', '化德县', '150900'), +('150923', '商都县', '150900'), +('150924', '兴和县', '150900'), +('150925', '凉城县', '150900'), +('150926', '察哈尔右翼前旗', '150900'), +('150927', '察哈尔右翼中旗', '150900'), +('150928', '察哈尔右翼后旗', '150900'), +('150929', '四子王旗', '150900'), +('150981', '丰镇市', '150900'), +('152200', '兴安盟', '150000'), +('152201', '乌兰浩特市', '152200'), +('152202', '阿尔山市', '152200'), +('152221', '科尔沁右翼前旗', '152200'), +('152222', '科尔沁右翼中旗', '152200'), +('152223', '扎赉特旗', '152200'), +('152224', '突泉县', '152200'), +('152500', '锡林郭勒盟', '150000'), +('152501', '二连浩特市', '152500'), +('152502', '锡林浩特市', '152500'), +('152522', '阿巴嘎旗', '152500'), +('152523', '苏尼特左旗', '152500'), +('152524', '苏尼特右旗', '152500'), +('152525', '东乌珠穆沁旗', '152500'), +('152526', '西乌珠穆沁旗', '152500'), +('152527', '太仆寺旗', '152500'), +('152528', '镶黄旗', '152500'), +('152529', '正镶白旗', '152500'), +('152530', '正蓝旗', '152500'), +('152531', '多伦县', '152500'), +('152900', '阿拉善盟', '150000'), +('152921', '阿拉善左旗', '152900'), +('152922', '阿拉善右旗', '152900'), +('152923', '额济纳旗', '152900'), +('210000', '辽宁省', null), +('210100', '沈阳市', '210000'), +('210102', '和平区', '210100'), +('210103', '沈河区', '210100'), +('210104', '大东区', '210100'), +('210105', '皇姑区', '210100'), +('210106', '铁西区', '210100'), +('210111', '苏家屯区', '210100'), +('210112', '浑南区', '210100'), +('210113', '沈北新区', '210100'), +('210114', '于洪区', '210100'), +('210115', '辽中区', '210100'), +('210123', '康平县', '210100'), +('210124', '法库县', '210100'), +('210181', '新民市', '210100'), +('210200', '大连市', '210000'), +('210202', '中山区', '210200'), +('210203', '西岗区', '210200'), +('210204', '沙河口区', '210200'), +('210211', '甘井子区', '210200'), +('210212', '旅顺口区', '210200'), +('210213', '金州区', '210200'), +('210214', '普兰店区', '210200'), +('210224', '长海县', '210200'), +('210281', '瓦房店市', '210200'), +('210283', '庄河市', '210200'), +('210300', '鞍山市', '210000'), +('210302', '铁东区', '210300'), +('210303', '铁西区', '210300'), +('210304', '立山区', '210300'), +('210311', '千山区', '210300'), +('210321', '台安县', '210300'), +('210323', '岫岩满族自治县', '210300'), +('210381', '海城市', '210300'), +('210400', '抚顺市', '210000'), +('210402', '新抚区', '210400'), +('210403', '东洲区', '210400'), +('210404', '望花区', '210400'), +('210411', '顺城区', '210400'), +('210421', '抚顺县', '210400'), +('210422', '新宾满族自治县', '210400'), +('210423', '清原满族自治县', '210400'), +('210500', '本溪市', '210000'), +('210502', '平山区', '210500'), +('210503', '溪湖区', '210500'), +('210504', '明山区', '210500'), +('210505', '南芬区', '210500'), +('210521', '本溪满族自治县', '210500'), +('210522', '桓仁满族自治县', '210500'), +('210600', '丹东市', '210000'), +('210602', '元宝区', '210600'), +('210603', '振兴区', '210600'), +('210604', '振安区', '210600'), +('210624', '宽甸满族自治县', '210600'), +('210681', '东港市', '210600'), +('210682', '凤城市', '210600'), +('210700', '锦州市', '210000'), +('210702', '古塔区', '210700'), +('210703', '凌河区', '210700'), +('210711', '太和区', '210700'), +('210726', '黑山县', '210700'), +('210727', '义县', '210700'), +('210781', '凌海市', '210700'), +('210782', '北镇市', '210700'), +('210800', '营口市', '210000'), +('210802', '站前区', '210800'), +('210803', '西市区', '210800'), +('210804', '鲅鱼圈区', '210800'), +('210811', '老边区', '210800'), +('210881', '盖州市', '210800'), +('210882', '大石桥市', '210800'), +('210900', '阜新市', '210000'), +('210902', '海州区', '210900'), +('210903', '新邱区', '210900'), +('210904', '太平区', '210900'), +('210905', '清河门区', '210900'), +('210911', '细河区', '210900'), +('210921', '阜新蒙古族自治县', '210900'), +('210922', '彰武县', '210900'), +('211000', '辽阳市', '210000'), +('211002', '白塔区', '211000'), +('211003', '文圣区', '211000'), +('211004', '宏伟区', '211000'), +('211005', '弓长岭区', '211000'), +('211011', '太子河区', '211000'), +('211021', '辽阳县', '211000'), +('211081', '灯塔市', '211000'), +('211100', '盘锦市', '210000'), +('211102', '双台子区', '211100'), +('211103', '兴隆台区', '211100'), +('211104', '大洼区', '211100'), +('211122', '盘山县', '211100'), +('211200', '铁岭市', '210000'), +('211202', '银州区', '211200'), +('211204', '清河区', '211200'), +('211221', '铁岭县', '211200'), +('211223', '西丰县', '211200'), +('211224', '昌图县', '211200'), +('211281', '调兵山市', '211200'), +('211282', '开原市', '211200'), +('211300', '朝阳市', '210000'), +('211302', '双塔区', '211300'), +('211303', '龙城区', '211300'), +('211321', '朝阳县', '211300'), +('211322', '建平县', '211300'), +('211324', '喀喇沁左翼蒙古族自治县', '211300'), +('211381', '北票市', '211300'), +('211382', '凌源市', '211300'), +('211400', '葫芦岛市', '210000'), +('211402', '连山区', '211400'), +('211403', '龙港区', '211400'), +('211404', '南票区', '211400'), +('211421', '绥中县', '211400'), +('211422', '建昌县', '211400'), +('211481', '兴城市', '211400'), +('220000', '吉林省', null), +('220100', '长春市', '220000'), +('220102', '南关区', '220100'), +('220103', '宽城区', '220100'), +('220104', '朝阳区', '220100'), +('220105', '二道区', '220100'), +('220106', '绿园区', '220100'), +('220112', '双阳区', '220100'), +('220113', '九台区', '220100'), +('220122', '农安县', '220100'), +('220182', '榆树市', '220100'), +('220183', '德惠市', '220100'), +('220200', '吉林市', '220000'), +('220202', '昌邑区', '220200'), +('220203', '龙潭区', '220200'), +('220204', '船营区', '220200'), +('220211', '丰满区', '220200'), +('220221', '永吉县', '220200'), +('220281', '蛟河市', '220200'), +('220282', '桦甸市', '220200'), +('220283', '舒兰市', '220200'), +('220284', '磐石市', '220200'), +('220300', '四平市', '220000'), +('220302', '铁西区', '220300'), +('220303', '铁东区', '220300'), +('220322', '梨树县', '220300'), +('220323', '伊通满族自治县', '220300'), +('220381', '公主岭市', '220300'), +('220382', '双辽市', '220300'), +('220400', '辽源市', '220000'), +('220402', '龙山区', '220400'), +('220403', '西安区', '220400'), +('220421', '东丰县', '220400'), +('220422', '东辽县', '220400'), +('220500', '通化市', '220000'), +('220502', '东昌区', '220500'), +('220503', '二道江区', '220500'), +('220521', '通化县', '220500'), +('220523', '辉南县', '220500'), +('220524', '柳河县', '220500'), +('220581', '梅河口市', '220500'), +('220582', '集安市', '220500'), +('220600', '白山市', '220000'), +('220602', '浑江区', '220600'), +('220605', '江源区', '220600'), +('220621', '抚松县', '220600'), +('220622', '靖宇县', '220600'), +('220623', '长白朝鲜族自治县', '220600'), +('220681', '临江市', '220600'), +('220700', '松原市', '220000'), +('220702', '宁江区', '220700'), +('220721', '前郭尔罗斯蒙古族自治县', '220700'), +('220722', '长岭县', '220700'), +('220723', '乾安县', '220700'), +('220781', '扶余市', '220700'), +('220800', '白城市', '220000'), +('220802', '洮北区', '220800'), +('220821', '镇赉县', '220800'), +('220822', '通榆县', '220800'), +('220881', '洮南市', '220800'), +('220882', '大安市', '220800'), +('222400', '延边朝鲜族自治州', '220000'), +('222401', '延吉市', '222400'), +('222402', '图们市', '222400'), +('222403', '敦化市', '222400'), +('222404', '珲春市', '222400'), +('222405', '龙井市', '222400'), +('222406', '和龙市', '222400'), +('222424', '汪清县', '222400'), +('222426', '安图县', '222400'), +('230000', '黑龙江省', null), +('230100', '哈尔滨市', '230000'), +('230102', '道里区', '230100'), +('230103', '南岗区', '230100'), +('230104', '道外区', '230100'), +('230108', '平房区', '230100'), +('230109', '松北区', '230100'), +('230110', '香坊区', '230100'), +('230111', '呼兰区', '230100'), +('230112', '阿城区', '230100'), +('230113', '双城区', '230100'), +('230123', '依兰县', '230100'), +('230124', '方正县', '230100'), +('230125', '宾县', '230100'), +('230126', '巴彦县', '230100'), +('230127', '木兰县', '230100'), +('230128', '通河县', '230100'), +('230129', '延寿县', '230100'), +('230183', '尚志市', '230100'), +('230184', '五常市', '230100'), +('230200', '齐齐哈尔市', '230000'), +('230202', '龙沙区', '230200'), +('230203', '建华区', '230200'), +('230204', '铁锋区', '230200'), +('230205', '昂昂溪区', '230200'), +('230206', '富拉尔基区', '230200'), +('230207', '碾子山区', '230200'), +('230208', '梅里斯达斡尔族区', '230200'), +('230221', '龙江县', '230200'), +('230223', '依安县', '230200'), +('230224', '泰来县', '230200'), +('230225', '甘南县', '230200'), +('230227', '富裕县', '230200'), +('230229', '克山县', '230200'), +('230230', '克东县', '230200'), +('230231', '拜泉县', '230200'), +('230281', '讷河市', '230200'), +('230300', '鸡西市', '230000'), +('230302', '鸡冠区', '230300'), +('230303', '恒山区', '230300'), +('230304', '滴道区', '230300'), +('230305', '梨树区', '230300'), +('230306', '城子河区', '230300'), +('230307', '麻山区', '230300'), +('230321', '鸡东县', '230300'), +('230381', '虎林市', '230300'), +('230382', '密山市', '230300'), +('230400', '鹤岗市', '230000'), +('230402', '向阳区', '230400'), +('230403', '工农区', '230400'), +('230404', '南山区', '230400'), +('230405', '兴安区', '230400'), +('230406', '东山区', '230400'), +('230407', '兴山区', '230400'), +('230421', '萝北县', '230400'), +('230422', '绥滨县', '230400'), +('230500', '双鸭山市', '230000'), +('230502', '尖山区', '230500'), +('230503', '岭东区', '230500'), +('230505', '四方台区', '230500'), +('230506', '宝山区', '230500'), +('230521', '集贤县', '230500'), +('230522', '友谊县', '230500'), +('230523', '宝清县', '230500'), +('230524', '饶河县', '230500'), +('230600', '大庆市', '230000'), +('230602', '萨尔图区', '230600'), +('230603', '龙凤区', '230600'), +('230604', '让胡路区', '230600'), +('230605', '红岗区', '230600'), +('230606', '大同区', '230600'), +('230621', '肇州县', '230600'), +('230622', '肇源县', '230600'), +('230623', '林甸县', '230600'), +('230624', '杜尔伯特蒙古族自治县', '230600'), +('230700', '伊春市', '230000'), +('230702', '伊春区', '230700'), +('230703', '南岔区', '230700'), +('230704', '友好区', '230700'), +('230705', '西林区', '230700'), +('230706', '翠峦区', '230700'), +('230707', '新青区', '230700'), +('230708', '美溪区', '230700'), +('230709', '金山屯区', '230700'), +('230710', '五营区', '230700'), +('230711', '乌马河区', '230700'), +('230712', '汤旺河区', '230700'), +('230713', '带岭区', '230700'), +('230714', '乌伊岭区', '230700'), +('230715', '红星区', '230700'), +('230716', '上甘岭区', '230700'), +('230722', '嘉荫县', '230700'), +('230781', '铁力市', '230700'), +('230800', '佳木斯市', '230000'), +('230803', '向阳区', '230800'), +('230804', '前进区', '230800'), +('230805', '东风区', '230800'), +('230811', '郊区', '230800'), +('230822', '桦南县', '230800'), +('230826', '桦川县', '230800'), +('230828', '汤原县', '230800'), +('230881', '同江市', '230800'), +('230882', '富锦市', '230800'), +('230883', '抚远市', '230800'), +('230900', '七台河市', '230000'), +('230902', '新兴区', '230900'), +('230903', '桃山区', '230900'), +('230904', '茄子河区', '230900'), +('230921', '勃利县', '230900'), +('231000', '牡丹江市', '230000'), +('231002', '东安区', '231000'), +('231003', '阳明区', '231000'), +('231004', '爱民区', '231000'), +('231005', '西安区', '231000'), +('231025', '林口县', '231000'), +('231081', '绥芬河市', '231000'), +('231083', '海林市', '231000'), +('231084', '宁安市', '231000'), +('231085', '穆棱市', '231000'), +('231086', '东宁市', '231000'), +('231100', '黑河市', '230000'), +('231102', '爱辉区', '231100'), +('231121', '嫩江县', '231100'), +('231123', '逊克县', '231100'), +('231124', '孙吴县', '231100'), +('231181', '北安市', '231100'), +('231182', '五大连池市', '231100'), +('231200', '绥化市', '230000'), +('231202', '北林区', '231200'), +('231221', '望奎县', '231200'), +('231222', '兰西县', '231200'), +('231223', '青冈县', '231200'), +('231224', '庆安县', '231200'), +('231225', '明水县', '231200'), +('231226', '绥棱县', '231200'), +('231281', '安达市', '231200'), +('231282', '肇东市', '231200'), +('231283', '海伦市', '231200'), +('232700', '大兴安岭地区', '230000'), +('232721', '呼玛县', '232700'), +('232722', '塔河县', '232700'), +('232723', '漠河县', '232700'), +('310000', '上海市', null), +('310100', '上海市', '310000'), +('310101', '黄浦区', '310100'), +('310104', '徐汇区', '310100'), +('310105', '长宁区', '310100'), +('310106', '静安区', '310100'), +('310107', '普陀区', '310100'), +('310109', '虹口区', '310100'), +('310110', '杨浦区', '310100'), +('310112', '闵行区', '310100'), +('310113', '宝山区', '310100'), +('310114', '嘉定区', '310100'), +('310115', '浦东新区', '310100'), +('310116', '金山区', '310100'), +('310117', '松江区', '310100'), +('310118', '青浦区', '310100'), +('310120', '奉贤区', '310100'), +('310151', '崇明区', '310100'), +('320000', '江苏省', null), +('320100', '南京市', '320000'), +('320102', '玄武区', '320100'), +('320104', '秦淮区', '320100'), +('320105', '建邺区', '320100'), +('320106', '鼓楼区', '320100'), +('320111', '浦口区', '320100'), +('320113', '栖霞区', '320100'), +('320114', '雨花台区', '320100'), +('320115', '江宁区', '320100'), +('320116', '六合区', '320100'), +('320117', '溧水区', '320100'), +('320118', '高淳区', '320100'), +('320200', '无锡市', '320000'), +('320205', '锡山区', '320200'), +('320206', '惠山区', '320200'), +('320211', '滨湖区', '320200'), +('320213', '梁溪区', '320200'), +('320214', '新吴区', '320200'), +('320281', '江阴市', '320200'), +('320282', '宜兴市', '320200'), +('320300', '徐州市', '320000'), +('320302', '鼓楼区', '320300'), +('320303', '云龙区', '320300'), +('320305', '贾汪区', '320300'), +('320311', '泉山区', '320300'), +('320312', '铜山区', '320300'), +('320321', '丰县', '320300'), +('320322', '沛县', '320300'), +('320324', '睢宁县', '320300'), +('320381', '新沂市', '320300'), +('320382', '邳州市', '320300'), +('320400', '常州市', '320000'), +('320402', '天宁区', '320400'), +('320404', '钟楼区', '320400'), +('320411', '新北区', '320400'), +('320412', '武进区', '320400'), +('320413', '金坛区', '320400'), +('320481', '溧阳市', '320400'), +('320500', '苏州市', '320000'), +('320505', '虎丘区', '320500'), +('320506', '吴中区', '320500'), +('320507', '相城区', '320500'), +('320508', '姑苏区', '320500'), +('320509', '吴江区', '320500'), +('320581', '常熟市', '320500'), +('320582', '张家港市', '320500'), +('320583', '昆山市', '320500'), +('320585', '太仓市', '320500'), +('320600', '南通市', '320000'), +('320602', '崇川区', '320600'), +('320611', '港闸区', '320600'), +('320612', '通州区', '320600'), +('320621', '海安县', '320600'), +('320623', '如东县', '320600'), +('320681', '启东市', '320600'), +('320682', '如皋市', '320600'), +('320684', '海门市', '320600'), +('320700', '连云港市', '320000'), +('320703', '连云区', '320700'), +('320706', '海州区', '320700'), +('320707', '赣榆区', '320700'), +('320722', '东海县', '320700'), +('320723', '灌云县', '320700'), +('320724', '灌南县', '320700'), +('320800', '淮安市', '320000'), +('320803', '淮安区', '320800'), +('320804', '淮阴区', '320800'), +('320812', '清江浦区', '320800'), +('320813', '洪泽区', '320800'), +('320826', '涟水县', '320800'), +('320830', '盱眙县', '320800'), +('320831', '金湖县', '320800'), +('320900', '盐城市', '320000'), +('320902', '亭湖区', '320900'), +('320903', '盐都区', '320900'), +('320904', '大丰区', '320900'), +('320921', '响水县', '320900'), +('320922', '滨海县', '320900'), +('320923', '阜宁县', '320900'), +('320924', '射阳县', '320900'), +('320925', '建湖县', '320900'), +('320981', '东台市', '320900'), +('321000', '扬州市', '320000'), +('321002', '广陵区', '321000'), +('321003', '邗江区', '321000'), +('321012', '江都区', '321000'), +('321023', '宝应县', '321000'), +('321081', '仪征市', '321000'), +('321084', '高邮市', '321000'), +('321100', '镇江市', '320000'), +('321102', '京口区', '321100'), +('321111', '润州区', '321100'), +('321112', '丹徒区', '321100'), +('321181', '丹阳市', '321100'), +('321182', '扬中市', '321100'), +('321183', '句容市', '321100'), +('321200', '泰州市', '320000'), +('321202', '海陵区', '321200'), +('321203', '高港区', '321200'), +('321204', '姜堰区', '321200'), +('321281', '兴化市', '321200'), +('321282', '靖江市', '321200'), +('321283', '泰兴市', '321200'), +('321300', '宿迁市', '320000'), +('321302', '宿城区', '321300'), +('321311', '宿豫区', '321300'), +('321322', '沭阳县', '321300'), +('321323', '泗阳县', '321300'), +('321324', '泗洪县', '321300'), +('330000', '浙江省', null), +('330100', '杭州市', '330000'), +('330102', '上城区', '330100'), +('330103', '下城区', '330100'), +('330104', '江干区', '330100'), +('330105', '拱墅区', '330100'), +('330106', '西湖区', '330100'), +('330108', '滨江区', '330100'), +('330109', '萧山区', '330100'), +('330110', '余杭区', '330100'), +('330111', '富阳区', '330100'), +('330122', '桐庐县', '330100'), +('330127', '淳安县', '330100'), +('330182', '建德市', '330100'), +('330185', '临安市', '330100'), +('330200', '宁波市', '330000'), +('330203', '海曙区', '330200'), +('330204', '江东区', '330200'), +('330205', '江北区', '330200'), +('330206', '北仑区', '330200'), +('330211', '镇海区', '330200'), +('330212', '鄞州区', '330200'), +('330225', '象山县', '330200'), +('330226', '宁海县', '330200'), +('330281', '余姚市', '330200'), +('330282', '慈溪市', '330200'), +('330283', '奉化市', '330200'), +('330300', '温州市', '330000'), +('330302', '鹿城区', '330300'), +('330303', '龙湾区', '330300'), +('330304', '瓯海区', '330300'), +('330305', '洞头区', '330300'), +('330324', '永嘉县', '330300'), +('330326', '平阳县', '330300'), +('330327', '苍南县', '330300'), +('330328', '文成县', '330300'), +('330329', '泰顺县', '330300'), +('330381', '瑞安市', '330300'), +('330382', '乐清市', '330300'), +('330400', '嘉兴市', '330000'), +('330402', '南湖区', '330400'), +('330411', '秀洲区', '330400'), +('330421', '嘉善县', '330400'), +('330424', '海盐县', '330400'), +('330481', '海宁市', '330400'), +('330482', '平湖市', '330400'), +('330483', '桐乡市', '330400'), +('330500', '湖州市', '330000'), +('330502', '吴兴区', '330500'), +('330503', '南浔区', '330500'), +('330521', '德清县', '330500'), +('330522', '长兴县', '330500'), +('330523', '安吉县', '330500'), +('330600', '绍兴市', '330000'), +('330602', '越城区', '330600'), +('330603', '柯桥区', '330600'), +('330604', '上虞区', '330600'), +('330624', '新昌县', '330600'), +('330681', '诸暨市', '330600'), +('330683', '嵊州市', '330600'), +('330700', '金华市', '330000'), +('330702', '婺城区', '330700'), +('330703', '金东区', '330700'), +('330723', '武义县', '330700'), +('330726', '浦江县', '330700'), +('330727', '磐安县', '330700'), +('330781', '兰溪市', '330700'), +('330782', '义乌市', '330700'), +('330783', '东阳市', '330700'), +('330784', '永康市', '330700'), +('330800', '衢州市', '330000'), +('330802', '柯城区', '330800'), +('330803', '衢江区', '330800'), +('330822', '常山县', '330800'), +('330824', '开化县', '330800'), +('330825', '龙游县', '330800'), +('330881', '江山市', '330800'), +('330900', '舟山市', '330000'), +('330902', '定海区', '330900'), +('330903', '普陀区', '330900'), +('330921', '岱山县', '330900'), +('330922', '嵊泗县', '330900'), +('331000', '台州市', '330000'), +('331002', '椒江区', '331000'), +('331003', '黄岩区', '331000'), +('331004', '路桥区', '331000'), +('331021', '玉环县', '331000'), +('331022', '三门县', '331000'), +('331023', '天台县', '331000'), +('331024', '仙居县', '331000'), +('331081', '温岭市', '331000'), +('331082', '临海市', '331000'), +('331100', '丽水市', '330000'), +('331102', '莲都区', '331100'), +('331121', '青田县', '331100'), +('331122', '缙云县', '331100'), +('331123', '遂昌县', '331100'), +('331124', '松阳县', '331100'), +('331125', '云和县', '331100'), +('331126', '庆元县', '331100'), +('331127', '景宁畲族自治县', '331100'), +('331181', '龙泉市', '331100'), +('340000', '安徽省', null), +('340100', '合肥市', '340000'), +('340102', '瑶海区', '340100'), +('340103', '庐阳区', '340100'), +('340104', '蜀山区', '340100'), +('340111', '包河区', '340100'), +('340121', '长丰县', '340100'), +('340122', '肥东县', '340100'), +('340123', '肥西县', '340100'), +('340124', '庐江县', '340100'), +('340181', '巢湖市', '340100'), +('340200', '芜湖市', '340000'), +('340202', '镜湖区', '340200'), +('340203', '弋江区', '340200'), +('340207', '鸠江区', '340200'), +('340208', '三山区', '340200'), +('340221', '芜湖县', '340200'), +('340222', '繁昌县', '340200'), +('340223', '南陵县', '340200'), +('340225', '无为县', '340200'), +('340300', '蚌埠市', '340000'), +('340302', '龙子湖区', '340300'), +('340303', '蚌山区', '340300'), +('340304', '禹会区', '340300'), +('340311', '淮上区', '340300'), +('340321', '怀远县', '340300'), +('340322', '五河县', '340300'), +('340323', '固镇县', '340300'), +('340400', '淮南市', '340000'), +('340402', '大通区', '340400'), +('340403', '田家庵区', '340400'), +('340404', '谢家集区', '340400'), +('340405', '八公山区', '340400'), +('340406', '潘集区', '340400'), +('340421', '凤台县', '340400'), +('340422', '寿县', '340400'), +('340500', '马鞍山市', '340000'), +('340503', '花山区', '340500'), +('340504', '雨山区', '340500'), +('340506', '博望区', '340500'), +('340521', '当涂县', '340500'), +('340522', '含山县', '340500'), +('340523', '和县', '340500'), +('340600', '淮北市', '340000'), +('340602', '杜集区', '340600'), +('340603', '相山区', '340600'), +('340604', '烈山区', '340600'), +('340621', '濉溪县', '340600'), +('340700', '铜陵市', '340000'), +('340705', '铜官区', '340700'), +('340706', '义安区', '340700'), +('340711', '郊区', '340700'), +('340722', '枞阳县', '340700'), +('340800', '安庆市', '340000'), +('340802', '迎江区', '340800'), +('340803', '大观区', '340800'), +('340811', '宜秀区', '340800'), +('340822', '怀宁县', '340800'), +('340824', '潜山县', '340800'), +('340825', '太湖县', '340800'), +('340826', '宿松县', '340800'), +('340827', '望江县', '340800'), +('340828', '岳西县', '340800'), +('340881', '桐城市', '340800'), +('341000', '黄山市', '340000'), +('341002', '屯溪区', '341000'), +('341003', '黄山区', '341000'), +('341004', '徽州区', '341000'), +('341021', '歙县', '341000'), +('341022', '休宁县', '341000'), +('341023', '黟县', '341000'), +('341024', '祁门县', '341000'), +('341100', '滁州市', '340000'), +('341102', '琅琊区', '341100'), +('341103', '南谯区', '341100'), +('341122', '来安县', '341100'), +('341124', '全椒县', '341100'), +('341125', '定远县', '341100'), +('341126', '凤阳县', '341100'), +('341181', '天长市', '341100'), +('341182', '明光市', '341100'), +('341200', '阜阳市', '340000'), +('341202', '颍州区', '341200'), +('341203', '颍东区', '341200'), +('341204', '颍泉区', '341200'), +('341221', '临泉县', '341200'), +('341222', '太和县', '341200'), +('341225', '阜南县', '341200'), +('341226', '颍上县', '341200'), +('341282', '界首市', '341200'), +('341300', '宿州市', '340000'), +('341302', '埇桥区', '341300'), +('341321', '砀山县', '341300'), +('341322', '萧县', '341300'), +('341323', '灵璧县', '341300'), +('341324', '泗县', '341300'), +('341500', '六安市', '340000'), +('341502', '金安区', '341500'), +('341503', '裕安区', '341500'), +('341504', '叶集区', '341500'), +('341522', '霍邱县', '341500'), +('341523', '舒城县', '341500'), +('341524', '金寨县', '341500'), +('341525', '霍山县', '341500'), +('341600', '亳州市', '340000'), +('341602', '谯城区', '341600'), +('341621', '涡阳县', '341600'), +('341622', '蒙城县', '341600'), +('341623', '利辛县', '341600'), +('341700', '池州市', '340000'), +('341702', '贵池区', '341700'), +('341721', '东至县', '341700'), +('341722', '石台县', '341700'), +('341723', '青阳县', '341700'), +('341800', '宣城市', '340000'), +('341802', '宣州区', '341800'), +('341821', '郎溪县', '341800'), +('341822', '广德县', '341800'), +('341823', '泾县', '341800'), +('341824', '绩溪县', '341800'), +('341825', '旌德县', '341800'), +('341881', '宁国市', '341800'), +('350000', '福建省', null), +('350100', '福州市', '350000'), +('350102', '鼓楼区', '350100'), +('350103', '台江区', '350100'), +('350104', '仓山区', '350100'), +('350105', '马尾区', '350100'), +('350111', '晋安区', '350100'), +('350121', '闽侯县', '350100'), +('350122', '连江县', '350100'), +('350123', '罗源县', '350100'), +('350124', '闽清县', '350100'), +('350125', '永泰县', '350100'), +('350128', '平潭县', '350100'), +('350181', '福清市', '350100'), +('350182', '长乐市', '350100'), +('350200', '厦门市', '350000'), +('350203', '思明区', '350200'), +('350205', '海沧区', '350200'), +('350206', '湖里区', '350200'), +('350211', '集美区', '350200'), +('350212', '同安区', '350200'), +('350213', '翔安区', '350200'), +('350300', '莆田市', '350000'), +('350302', '城厢区', '350300'), +('350303', '涵江区', '350300'), +('350304', '荔城区', '350300'), +('350305', '秀屿区', '350300'), +('350322', '仙游县', '350300'), +('350400', '三明市', '350000'), +('350402', '梅列区', '350400'), +('350403', '三元区', '350400'), +('350421', '明溪县', '350400'), +('350423', '清流县', '350400'), +('350424', '宁化县', '350400'), +('350425', '大田县', '350400'), +('350426', '尤溪县', '350400'), +('350427', '沙县', '350400'), +('350428', '将乐县', '350400'), +('350429', '泰宁县', '350400'), +('350430', '建宁县', '350400'), +('350481', '永安市', '350400'), +('350500', '泉州市', '350000'), +('350502', '鲤城区', '350500'), +('350503', '丰泽区', '350500'), +('350504', '洛江区', '350500'), +('350505', '泉港区', '350500'), +('350521', '惠安县', '350500'), +('350524', '安溪县', '350500'), +('350525', '永春县', '350500'), +('350526', '德化县', '350500'), +('350527', '金门县', '350500'), +('350581', '石狮市', '350500'), +('350582', '晋江市', '350500'), +('350583', '南安市', '350500'), +('350600', '漳州市', '350000'), +('350602', '芗城区', '350600'), +('350603', '龙文区', '350600'), +('350622', '云霄县', '350600'), +('350623', '漳浦县', '350600'), +('350624', '诏安县', '350600'), +('350625', '长泰县', '350600'), +('350626', '东山县', '350600'), +('350627', '南靖县', '350600'), +('350628', '平和县', '350600'), +('350629', '华安县', '350600'), +('350681', '龙海市', '350600'), +('350700', '南平市', '350000'), +('350702', '延平区', '350700'), +('350703', '建阳区', '350700'), +('350721', '顺昌县', '350700'), +('350722', '浦城县', '350700'), +('350723', '光泽县', '350700'), +('350724', '松溪县', '350700'), +('350725', '政和县', '350700'), +('350781', '邵武市', '350700'), +('350782', '武夷山市', '350700'), +('350783', '建瓯市', '350700'), +('350800', '龙岩市', '350000'), +('350802', '新罗区', '350800'), +('350803', '永定区', '350800'), +('350821', '长汀县', '350800'), +('350823', '上杭县', '350800'), +('350824', '武平县', '350800'), +('350825', '连城县', '350800'), +('350881', '漳平市', '350800'), +('350900', '宁德市', '350000'), +('350902', '蕉城区', '350900'), +('350921', '霞浦县', '350900'), +('350922', '古田县', '350900'), +('350923', '屏南县', '350900'), +('350924', '寿宁县', '350900'), +('350925', '周宁县', '350900'), +('350926', '柘荣县', '350900'), +('350981', '福安市', '350900'), +('350982', '福鼎市', '350900'), +('360000', '江西省', null), +('360100', '南昌市', '360000'), +('360102', '东湖区', '360100'), +('360103', '西湖区', '360100'), +('360104', '青云谱区', '360100'), +('360105', '湾里区', '360100'), +('360111', '青山湖区', '360100'), +('360112', '新建区', '360100'), +('360121', '南昌县', '360100'), +('360123', '安义县', '360100'), +('360124', '进贤县', '360100'), +('360200', '景德镇市', '360000'), +('360202', '昌江区', '360200'), +('360203', '珠山区', '360200'), +('360222', '浮梁县', '360200'), +('360281', '乐平市', '360200'), +('360300', '萍乡市', '360000'), +('360302', '安源区', '360300'), +('360313', '湘东区', '360300'), +('360321', '莲花县', '360300'), +('360322', '上栗县', '360300'), +('360323', '芦溪县', '360300'), +('360400', '九江市', '360000'), +('360402', '濂溪区', '360400'), +('360403', '浔阳区', '360400'), +('360421', '九江县', '360400'), +('360423', '武宁县', '360400'), +('360424', '修水县', '360400'), +('360425', '永修县', '360400'), +('360426', '德安县', '360400'), +('360428', '都昌县', '360400'), +('360429', '湖口县', '360400'), +('360430', '彭泽县', '360400'), +('360481', '瑞昌市', '360400'), +('360482', '共青城市', '360400'), +('360483', '庐山市', '360400'), +('360500', '新余市', '360000'), +('360502', '渝水区', '360500'), +('360521', '分宜县', '360500'), +('360600', '鹰潭市', '360000'), +('360602', '月湖区', '360600'), +('360622', '余江县', '360600'), +('360681', '贵溪市', '360600'), +('360700', '赣州市', '360000'), +('360702', '章贡区', '360700'), +('360703', '南康区', '360700'), +('360721', '赣县', '360700'), +('360722', '信丰县', '360700'), +('360723', '大余县', '360700'), +('360724', '上犹县', '360700'), +('360725', '崇义县', '360700'), +('360726', '安远县', '360700'), +('360727', '龙南县', '360700'), +('360728', '定南县', '360700'), +('360729', '全南县', '360700'), +('360730', '宁都县', '360700'), +('360731', '于都县', '360700'), +('360732', '兴国县', '360700'), +('360733', '会昌县', '360700'), +('360734', '寻乌县', '360700'), +('360735', '石城县', '360700'), +('360781', '瑞金市', '360700'), +('360800', '吉安市', '360000'), +('360802', '吉州区', '360800'), +('360803', '青原区', '360800'), +('360821', '吉安县', '360800'), +('360822', '吉水县', '360800'), +('360823', '峡江县', '360800'), +('360824', '新干县', '360800'), +('360825', '永丰县', '360800'), +('360826', '泰和县', '360800'), +('360827', '遂川县', '360800'), +('360828', '万安县', '360800'), +('360829', '安福县', '360800'), +('360830', '永新县', '360800'), +('360881', '井冈山市', '360800'), +('360900', '宜春市', '360000'), +('360902', '袁州区', '360900'), +('360921', '奉新县', '360900'), +('360922', '万载县', '360900'), +('360923', '上高县', '360900'), +('360924', '宜丰县', '360900'), +('360925', '靖安县', '360900'), +('360926', '铜鼓县', '360900'), +('360981', '丰城市', '360900'), +('360982', '樟树市', '360900'), +('360983', '高安市', '360900'), +('361000', '抚州市', '360000'), +('361002', '临川区', '361000'), +('361021', '南城县', '361000'), +('361022', '黎川县', '361000'), +('361023', '南丰县', '361000'), +('361024', '崇仁县', '361000'), +('361025', '乐安县', '361000'), +('361026', '宜黄县', '361000'), +('361027', '金溪县', '361000'), +('361028', '资溪县', '361000'), +('361029', '东乡县', '361000'), +('361030', '广昌县', '361000'), +('361100', '上饶市', '360000'), +('361102', '信州区', '361100'), +('361103', '广丰区', '361100'), +('361121', '上饶县', '361100'), +('361123', '玉山县', '361100'), +('361124', '铅山县', '361100'), +('361125', '横峰县', '361100'), +('361126', '弋阳县', '361100'), +('361127', '余干县', '361100'), +('361128', '鄱阳县', '361100'), +('361129', '万年县', '361100'), +('361130', '婺源县', '361100'), +('361181', '德兴市', '361100'), +('370000', '山东省', null), +('370100', '济南市', '370000'), +('370102', '历下区', '370100'), +('370103', '市中区', '370100'), +('370104', '槐荫区', '370100'), +('370105', '天桥区', '370100'), +('370112', '历城区', '370100'), +('370113', '长清区', '370100'), +('370124', '平阴县', '370100'), +('370125', '济阳县', '370100'), +('370126', '商河县', '370100'), +('370181', '章丘市', '370100'), +('370200', '青岛市', '370000'), +('370202', '市南区', '370200'), +('370203', '市北区', '370200'), +('370211', '黄岛区', '370200'), +('370212', '崂山区', '370200'), +('370213', '李沧区', '370200'), +('370214', '城阳区', '370200'), +('370281', '胶州市', '370200'), +('370282', '即墨市', '370200'), +('370283', '平度市', '370200'), +('370285', '莱西市', '370200'), +('370300', '淄博市', '370000'), +('370302', '淄川区', '370300'), +('370303', '张店区', '370300'), +('370304', '博山区', '370300'), +('370305', '临淄区', '370300'), +('370306', '周村区', '370300'), +('370321', '桓台县', '370300'), +('370322', '高青县', '370300'), +('370323', '沂源县', '370300'), +('370400', '枣庄市', '370000'), +('370402', '市中区', '370400'), +('370403', '薛城区', '370400'), +('370404', '峄城区', '370400'), +('370405', '台儿庄区', '370400'), +('370406', '山亭区', '370400'), +('370481', '滕州市', '370400'), +('370500', '东营市', '370000'), +('370502', '东营区', '370500'), +('370503', '河口区', '370500'), +('370505', '垦利区', '370500'), +('370522', '利津县', '370500'), +('370523', '广饶县', '370500'), +('370600', '烟台市', '370000'), +('370602', '芝罘区', '370600'), +('370611', '福山区', '370600'), +('370612', '牟平区', '370600'), +('370613', '莱山区', '370600'), +('370634', '长岛县', '370600'), +('370681', '龙口市', '370600'), +('370682', '莱阳市', '370600'), +('370683', '莱州市', '370600'), +('370684', '蓬莱市', '370600'), +('370685', '招远市', '370600'), +('370686', '栖霞市', '370600'), +('370687', '海阳市', '370600'), +('370700', '潍坊市', '370000'), +('370702', '潍城区', '370700'), +('370703', '寒亭区', '370700'), +('370704', '坊子区', '370700'), +('370705', '奎文区', '370700'), +('370724', '临朐县', '370700'), +('370725', '昌乐县', '370700'), +('370781', '青州市', '370700'), +('370782', '诸城市', '370700'), +('370783', '寿光市', '370700'), +('370784', '安丘市', '370700'), +('370785', '高密市', '370700'), +('370786', '昌邑市', '370700'), +('370800', '济宁市', '370000'), +('370811', '任城区', '370800'), +('370812', '兖州区', '370800'), +('370826', '微山县', '370800'), +('370827', '鱼台县', '370800'), +('370828', '金乡县', '370800'), +('370829', '嘉祥县', '370800'), +('370830', '汶上县', '370800'), +('370831', '泗水县', '370800'), +('370832', '梁山县', '370800'), +('370881', '曲阜市', '370800'), +('370883', '邹城市', '370800'), +('370900', '泰安市', '370000'), +('370902', '泰山区', '370900'), +('370911', '岱岳区', '370900'), +('370921', '宁阳县', '370900'), +('370923', '东平县', '370900'), +('370982', '新泰市', '370900'), +('370983', '肥城市', '370900'), +('371000', '威海市', '370000'), +('371002', '环翠区', '371000'), +('371003', '文登区', '371000'), +('371082', '荣成市', '371000'), +('371083', '乳山市', '371000'), +('371100', '日照市', '370000'), +('371102', '东港区', '371100'), +('371103', '岚山区', '371100'), +('371121', '五莲县', '371100'), +('371122', '莒县', '371100'), +('371200', '莱芜市', '370000'), +('371202', '莱城区', '371200'), +('371203', '钢城区', '371200'), +('371300', '临沂市', '370000'), +('371302', '兰山区', '371300'), +('371311', '罗庄区', '371300'), +('371312', '河东区', '371300'), +('371321', '沂南县', '371300'), +('371322', '郯城县', '371300'), +('371323', '沂水县', '371300'), +('371324', '兰陵县', '371300'), +('371325', '费县', '371300'), +('371326', '平邑县', '371300'), +('371327', '莒南县', '371300'), +('371328', '蒙阴县', '371300'), +('371329', '临沭县', '371300'), +('371400', '德州市', '370000'), +('371402', '德城区', '371400'), +('371403', '陵城区', '371400'), +('371422', '宁津县', '371400'), +('371423', '庆云县', '371400'), +('371424', '临邑县', '371400'), +('371425', '齐河县', '371400'), +('371426', '平原县', '371400'), +('371427', '夏津县', '371400'), +('371428', '武城县', '371400'), +('371481', '乐陵市', '371400'), +('371482', '禹城市', '371400'), +('371500', '聊城市', '370000'), +('371502', '东昌府区', '371500'), +('371521', '阳谷县', '371500'), +('371522', '莘县', '371500'), +('371523', '茌平县', '371500'), +('371524', '东阿县', '371500'), +('371525', '冠县', '371500'), +('371526', '高唐县', '371500'), +('371581', '临清市', '371500'), +('371600', '滨州市', '370000'), +('371602', '滨城区', '371600'), +('371603', '沾化区', '371600'), +('371621', '惠民县', '371600'), +('371622', '阳信县', '371600'), +('371623', '无棣县', '371600'), +('371625', '博兴县', '371600'), +('371626', '邹平县', '371600'), +('371700', '菏泽市', '370000'), +('371702', '牡丹区', '371700'), +('371703', '定陶区', '371700'), +('371721', '曹县', '371700'), +('371722', '单县', '371700'), +('371723', '成武县', '371700'), +('371724', '巨野县', '371700'), +('371725', '郓城县', '371700'), +('371726', '鄄城县', '371700'), +('371728', '东明县', '371700'), +('410000', '河南省', null), +('410100', '郑州市', '410000'), +('410102', '中原区', '410100'), +('410103', '二七区', '410100'), +('410104', '管城回族区', '410100'), +('410105', '金水区', '410100'), +('410106', '上街区', '410100'), +('410108', '惠济区', '410100'), +('410122', '中牟县', '410100'), +('410181', '巩义市', '410100'), +('410182', '荥阳市', '410100'), +('410183', '新密市', '410100'), +('410184', '新郑市', '410100'), +('410185', '登封市', '410100'), +('410200', '开封市', '410000'), +('410202', '龙亭区', '410200'), +('410203', '顺河回族区', '410200'), +('410204', '鼓楼区', '410200'), +('410205', '禹王台区', '410200'), +('410211', '金明区', '410200'), +('410212', '祥符区', '410200'), +('410221', '杞县', '410200'), +('410222', '通许县', '410200'), +('410223', '尉氏县', '410200'), +('410225', '兰考县', '410200'), +('410300', '洛阳市', '410000'), +('410302', '老城区', '410300'), +('410303', '西工区', '410300'), +('410304', '瀍河回族区', '410300'), +('410305', '涧西区', '410300'), +('410306', '吉利区', '410300'), +('410311', '洛龙区', '410300'), +('410322', '孟津县', '410300'), +('410323', '新安县', '410300'), +('410324', '栾川县', '410300'), +('410325', '嵩县', '410300'), +('410326', '汝阳县', '410300'), +('410327', '宜阳县', '410300'), +('410328', '洛宁县', '410300'), +('410329', '伊川县', '410300'), +('410381', '偃师市', '410300'), +('410400', '平顶山市', '410000'), +('410402', '新华区', '410400'), +('410403', '卫东区', '410400'), +('410404', '石龙区', '410400'), +('410411', '湛河区', '410400'), +('410421', '宝丰县', '410400'), +('410422', '叶县', '410400'), +('410423', '鲁山县', '410400'), +('410425', '郏县', '410400'), +('410481', '舞钢市', '410400'), +('410482', '汝州市', '410400'), +('410500', '安阳市', '410000'), +('410502', '文峰区', '410500'), +('410503', '北关区', '410500'), +('410505', '殷都区', '410500'), +('410506', '龙安区', '410500'), +('410522', '安阳县', '410500'), +('410523', '汤阴县', '410500'), +('410526', '滑县', '410500'), +('410527', '内黄县', '410500'), +('410581', '林州市', '410500'), +('410600', '鹤壁市', '410000'), +('410602', '鹤山区', '410600'), +('410603', '山城区', '410600'), +('410611', '淇滨区', '410600'), +('410621', '浚县', '410600'), +('410622', '淇县', '410600'), +('410700', '新乡市', '410000'), +('410702', '红旗区', '410700'), +('410703', '卫滨区', '410700'), +('410704', '凤泉区', '410700'), +('410711', '牧野区', '410700'), +('410721', '新乡县', '410700'), +('410724', '获嘉县', '410700'), +('410725', '原阳县', '410700'), +('410726', '延津县', '410700'), +('410727', '封丘县', '410700'), +('410728', '长垣县', '410700'), +('410781', '卫辉市', '410700'), +('410782', '辉县市', '410700'), +('410800', '焦作市', '410000'), +('410802', '解放区', '410800'), +('410803', '中站区', '410800'), +('410804', '马村区', '410800'), +('410811', '山阳区', '410800'), +('410821', '修武县', '410800'), +('410822', '博爱县', '410800'), +('410823', '武陟县', '410800'), +('410825', '温县', '410800'), +('410882', '沁阳市', '410800'), +('410883', '孟州市', '410800'), +('410900', '濮阳市', '410000'), +('410902', '华龙区', '410900'), +('410922', '清丰县', '410900'), +('410923', '南乐县', '410900'), +('410926', '范县', '410900'), +('410927', '台前县', '410900'), +('410928', '濮阳县', '410900'), +('411000', '许昌市', '410000'), +('411002', '魏都区', '411000'), +('411023', '许昌县', '411000'), +('411024', '鄢陵县', '411000'), +('411025', '襄城县', '411000'), +('411081', '禹州市', '411000'), +('411082', '长葛市', '411000'), +('411100', '漯河市', '410000'), +('411102', '源汇区', '411100'), +('411103', '郾城区', '411100'), +('411104', '召陵区', '411100'), +('411121', '舞阳县', '411100'), +('411122', '临颍县', '411100'), +('411200', '三门峡市', '410000'), +('411202', '湖滨区', '411200'), +('411203', '陕州区', '411200'), +('411221', '渑池县', '411200'), +('411224', '卢氏县', '411200'), +('411281', '义马市', '411200'), +('411282', '灵宝市', '411200'), +('411300', '南阳市', '410000'), +('411302', '宛城区', '411300'), +('411303', '卧龙区', '411300'), +('411321', '南召县', '411300'), +('411322', '方城县', '411300'), +('411323', '西峡县', '411300'), +('411324', '镇平县', '411300'), +('411325', '内乡县', '411300'), +('411326', '淅川县', '411300'), +('411327', '社旗县', '411300'), +('411328', '唐河县', '411300'), +('411329', '新野县', '411300'), +('411330', '桐柏县', '411300'), +('411381', '邓州市', '411300'), +('411400', '商丘市', '410000'), +('411402', '梁园区', '411400'), +('411403', '睢阳区', '411400'), +('411421', '民权县', '411400'), +('411422', '睢县', '411400'), +('411423', '宁陵县', '411400'), +('411424', '柘城县', '411400'), +('411425', '虞城县', '411400'), +('411426', '夏邑县', '411400'), +('411481', '永城市', '411400'), +('411500', '信阳市', '410000'), +('411502', '浉河区', '411500'), +('411503', '平桥区', '411500'), +('411521', '罗山县', '411500'), +('411522', '光山县', '411500'), +('411523', '新县', '411500'), +('411524', '商城县', '411500'), +('411525', '固始县', '411500'), +('411526', '潢川县', '411500'), +('411527', '淮滨县', '411500'), +('411528', '息县', '411500'), +('411600', '周口市', '410000'), +('411602', '川汇区', '411600'), +('411621', '扶沟县', '411600'), +('411622', '西华县', '411600'), +('411623', '商水县', '411600'), +('411624', '沈丘县', '411600'), +('411625', '郸城县', '411600'), +('411626', '淮阳县', '411600'), +('411627', '太康县', '411600'), +('411628', '鹿邑县', '411600'), +('411681', '项城市', '411600'), +('411700', '驻马店市', '410000'), +('411702', '驿城区', '411700'), +('411721', '西平县', '411700'), +('411722', '上蔡县', '411700'), +('411723', '平舆县', '411700'), +('411724', '正阳县', '411700'), +('411725', '确山县', '411700'), +('411726', '泌阳县', '411700'), +('411727', '汝南县', '411700'), +('411728', '遂平县', '411700'), +('411729', '新蔡县', '411700'), +('419000', '省直辖县级行政区划', '410000'), +('419001', '济源市', '419000'), +('420000', '湖北省', null), +('420100', '武汉市', '420000'), +('420102', '江岸区', '420100'), +('420103', '江汉区', '420100'), +('420104', '硚口区', '420100'), +('420105', '汉阳区', '420100'), +('420106', '武昌区', '420100'), +('420107', '青山区', '420100'), +('420111', '洪山区', '420100'), +('420112', '东西湖区', '420100'), +('420113', '汉南区', '420100'), +('420114', '蔡甸区', '420100'), +('420115', '江夏区', '420100'), +('420116', '黄陂区', '420100'), +('420117', '新洲区', '420100'), +('420200', '黄石市', '420000'), +('420202', '黄石港区', '420200'), +('420203', '西塞山区', '420200'), +('420204', '下陆区', '420200'), +('420205', '铁山区', '420200'), +('420222', '阳新县', '420200'), +('420281', '大冶市', '420200'), +('420300', '十堰市', '420000'), +('420302', '茅箭区', '420300'), +('420303', '张湾区', '420300'), +('420304', '郧阳区', '420300'), +('420322', '郧西县', '420300'), +('420323', '竹山县', '420300'), +('420324', '竹溪县', '420300'), +('420325', '房县', '420300'), +('420381', '丹江口市', '420300'), +('420500', '宜昌市', '420000'), +('420502', '西陵区', '420500'), +('420503', '伍家岗区', '420500'), +('420504', '点军区', '420500'), +('420505', '猇亭区', '420500'), +('420506', '夷陵区', '420500'), +('420525', '远安县', '420500'), +('420526', '兴山县', '420500'), +('420527', '秭归县', '420500'), +('420528', '长阳土家族自治县', '420500'), +('420529', '五峰土家族自治县', '420500'), +('420581', '宜都市', '420500'), +('420582', '当阳市', '420500'), +('420583', '枝江市', '420500'), +('420600', '襄阳市', '420000'), +('420602', '襄城区', '420600'), +('420606', '樊城区', '420600'), +('420607', '襄州区', '420600'), +('420624', '南漳县', '420600'), +('420625', '谷城县', '420600'), +('420626', '保康县', '420600'), +('420682', '老河口市', '420600'), +('420683', '枣阳市', '420600'), +('420684', '宜城市', '420600'), +('420700', '鄂州市', '420000'), +('420702', '梁子湖区', '420700'), +('420703', '华容区', '420700'), +('420704', '鄂城区', '420700'), +('420800', '荆门市', '420000'), +('420802', '东宝区', '420800'), +('420804', '掇刀区', '420800'), +('420821', '京山县', '420800'), +('420822', '沙洋县', '420800'), +('420881', '钟祥市', '420800'), +('420900', '孝感市', '420000'), +('420902', '孝南区', '420900'), +('420921', '孝昌县', '420900'), +('420922', '大悟县', '420900'), +('420923', '云梦县', '420900'), +('420981', '应城市', '420900'), +('420982', '安陆市', '420900'), +('420984', '汉川市', '420900'), +('421000', '荆州市', '420000'), +('421002', '沙市区', '421000'), +('421003', '荆州区', '421000'), +('421022', '公安县', '421000'), +('421023', '监利县', '421000'), +('421024', '江陵县', '421000'), +('421081', '石首市', '421000'), +('421083', '洪湖市', '421000'), +('421087', '松滋市', '421000'), +('421100', '黄冈市', '420000'), +('421102', '黄州区', '421100'), +('421121', '团风县', '421100'), +('421122', '红安县', '421100'), +('421123', '罗田县', '421100'), +('421124', '英山县', '421100'), +('421125', '浠水县', '421100'), +('421126', '蕲春县', '421100'), +('421127', '黄梅县', '421100'), +('421181', '麻城市', '421100'), +('421182', '武穴市', '421100'), +('421200', '咸宁市', '420000'), +('421202', '咸安区', '421200'), +('421221', '嘉鱼县', '421200'), +('421222', '通城县', '421200'), +('421223', '崇阳县', '421200'), +('421224', '通山县', '421200'), +('421281', '赤壁市', '421200'), +('421300', '随州市', '420000'), +('421303', '曾都区', '421300'), +('421321', '随县', '421300'), +('421381', '广水市', '421300'), +('422800', '恩施土家族苗族自治州', '420000'), +('422801', '恩施市', '422800'), +('422802', '利川市', '422800'), +('422822', '建始县', '422800'), +('422823', '巴东县', '422800'), +('422825', '宣恩县', '422800'), +('422826', '咸丰县', '422800'), +('422827', '来凤县', '422800'), +('422828', '鹤峰县', '422800'), +('429000', '省直辖县级行政区划', '420000'), +('429004', '仙桃市', '429000'), +('429005', '潜江市', '429000'), +('429006', '天门市', '429000'), +('429021', '神农架林区', '429000'), +('430000', '湖南省', null), +('430100', '长沙市', '430000'), +('430102', '芙蓉区', '430100'), +('430103', '天心区', '430100'), +('430104', '岳麓区', '430100'), +('430105', '开福区', '430100'), +('430111', '雨花区', '430100'), +('430112', '望城区', '430100'), +('430121', '长沙县', '430100'), +('430124', '宁乡县', '430100'), +('430181', '浏阳市', '430100'), +('430200', '株洲市', '430000'), +('430202', '荷塘区', '430200'), +('430203', '芦淞区', '430200'), +('430204', '石峰区', '430200'), +('430211', '天元区', '430200'), +('430221', '株洲县', '430200'), +('430223', '攸县', '430200'), +('430224', '茶陵县', '430200'), +('430225', '炎陵县', '430200'), +('430281', '醴陵市', '430200'), +('430300', '湘潭市', '430000'), +('430302', '雨湖区', '430300'), +('430304', '岳塘区', '430300'), +('430321', '湘潭县', '430300'), +('430381', '湘乡市', '430300'), +('430382', '韶山市', '430300'), +('430400', '衡阳市', '430000'), +('430405', '珠晖区', '430400'), +('430406', '雁峰区', '430400'), +('430407', '石鼓区', '430400'), +('430408', '蒸湘区', '430400'), +('430412', '南岳区', '430400'), +('430421', '衡阳县', '430400'), +('430422', '衡南县', '430400'), +('430423', '衡山县', '430400'), +('430424', '衡东县', '430400'), +('430426', '祁东县', '430400'), +('430481', '耒阳市', '430400'), +('430482', '常宁市', '430400'), +('430500', '邵阳市', '430000'), +('430502', '双清区', '430500'), +('430503', '大祥区', '430500'), +('430511', '北塔区', '430500'), +('430521', '邵东县', '430500'), +('430522', '新邵县', '430500'), +('430523', '邵阳县', '430500'), +('430524', '隆回县', '430500'), +('430525', '洞口县', '430500'), +('430527', '绥宁县', '430500'), +('430528', '新宁县', '430500'), +('430529', '城步苗族自治县', '430500'), +('430581', '武冈市', '430500'), +('430600', '岳阳市', '430000'), +('430602', '岳阳楼区', '430600'), +('430603', '云溪区', '430600'), +('430611', '君山区', '430600'), +('430621', '岳阳县', '430600'), +('430623', '华容县', '430600'), +('430624', '湘阴县', '430600'), +('430626', '平江县', '430600'), +('430681', '汨罗市', '430600'), +('430682', '临湘市', '430600'), +('430700', '常德市', '430000'), +('430702', '武陵区', '430700'), +('430703', '鼎城区', '430700'), +('430721', '安乡县', '430700'), +('430722', '汉寿县', '430700'), +('430723', '澧县', '430700'), +('430724', '临澧县', '430700'), +('430725', '桃源县', '430700'), +('430726', '石门县', '430700'), +('430781', '津市市', '430700'), +('430800', '张家界市', '430000'), +('430802', '永定区', '430800'), +('430811', '武陵源区', '430800'), +('430821', '慈利县', '430800'), +('430822', '桑植县', '430800'), +('430900', '益阳市', '430000'), +('430902', '资阳区', '430900'), +('430903', '赫山区', '430900'), +('430921', '南县', '430900'), +('430922', '桃江县', '430900'), +('430923', '安化县', '430900'), +('430981', '沅江市', '430900'), +('431000', '郴州市', '430000'), +('431002', '北湖区', '431000'), +('431003', '苏仙区', '431000'), +('431021', '桂阳县', '431000'), +('431022', '宜章县', '431000'), +('431023', '永兴县', '431000'), +('431024', '嘉禾县', '431000'), +('431025', '临武县', '431000'), +('431026', '汝城县', '431000'), +('431027', '桂东县', '431000'), +('431028', '安仁县', '431000'), +('431081', '资兴市', '431000'), +('431100', '永州市', '430000'), +('431102', '零陵区', '431100'), +('431103', '冷水滩区', '431100'), +('431121', '祁阳县', '431100'), +('431122', '东安县', '431100'), +('431123', '双牌县', '431100'), +('431124', '道县', '431100'), +('431125', '江永县', '431100'), +('431126', '宁远县', '431100'), +('431127', '蓝山县', '431100'), +('431128', '新田县', '431100'), +('431129', '江华瑶族自治县', '431100'), +('431200', '怀化市', '430000'), +('431202', '鹤城区', '431200'), +('431221', '中方县', '431200'), +('431222', '沅陵县', '431200'), +('431223', '辰溪县', '431200'), +('431224', '溆浦县', '431200'), +('431225', '会同县', '431200'), +('431226', '麻阳苗族自治县', '431200'), +('431227', '新晃侗族自治县', '431200'), +('431228', '芷江侗族自治县', '431200'), +('431229', '靖州苗族侗族自治县', '431200'), +('431230', '通道侗族自治县', '431200'), +('431281', '洪江市', '431200'), +('431300', '娄底市', '430000'), +('431302', '娄星区', '431300'), +('431321', '双峰县', '431300'), +('431322', '新化县', '431300'), +('431381', '冷水江市', '431300'), +('431382', '涟源市', '431300'), +('433100', '湘西土家族苗族自治州', '430000'), +('433101', '吉首市', '433100'), +('433122', '泸溪县', '433100'), +('433123', '凤凰县', '433100'), +('433124', '花垣县', '433100'), +('433125', '保靖县', '433100'), +('433126', '古丈县', '433100'), +('433127', '永顺县', '433100'), +('433130', '龙山县', '433100'), +('440000', '广东省', null), +('440100', '广州市', '440000'), +('440103', '荔湾区', '440100'), +('440104', '越秀区', '440100'), +('440105', '海珠区', '440100'), +('440106', '天河区', '440100'), +('440111', '白云区', '440100'), +('440112', '黄埔区', '440100'), +('440113', '番禺区', '440100'), +('440114', '花都区', '440100'), +('440115', '南沙区', '440100'), +('440117', '从化区', '440100'), +('440118', '增城区', '440100'), +('440200', '韶关市', '440000'), +('440203', '武江区', '440200'), +('440204', '浈江区', '440200'), +('440205', '曲江区', '440200'), +('440222', '始兴县', '440200'), +('440224', '仁化县', '440200'), +('440229', '翁源县', '440200'), +('440232', '乳源瑶族自治县', '440200'), +('440233', '新丰县', '440200'), +('440281', '乐昌市', '440200'), +('440282', '南雄市', '440200'), +('440300', '深圳市', '440000'), +('440303', '罗湖区', '440300'), +('440304', '福田区', '440300'), +('440305', '南山区', '440300'), +('440306', '宝安区', '440300'), +('440307', '龙岗区', '440300'), +('440308', '盐田区', '440300'), +('440400', '珠海市', '440000'), +('440402', '香洲区', '440400'), +('440403', '斗门区', '440400'), +('440404', '金湾区', '440400'), +('440500', '汕头市', '440000'), +('440507', '龙湖区', '440500'), +('440511', '金平区', '440500'), +('440512', '濠江区', '440500'), +('440513', '潮阳区', '440500'), +('440514', '潮南区', '440500'), +('440515', '澄海区', '440500'), +('440523', '南澳县', '440500'), +('440600', '佛山市', '440000'), +('440604', '禅城区', '440600'), +('440605', '南海区', '440600'), +('440606', '顺德区', '440600'), +('440607', '三水区', '440600'), +('440608', '高明区', '440600'), +('440700', '江门市', '440000'), +('440703', '蓬江区', '440700'), +('440704', '江海区', '440700'), +('440705', '新会区', '440700'), +('440781', '台山市', '440700'), +('440783', '开平市', '440700'), +('440784', '鹤山市', '440700'), +('440785', '恩平市', '440700'), +('440800', '湛江市', '440000'), +('440802', '赤坎区', '440800'), +('440803', '霞山区', '440800'), +('440804', '坡头区', '440800'), +('440811', '麻章区', '440800'), +('440823', '遂溪县', '440800'), +('440825', '徐闻县', '440800'), +('440881', '廉江市', '440800'), +('440882', '雷州市', '440800'), +('440883', '吴川市', '440800'), +('440900', '茂名市', '440000'), +('440902', '茂南区', '440900'), +('440904', '电白区', '440900'), +('440981', '高州市', '440900'), +('440982', '化州市', '440900'), +('440983', '信宜市', '440900'), +('441200', '肇庆市', '440000'), +('441202', '端州区', '441200'), +('441203', '鼎湖区', '441200'), +('441204', '高要区', '441200'), +('441223', '广宁县', '441200'), +('441224', '怀集县', '441200'), +('441225', '封开县', '441200'), +('441226', '德庆县', '441200'), +('441284', '四会市', '441200'), +('441300', '惠州市', '440000'), +('441302', '惠城区', '441300'), +('441303', '惠阳区', '441300'), +('441322', '博罗县', '441300'), +('441323', '惠东县', '441300'), +('441324', '龙门县', '441300'), +('441400', '梅州市', '440000'), +('441402', '梅江区', '441400'), +('441403', '梅县区', '441400'), +('441422', '大埔县', '441400'), +('441423', '丰顺县', '441400'), +('441424', '五华县', '441400'), +('441426', '平远县', '441400'), +('441427', '蕉岭县', '441400'), +('441481', '兴宁市', '441400'), +('441500', '汕尾市', '440000'), +('441502', '城区', '441500'), +('441521', '海丰县', '441500'), +('441523', '陆河县', '441500'), +('441581', '陆丰市', '441500'), +('441600', '河源市', '440000'), +('441602', '源城区', '441600'), +('441621', '紫金县', '441600'), +('441622', '龙川县', '441600'), +('441623', '连平县', '441600'), +('441624', '和平县', '441600'), +('441625', '东源县', '441600'), +('441700', '阳江市', '440000'), +('441702', '江城区', '441700'), +('441704', '阳东区', '441700'), +('441721', '阳西县', '441700'), +('441781', '阳春市', '441700'), +('441800', '清远市', '440000'), +('441802', '清城区', '441800'), +('441803', '清新区', '441800'), +('441821', '佛冈县', '441800'), +('441823', '阳山县', '441800'), +('441825', '连山壮族瑶族自治县', '441800'), +('441826', '连南瑶族自治县', '441800'), +('441881', '英德市', '441800'), +('441882', '连州市', '441800'), +('441900', '东莞市', '440000'), +('442000', '中山市', '440000'), +('445100', '潮州市', '440000'), +('445102', '湘桥区', '445100'), +('445103', '潮安区', '445100'), +('445122', '饶平县', '445100'), +('445200', '揭阳市', '440000'), +('445202', '榕城区', '445200'), +('445203', '揭东区', '445200'), +('445222', '揭西县', '445200'), +('445224', '惠来县', '445200'), +('445281', '普宁市', '445200'), +('445300', '云浮市', '440000'), +('445302', '云城区', '445300'), +('445303', '云安区', '445300'), +('445321', '新兴县', '445300'), +('445322', '郁南县', '445300'), +('445381', '罗定市', '445300'), +('450000', '广西壮族自治区', null), +('450100', '南宁市', '450000'), +('450102', '兴宁区', '450100'), +('450103', '青秀区', '450100'), +('450105', '江南区', '450100'), +('450107', '西乡塘区', '450100'), +('450108', '良庆区', '450100'), +('450109', '邕宁区', '450100'), +('450110', '武鸣区', '450100'), +('450123', '隆安县', '450100'), +('450124', '马山县', '450100'), +('450125', '上林县', '450100'), +('450126', '宾阳县', '450100'), +('450127', '横县', '450100'), +('450200', '柳州市', '450000'), +('450202', '城中区', '450200'), +('450203', '鱼峰区', '450200'), +('450204', '柳南区', '450200'), +('450205', '柳北区', '450200'), +('450206', '柳江区', '450200'), +('450222', '柳城县', '450200'), +('450223', '鹿寨县', '450200'), +('450224', '融安县', '450200'), +('450225', '融水苗族自治县', '450200'), +('450226', '三江侗族自治县', '450200'), +('450300', '桂林市', '450000'), +('450302', '秀峰区', '450300'), +('450303', '叠彩区', '450300'), +('450304', '象山区', '450300'), +('450305', '七星区', '450300'), +('450311', '雁山区', '450300'), +('450312', '临桂区', '450300'), +('450321', '阳朔县', '450300'), +('450323', '灵川县', '450300'), +('450324', '全州县', '450300'), +('450325', '兴安县', '450300'), +('450326', '永福县', '450300'), +('450327', '灌阳县', '450300'), +('450328', '龙胜各族自治县', '450300'), +('450329', '资源县', '450300'), +('450330', '平乐县', '450300'), +('450331', '荔浦县', '450300'), +('450332', '恭城瑶族自治县', '450300'), +('450400', '梧州市', '450000'), +('450403', '万秀区', '450400'), +('450405', '长洲区', '450400'), +('450406', '龙圩区', '450400'), +('450421', '苍梧县', '450400'), +('450422', '藤县', '450400'), +('450423', '蒙山县', '450400'), +('450481', '岑溪市', '450400'), +('450500', '北海市', '450000'), +('450502', '海城区', '450500'), +('450503', '银海区', '450500'), +('450512', '铁山港区', '450500'), +('450521', '合浦县', '450500'), +('450600', '防城港市', '450000'), +('450602', '港口区', '450600'), +('450603', '防城区', '450600'), +('450621', '上思县', '450600'), +('450681', '东兴市', '450600'), +('450700', '钦州市', '450000'), +('450702', '钦南区', '450700'), +('450703', '钦北区', '450700'), +('450721', '灵山县', '450700'), +('450722', '浦北县', '450700'), +('450800', '贵港市', '450000'), +('450802', '港北区', '450800'), +('450803', '港南区', '450800'), +('450804', '覃塘区', '450800'), +('450821', '平南县', '450800'), +('450881', '桂平市', '450800'), +('450900', '玉林市', '450000'), +('450902', '玉州区', '450900'), +('450903', '福绵区', '450900'), +('450921', '容县', '450900'), +('450922', '陆川县', '450900'), +('450923', '博白县', '450900'), +('450924', '兴业县', '450900'), +('450981', '北流市', '450900'), +('451000', '百色市', '450000'), +('451002', '右江区', '451000'), +('451021', '田阳县', '451000'), +('451022', '田东县', '451000'), +('451023', '平果县', '451000'), +('451024', '德保县', '451000'), +('451026', '那坡县', '451000'), +('451027', '凌云县', '451000'), +('451028', '乐业县', '451000'), +('451029', '田林县', '451000'), +('451030', '西林县', '451000'), +('451031', '隆林各族自治县', '451000'), +('451081', '靖西市', '451000'), +('451100', '贺州市', '450000'), +('451102', '八步区', '451100'), +('451103', '平桂区', '451100'), +('451121', '昭平县', '451100'), +('451122', '钟山县', '451100'), +('451123', '富川瑶族自治县', '451100'), +('451200', '河池市', '450000'), +('451202', '金城江区', '451200'), +('451221', '南丹县', '451200'), +('451222', '天峨县', '451200'), +('451223', '凤山县', '451200'), +('451224', '东兰县', '451200'), +('451225', '罗城仫佬族自治县', '451200'), +('451226', '环江毛南族自治县', '451200'), +('451227', '巴马瑶族自治县', '451200'), +('451228', '都安瑶族自治县', '451200'), +('451229', '大化瑶族自治县', '451200'), +('451281', '宜州市', '451200'), +('451300', '来宾市', '450000'), +('451302', '兴宾区', '451300'), +('451321', '忻城县', '451300'), +('451322', '象州县', '451300'), +('451323', '武宣县', '451300'), +('451324', '金秀瑶族自治县', '451300'), +('451381', '合山市', '451300'), +('451400', '崇左市', '450000'), +('451402', '江州区', '451400'), +('451421', '扶绥县', '451400'), +('451422', '宁明县', '451400'), +('451423', '龙州县', '451400'), +('451424', '大新县', '451400'), +('451425', '天等县', '451400'), +('451481', '凭祥市', '451400'), +('460000', '海南省', null), +('460100', '海口市', '460000'), +('460105', '秀英区', '460100'), +('460106', '龙华区', '460100'), +('460107', '琼山区', '460100'), +('460108', '美兰区', '460100'), +('460200', '三亚市', '460000'), +('460202', '海棠区', '460200'), +('460203', '吉阳区', '460200'), +('460204', '天涯区', '460200'), +('460205', '崖州区', '460200'), +('460300', '三沙市', '460000'), +('460400', '儋州市', '460000'), +('469000', '省直辖县级行政区划', '460000'), +('469001', '五指山市', '469000'), +('469002', '琼海市', '469000'), +('469005', '文昌市', '469000'), +('469006', '万宁市', '469000'), +('469007', '东方市', '469000'), +('469021', '定安县', '469000'), +('469022', '屯昌县', '469000'), +('469023', '澄迈县', '469000'), +('469024', '临高县', '469000'), +('469025', '白沙黎族自治县', '469000'), +('469026', '昌江黎族自治县', '469000'), +('469027', '乐东黎族自治县', '469000'), +('469028', '陵水黎族自治县', '469000'), +('469029', '保亭黎族苗族自治县', '469000'), +('469030', '琼中黎族苗族自治县', '469000'), +('500000', '重庆市', null), +('500100', '重庆市', '500000'), +('500101', '万州区', '500100'), +('500102', '涪陵区', '500100'), +('500103', '渝中区', '500100'), +('500104', '大渡口区', '500100'), +('500105', '江北区', '500100'), +('500106', '沙坪坝区', '500100'), +('500107', '九龙坡区', '500100'), +('500108', '南岸区', '500100'), +('500109', '北碚区', '500100'), +('500110', '綦江区', '500100'), +('500111', '大足区', '500100'), +('500112', '渝北区', '500100'), +('500113', '巴南区', '500100'), +('500114', '黔江区', '500100'), +('500115', '长寿区', '500100'), +('500116', '江津区', '500100'), +('500117', '合川区', '500100'), +('500118', '永川区', '500100'), +('500119', '南川区', '500100'), +('500120', '璧山区', '500100'), +('500151', '铜梁区', '500100'), +('500152', '潼南区', '500100'), +('500153', '荣昌区', '500100'), +('500154', '开州区', '500100'), +('500200', '县', '500000'), +('500228', '梁平县', '500200'), +('500229', '城口县', '500200'), +('500230', '丰都县', '500200'), +('500231', '垫江县', '500200'), +('500232', '武隆县', '500200'), +('500233', '忠县', '500200'), +('500235', '云阳县', '500200'), +('500236', '奉节县', '500200'), +('500237', '巫山县', '500200'), +('500238', '巫溪县', '500200'), +('500240', '石柱土家族自治县', '500200'), +('500241', '秀山土家族苗族自治县', '500200'), +('500242', '酉阳土家族苗族自治县', '500200'), +('500243', '彭水苗族土家族自治县', '500200'), +('510000', '四川省', null), +('510100', '成都市', '510000'), +('510104', '锦江区', '510100'), +('510105', '青羊区', '510100'), +('510106', '金牛区', '510100'), +('510107', '武侯区', '510100'), +('510108', '成华区', '510100'), +('510112', '龙泉驿区', '510100'), +('510113', '青白江区', '510100'), +('510114', '新都区', '510100'), +('510115', '温江区', '510100'), +('510116', '双流区', '510100'), +('510121', '金堂县', '510100'), +('510124', '郫县', '510100'), +('510129', '大邑县', '510100'), +('510131', '蒲江县', '510100'), +('510132', '新津县', '510100'), +('510181', '都江堰市', '510100'), +('510182', '彭州市', '510100'), +('510183', '邛崃市', '510100'), +('510184', '崇州市', '510100'), +('510185', '简阳市', '510100'), +('510300', '自贡市', '510000'), +('510302', '自流井区', '510300'), +('510303', '贡井区', '510300'), +('510304', '大安区', '510300'), +('510311', '沿滩区', '510300'), +('510321', '荣县', '510300'), +('510322', '富顺县', '510300'), +('510400', '攀枝花市', '510000'), +('510402', '东区', '510400'), +('510403', '西区', '510400'), +('510411', '仁和区', '510400'), +('510421', '米易县', '510400'), +('510422', '盐边县', '510400'), +('510500', '泸州市', '510000'), +('510502', '江阳区', '510500'), +('510503', '纳溪区', '510500'), +('510504', '龙马潭区', '510500'), +('510521', '泸县', '510500'), +('510522', '合江县', '510500'), +('510524', '叙永县', '510500'), +('510525', '古蔺县', '510500'), +('510600', '德阳市', '510000'), +('510603', '旌阳区', '510600'), +('510623', '中江县', '510600'), +('510626', '罗江县', '510600'), +('510681', '广汉市', '510600'), +('510682', '什邡市', '510600'), +('510683', '绵竹市', '510600'), +('510700', '绵阳市', '510000'), +('510703', '涪城区', '510700'), +('510704', '游仙区', '510700'), +('510705', '安州区', '510700'), +('510722', '三台县', '510700'), +('510723', '盐亭县', '510700'), +('510725', '梓潼县', '510700'), +('510726', '北川羌族自治县', '510700'), +('510727', '平武县', '510700'), +('510781', '江油市', '510700'), +('510800', '广元市', '510000'), +('510802', '利州区', '510800'), +('510811', '昭化区', '510800'), +('510812', '朝天区', '510800'), +('510821', '旺苍县', '510800'), +('510822', '青川县', '510800'), +('510823', '剑阁县', '510800'), +('510824', '苍溪县', '510800'), +('510900', '遂宁市', '510000'), +('510903', '船山区', '510900'), +('510904', '安居区', '510900'), +('510921', '蓬溪县', '510900'), +('510922', '射洪县', '510900'), +('510923', '大英县', '510900'), +('511000', '内江市', '510000'), +('511002', '市中区', '511000'), +('511011', '东兴区', '511000'), +('511024', '威远县', '511000'), +('511025', '资中县', '511000'), +('511028', '隆昌县', '511000'), +('511100', '乐山市', '510000'), +('511102', '市中区', '511100'), +('511111', '沙湾区', '511100'), +('511112', '五通桥区', '511100'), +('511113', '金口河区', '511100'), +('511123', '犍为县', '511100'), +('511124', '井研县', '511100'), +('511126', '夹江县', '511100'), +('511129', '沐川县', '511100'), +('511132', '峨边彝族自治县', '511100'), +('511133', '马边彝族自治县', '511100'), +('511181', '峨眉山市', '511100'), +('511300', '南充市', '510000'), +('511302', '顺庆区', '511300'), +('511303', '高坪区', '511300'), +('511304', '嘉陵区', '511300'), +('511321', '南部县', '511300'), +('511322', '营山县', '511300'), +('511323', '蓬安县', '511300'), +('511324', '仪陇县', '511300'), +('511325', '西充县', '511300'), +('511381', '阆中市', '511300'), +('511400', '眉山市', '510000'), +('511402', '东坡区', '511400'), +('511403', '彭山区', '511400'), +('511421', '仁寿县', '511400'), +('511423', '洪雅县', '511400'), +('511424', '丹棱县', '511400'), +('511425', '青神县', '511400'), +('511500', '宜宾市', '510000'), +('511502', '翠屏区', '511500'), +('511503', '南溪区', '511500'), +('511521', '宜宾县', '511500'), +('511523', '江安县', '511500'), +('511524', '长宁县', '511500'), +('511525', '高县', '511500'), +('511526', '珙县', '511500'), +('511527', '筠连县', '511500'), +('511528', '兴文县', '511500'), +('511529', '屏山县', '511500'), +('511600', '广安市', '510000'), +('511602', '广安区', '511600'), +('511603', '前锋区', '511600'), +('511621', '岳池县', '511600'), +('511622', '武胜县', '511600'), +('511623', '邻水县', '511600'), +('511681', '华蓥市', '511600'), +('511700', '达州市', '510000'), +('511702', '通川区', '511700'), +('511703', '达川区', '511700'), +('511722', '宣汉县', '511700'), +('511723', '开江县', '511700'), +('511724', '大竹县', '511700'), +('511725', '渠县', '511700'), +('511781', '万源市', '511700'), +('511800', '雅安市', '510000'), +('511802', '雨城区', '511800'), +('511803', '名山区', '511800'), +('511822', '荥经县', '511800'), +('511823', '汉源县', '511800'), +('511824', '石棉县', '511800'), +('511825', '天全县', '511800'), +('511826', '芦山县', '511800'), +('511827', '宝兴县', '511800'), +('511900', '巴中市', '510000'), +('511902', '巴州区', '511900'), +('511903', '恩阳区', '511900'), +('511921', '通江县', '511900'), +('511922', '南江县', '511900'), +('511923', '平昌县', '511900'), +('512000', '资阳市', '510000'), +('512002', '雁江区', '512000'), +('512021', '安岳县', '512000'), +('512022', '乐至县', '512000'), +('513200', '阿坝藏族羌族自治州', '510000'), +('513201', '马尔康市', '513200'), +('513221', '汶川县', '513200'), +('513222', '理县', '513200'), +('513223', '茂县', '513200'), +('513224', '松潘县', '513200'), +('513225', '九寨沟县', '513200'), +('513226', '金川县', '513200'), +('513227', '小金县', '513200'), +('513228', '黑水县', '513200'), +('513230', '壤塘县', '513200'), +('513231', '阿坝县', '513200'), +('513232', '若尔盖县', '513200'), +('513233', '红原县', '513200'), +('513300', '甘孜藏族自治州', '510000'), +('513301', '康定市', '513300'), +('513322', '泸定县', '513300'), +('513323', '丹巴县', '513300'), +('513324', '九龙县', '513300'), +('513325', '雅江县', '513300'), +('513326', '道孚县', '513300'), +('513327', '炉霍县', '513300'), +('513328', '甘孜县', '513300'), +('513329', '新龙县', '513300'), +('513330', '德格县', '513300'), +('513331', '白玉县', '513300'), +('513332', '石渠县', '513300'), +('513333', '色达县', '513300'), +('513334', '理塘县', '513300'), +('513335', '巴塘县', '513300'), +('513336', '乡城县', '513300'), +('513337', '稻城县', '513300'), +('513338', '得荣县', '513300'), +('513400', '凉山彝族自治州', '510000'), +('513401', '西昌市', '513400'), +('513422', '木里藏族自治县', '513400'), +('513423', '盐源县', '513400'), +('513424', '德昌县', '513400'), +('513425', '会理县', '513400'), +('513426', '会东县', '513400'), +('513427', '宁南县', '513400'), +('513428', '普格县', '513400'), +('513429', '布拖县', '513400'), +('513430', '金阳县', '513400'), +('513431', '昭觉县', '513400'), +('513432', '喜德县', '513400'), +('513433', '冕宁县', '513400'), +('513434', '越西县', '513400'), +('513435', '甘洛县', '513400'), +('513436', '美姑县', '513400'), +('513437', '雷波县', '513400'), +('520000', '贵州省', null), +('520100', '贵阳市', '520000'), +('520102', '南明区', '520100'), +('520103', '云岩区', '520100'), +('520111', '花溪区', '520100'), +('520112', '乌当区', '520100'), +('520113', '白云区', '520100'), +('520115', '观山湖区', '520100'), +('520121', '开阳县', '520100'), +('520122', '息烽县', '520100'), +('520123', '修文县', '520100'), +('520181', '清镇市', '520100'), +('520200', '六盘水市', '520000'), +('520201', '钟山区', '520200'), +('520203', '六枝特区', '520200'), +('520221', '水城县', '520200'), +('520222', '盘县', '520200'), +('520300', '遵义市', '520000'), +('520302', '红花岗区', '520300'), +('520303', '汇川区', '520300'), +('520304', '播州区', '520300'), +('520322', '桐梓县', '520300'), +('520323', '绥阳县', '520300'), +('520324', '正安县', '520300'), +('520325', '道真仡佬族苗族自治县', '520300'), +('520326', '务川仡佬族苗族自治县', '520300'), +('520327', '凤冈县', '520300'), +('520328', '湄潭县', '520300'), +('520329', '余庆县', '520300'), +('520330', '习水县', '520300'), +('520381', '赤水市', '520300'), +('520382', '仁怀市', '520300'), +('520400', '安顺市', '520000'), +('520402', '西秀区', '520400'), +('520403', '平坝区', '520400'), +('520422', '普定县', '520400'), +('520423', '镇宁布依族苗族自治县', '520400'), +('520424', '关岭布依族苗族自治县', '520400'), +('520425', '紫云苗族布依族自治县', '520400'), +('520500', '毕节市', '520000'), +('520502', '七星关区', '520500'), +('520521', '大方县', '520500'), +('520522', '黔西县', '520500'), +('520523', '金沙县', '520500'), +('520524', '织金县', '520500'), +('520525', '纳雍县', '520500'), +('520526', '威宁彝族回族苗族自治县', '520500'), +('520527', '赫章县', '520500'), +('520600', '铜仁市', '520000'), +('520602', '碧江区', '520600'), +('520603', '万山区', '520600'), +('520621', '江口县', '520600'), +('520622', '玉屏侗族自治县', '520600'), +('520623', '石阡县', '520600'), +('520624', '思南县', '520600'), +('520625', '印江土家族苗族自治县', '520600'), +('520626', '德江县', '520600'), +('520627', '沿河土家族自治县', '520600'), +('520628', '松桃苗族自治县', '520600'), +('522300', '黔西南布依族苗族自治州', '520000'), +('522301', '兴义市', '522300'), +('522322', '兴仁县', '522300'), +('522323', '普安县', '522300'), +('522324', '晴隆县', '522300'), +('522325', '贞丰县', '522300'), +('522326', '望谟县', '522300'), +('522327', '册亨县', '522300'), +('522328', '安龙县', '522300'), +('522600', '黔东南苗族侗族自治州', '520000'), +('522601', '凯里市', '522600'), +('522622', '黄平县', '522600'), +('522623', '施秉县', '522600'), +('522624', '三穗县', '522600'), +('522625', '镇远县', '522600'), +('522626', '岑巩县', '522600'), +('522627', '天柱县', '522600'), +('522628', '锦屏县', '522600'), +('522629', '剑河县', '522600'), +('522630', '台江县', '522600'), +('522631', '黎平县', '522600'), +('522632', '榕江县', '522600'), +('522633', '从江县', '522600'), +('522634', '雷山县', '522600'), +('522635', '麻江县', '522600'), +('522636', '丹寨县', '522600'), +('522700', '黔南布依族苗族自治州', '520000'), +('522701', '都匀市', '522700'), +('522702', '福泉市', '522700'), +('522722', '荔波县', '522700'), +('522723', '贵定县', '522700'), +('522725', '瓮安县', '522700'), +('522726', '独山县', '522700'), +('522727', '平塘县', '522700'), +('522728', '罗甸县', '522700'), +('522729', '长顺县', '522700'), +('522730', '龙里县', '522700'), +('522731', '惠水县', '522700'), +('522732', '三都水族自治县', '522700'), +('530000', '云南省', null), +('530100', '昆明市', '530000'), +('530102', '五华区', '530100'), +('530103', '盘龙区', '530100'), +('530111', '官渡区', '530100'), +('530112', '西山区', '530100'), +('530113', '东川区', '530100'), +('530114', '呈贡区', '530100'), +('530122', '晋宁县', '530100'), +('530124', '富民县', '530100'), +('530125', '宜良县', '530100'), +('530126', '石林彝族自治县', '530100'), +('530127', '嵩明县', '530100'), +('530128', '禄劝彝族苗族自治县', '530100'), +('530129', '寻甸回族彝族自治县', '530100'), +('530181', '安宁市', '530100'), +('530300', '曲靖市', '530000'), +('530302', '麒麟区', '530300'), +('530303', '沾益区', '530300'), +('530321', '马龙县', '530300'), +('530322', '陆良县', '530300'), +('530323', '师宗县', '530300'), +('530324', '罗平县', '530300'), +('530325', '富源县', '530300'), +('530326', '会泽县', '530300'), +('530381', '宣威市', '530300'), +('530400', '玉溪市', '530000'), +('530402', '红塔区', '530400'), +('530403', '江川区', '530400'), +('530422', '澄江县', '530400'), +('530423', '通海县', '530400'), +('530424', '华宁县', '530400'), +('530425', '易门县', '530400'), +('530426', '峨山彝族自治县', '530400'), +('530427', '新平彝族傣族自治县', '530400'), +('530428', '元江哈尼族彝族傣族自治县', '530400'), +('530500', '保山市', '530000'), +('530502', '隆阳区', '530500'), +('530521', '施甸县', '530500'), +('530523', '龙陵县', '530500'), +('530524', '昌宁县', '530500'), +('530581', '腾冲市', '530500'), +('530600', '昭通市', '530000'), +('530602', '昭阳区', '530600'), +('530621', '鲁甸县', '530600'), +('530622', '巧家县', '530600'), +('530623', '盐津县', '530600'), +('530624', '大关县', '530600'), +('530625', '永善县', '530600'), +('530626', '绥江县', '530600'), +('530627', '镇雄县', '530600'), +('530628', '彝良县', '530600'), +('530629', '威信县', '530600'), +('530630', '水富县', '530600'), +('530700', '丽江市', '530000'), +('530702', '古城区', '530700'), +('530721', '玉龙纳西族自治县', '530700'), +('530722', '永胜县', '530700'), +('530723', '华坪县', '530700'), +('530724', '宁蒗彝族自治县', '530700'), +('530800', '普洱市', '530000'), +('530802', '思茅区', '530800'), +('530821', '宁洱哈尼族彝族自治县', '530800'), +('530822', '墨江哈尼族自治县', '530800'), +('530823', '景东彝族自治县', '530800'), +('530824', '景谷傣族彝族自治县', '530800'), +('530825', '镇沅彝族哈尼族拉祜族自治县', '530800'), +('530826', '江城哈尼族彝族自治县', '530800'), +('530827', '孟连傣族拉祜族佤族自治县', '530800'), +('530828', '澜沧拉祜族自治县', '530800'), +('530829', '西盟佤族自治县', '530800'), +('530900', '临沧市', '530000'), +('530902', '临翔区', '530900'), +('530921', '凤庆县', '530900'), +('530922', '云县', '530900'), +('530923', '永德县', '530900'), +('530924', '镇康县', '530900'), +('530925', '双江拉祜族佤族布朗族傣族自治县', '530900'), +('530926', '耿马傣族佤族自治县', '530900'), +('530927', '沧源佤族自治县', '530900'), +('532300', '楚雄彝族自治州', '530000'), +('532301', '楚雄市', '532300'), +('532322', '双柏县', '532300'), +('532323', '牟定县', '532300'), +('532324', '南华县', '532300'), +('532325', '姚安县', '532300'), +('532326', '大姚县', '532300'), +('532327', '永仁县', '532300'), +('532328', '元谋县', '532300'), +('532329', '武定县', '532300'), +('532331', '禄丰县', '532300'), +('532500', '红河哈尼族彝族自治州', '530000'), +('532501', '个旧市', '532500'), +('532502', '开远市', '532500'), +('532503', '蒙自市', '532500'), +('532504', '弥勒市', '532500'), +('532523', '屏边苗族自治县', '532500'), +('532524', '建水县', '532500'), +('532525', '石屏县', '532500'), +('532527', '泸西县', '532500'), +('532528', '元阳县', '532500'), +('532529', '红河县', '532500'), +('532530', '金平苗族瑶族傣族自治县', '532500'), +('532531', '绿春县', '532500'), +('532532', '河口瑶族自治县', '532500'), +('532600', '文山壮族苗族自治州', '530000'), +('532601', '文山市', '532600'), +('532622', '砚山县', '532600'), +('532623', '西畴县', '532600'), +('532624', '麻栗坡县', '532600'), +('532625', '马关县', '532600'), +('532626', '丘北县', '532600'), +('532627', '广南县', '532600'), +('532628', '富宁县', '532600'), +('532800', '西双版纳傣族自治州', '530000'), +('532801', '景洪市', '532800'), +('532822', '勐海县', '532800'), +('532823', '勐腊县', '532800'), +('532900', '大理白族自治州', '530000'), +('532901', '大理市', '532900'), +('532922', '漾濞彝族自治县', '532900'), +('532923', '祥云县', '532900'), +('532924', '宾川县', '532900'), +('532925', '弥渡县', '532900'), +('532926', '南涧彝族自治县', '532900'), +('532927', '巍山彝族回族自治县', '532900'), +('532928', '永平县', '532900'), +('532929', '云龙县', '532900'), +('532930', '洱源县', '532900'), +('532931', '剑川县', '532900'), +('532932', '鹤庆县', '532900'), +('533100', '德宏傣族景颇族自治州', '530000'), +('533102', '瑞丽市', '533100'), +('533103', '芒市', '533100'), +('533122', '梁河县', '533100'), +('533123', '盈江县', '533100'), +('533124', '陇川县', '533100'), +('533300', '怒江傈僳族自治州', '530000'), +('533301', '泸水市', '533300'), +('533323', '福贡县', '533300'), +('533324', '贡山独龙族怒族自治县', '533300'), +('533325', '兰坪白族普米族自治县', '533300'), +('533400', '迪庆藏族自治州', '530000'), +('533401', '香格里拉市', '533400'), +('533422', '德钦县', '533400'), +('533423', '维西傈僳族自治县', '533400'), +('540000', '西藏自治区', null), +('540100', '拉萨市', '540000'), +('540102', '城关区', '540100'), +('540103', '堆龙德庆区', '540100'), +('540121', '林周县', '540100'), +('540122', '当雄县', '540100'), +('540123', '尼木县', '540100'), +('540124', '曲水县', '540100'), +('540126', '达孜县', '540100'), +('540127', '墨竹工卡县', '540100'), +('540200', '日喀则市', '540000'), +('540202', '桑珠孜区', '540200'), +('540221', '南木林县', '540200'), +('540222', '江孜县', '540200'), +('540223', '定日县', '540200'), +('540224', '萨迦县', '540200'), +('540225', '拉孜县', '540200'), +('540226', '昂仁县', '540200'), +('540227', '谢通门县', '540200'), +('540228', '白朗县', '540200'), +('540229', '仁布县', '540200'), +('540230', '康马县', '540200'), +('540231', '定结县', '540200'), +('540232', '仲巴县', '540200'), +('540233', '亚东县', '540200'), +('540234', '吉隆县', '540200'), +('540235', '聂拉木县', '540200'), +('540236', '萨嘎县', '540200'), +('540237', '岗巴县', '540200'), +('540300', '昌都市', '540000'), +('540302', '卡若区', '540300'), +('540321', '江达县', '540300'), +('540322', '贡觉县', '540300'), +('540323', '类乌齐县', '540300'), +('540324', '丁青县', '540300'), +('540325', '察雅县', '540300'), +('540326', '八宿县', '540300'), +('540327', '左贡县', '540300'), +('540328', '芒康县', '540300'), +('540329', '洛隆县', '540300'), +('540330', '边坝县', '540300'), +('540400', '林芝市', '540000'), +('540402', '巴宜区', '540400'), +('540421', '工布江达县', '540400'), +('540422', '米林县', '540400'), +('540423', '墨脱县', '540400'), +('540424', '波密县', '540400'), +('540425', '察隅县', '540400'), +('540426', '朗县', '540400'), +('540500', '山南市', '540000'), +('540502', '乃东区', '540500'), +('540521', '扎囊县', '540500'), +('540522', '贡嘎县', '540500'), +('540523', '桑日县', '540500'), +('540524', '琼结县', '540500'), +('540525', '曲松县', '540500'), +('540526', '措美县', '540500'), +('540527', '洛扎县', '540500'), +('540528', '加查县', '540500'), +('540529', '隆子县', '540500'), +('540530', '错那县', '540500'), +('540531', '浪卡子县', '540500'), +('542400', '那曲地区', '540000'), +('542421', '那曲县', '542400'), +('542422', '嘉黎县', '542400'), +('542423', '比如县', '542400'), +('542424', '聂荣县', '542400'), +('542425', '安多县', '542400'), +('542426', '申扎县', '542400'), +('542427', '索县', '542400'), +('542428', '班戈县', '542400'), +('542429', '巴青县', '542400'), +('542430', '尼玛县', '542400'), +('542431', '双湖县', '542400'), +('542500', '阿里地区', '540000'), +('542521', '普兰县', '542500'), +('542522', '札达县', '542500'), +('542523', '噶尔县', '542500'), +('542524', '日土县', '542500'), +('542525', '革吉县', '542500'), +('542526', '改则县', '542500'), +('542527', '措勤县', '542500'), +('610000', '陕西省', null), +('610100', '西安市', '610000'), +('610102', '新城区', '610100'), +('610103', '碑林区', '610100'), +('610104', '莲湖区', '610100'), +('610111', '灞桥区', '610100'), +('610112', '未央区', '610100'), +('610113', '雁塔区', '610100'), +('610114', '阎良区', '610100'), +('610115', '临潼区', '610100'), +('610116', '长安区', '610100'), +('610117', '高陵区', '610100'), +('610122', '蓝田县', '610100'), +('610124', '周至县', '610100'), +('610125', '户县', '610100'), +('610200', '铜川市', '610000'), +('610202', '王益区', '610200'), +('610203', '印台区', '610200'), +('610204', '耀州区', '610200'), +('610222', '宜君县', '610200'), +('610300', '宝鸡市', '610000'), +('610302', '渭滨区', '610300'), +('610303', '金台区', '610300'), +('610304', '陈仓区', '610300'), +('610322', '凤翔县', '610300'), +('610323', '岐山县', '610300'), +('610324', '扶风县', '610300'), +('610326', '眉县', '610300'), +('610327', '陇县', '610300'), +('610328', '千阳县', '610300'), +('610329', '麟游县', '610300'), +('610330', '凤县', '610300'), +('610331', '太白县', '610300'), +('610400', '咸阳市', '610000'), +('610402', '秦都区', '610400'), +('610403', '杨陵区', '610400'), +('610404', '渭城区', '610400'), +('610422', '三原县', '610400'), +('610423', '泾阳县', '610400'), +('610424', '乾县', '610400'), +('610425', '礼泉县', '610400'), +('610426', '永寿县', '610400'), +('610427', '彬县', '610400'), +('610428', '长武县', '610400'), +('610429', '旬邑县', '610400'), +('610430', '淳化县', '610400'), +('610431', '武功县', '610400'), +('610481', '兴平市', '610400'), +('610500', '渭南市', '610000'), +('610502', '临渭区', '610500'), +('610503', '华州区', '610500'), +('610522', '潼关县', '610500'), +('610523', '大荔县', '610500'), +('610524', '合阳县', '610500'), +('610525', '澄城县', '610500'), +('610526', '蒲城县', '610500'), +('610527', '白水县', '610500'), +('610528', '富平县', '610500'), +('610581', '韩城市', '610500'), +('610582', '华阴市', '610500'), +('610600', '延安市', '610000'), +('610602', '宝塔区', '610600'), +('610603', '安塞区', '610600'), +('610621', '延长县', '610600'), +('610622', '延川县', '610600'), +('610623', '子长县', '610600'), +('610625', '志丹县', '610600'), +('610626', '吴起县', '610600'), +('610627', '甘泉县', '610600'), +('610628', '富县', '610600'), +('610629', '洛川县', '610600'), +('610630', '宜川县', '610600'), +('610631', '黄龙县', '610600'), +('610632', '黄陵县', '610600'), +('610700', '汉中市', '610000'), +('610702', '汉台区', '610700'), +('610721', '南郑县', '610700'), +('610722', '城固县', '610700'), +('610723', '洋县', '610700'), +('610724', '西乡县', '610700'), +('610725', '勉县', '610700'), +('610726', '宁强县', '610700'), +('610727', '略阳县', '610700'), +('610728', '镇巴县', '610700'), +('610729', '留坝县', '610700'), +('610730', '佛坪县', '610700'), +('610800', '榆林市', '610000'), +('610802', '榆阳区', '610800'), +('610803', '横山区', '610800'), +('610821', '神木县', '610800'), +('610822', '府谷县', '610800'), +('610824', '靖边县', '610800'), +('610825', '定边县', '610800'), +('610826', '绥德县', '610800'), +('610827', '米脂县', '610800'), +('610828', '佳县', '610800'), +('610829', '吴堡县', '610800'), +('610830', '清涧县', '610800'), +('610831', '子洲县', '610800'), +('610900', '安康市', '610000'), +('610902', '汉滨区', '610900'), +('610921', '汉阴县', '610900'), +('610922', '石泉县', '610900'), +('610923', '宁陕县', '610900'), +('610924', '紫阳县', '610900'), +('610925', '岚皋县', '610900'), +('610926', '平利县', '610900'), +('610927', '镇坪县', '610900'), +('610928', '旬阳县', '610900'), +('610929', '白河县', '610900'), +('611000', '商洛市', '610000'), +('611002', '商州区', '611000'), +('611021', '洛南县', '611000'), +('611022', '丹凤县', '611000'), +('611023', '商南县', '611000'), +('611024', '山阳县', '611000'), +('611025', '镇安县', '611000'), +('611026', '柞水县', '611000'), +('620000', '甘肃省', null), +('620100', '兰州市', '620000'), +('620102', '城关区', '620100'), +('620103', '七里河区', '620100'), +('620104', '西固区', '620100'), +('620105', '安宁区', '620100'), +('620111', '红古区', '620100'), +('620121', '永登县', '620100'), +('620122', '皋兰县', '620100'), +('620123', '榆中县', '620100'), +('620200', '嘉峪关市', '620000'), +('620300', '金昌市', '620000'), +('620302', '金川区', '620300'), +('620321', '永昌县', '620300'), +('620400', '白银市', '620000'), +('620402', '白银区', '620400'), +('620403', '平川区', '620400'), +('620421', '靖远县', '620400'), +('620422', '会宁县', '620400'), +('620423', '景泰县', '620400'), +('620500', '天水市', '620000'), +('620502', '秦州区', '620500'), +('620503', '麦积区', '620500'), +('620521', '清水县', '620500'), +('620522', '秦安县', '620500'), +('620523', '甘谷县', '620500'), +('620524', '武山县', '620500'), +('620525', '张家川回族自治县', '620500'), +('620600', '武威市', '620000'), +('620602', '凉州区', '620600'), +('620621', '民勤县', '620600'), +('620622', '古浪县', '620600'), +('620623', '天祝藏族自治县', '620600'), +('620700', '张掖市', '620000'), +('620702', '甘州区', '620700'), +('620721', '肃南裕固族自治县', '620700'), +('620722', '民乐县', '620700'), +('620723', '临泽县', '620700'), +('620724', '高台县', '620700'), +('620725', '山丹县', '620700'), +('620800', '平凉市', '620000'), +('620802', '崆峒区', '620800'), +('620821', '泾川县', '620800'), +('620822', '灵台县', '620800'), +('620823', '崇信县', '620800'), +('620824', '华亭县', '620800'), +('620825', '庄浪县', '620800'), +('620826', '静宁县', '620800'), +('620900', '酒泉市', '620000'), +('620902', '肃州区', '620900'), +('620921', '金塔县', '620900'), +('620922', '瓜州县', '620900'), +('620923', '肃北蒙古族自治县', '620900'), +('620924', '阿克塞哈萨克族自治县', '620900'), +('620981', '玉门市', '620900'), +('620982', '敦煌市', '620900'), +('621000', '庆阳市', '620000'), +('621002', '西峰区', '621000'), +('621021', '庆城县', '621000'), +('621022', '环县', '621000'), +('621023', '华池县', '621000'), +('621024', '合水县', '621000'), +('621025', '正宁县', '621000'), +('621026', '宁县', '621000'), +('621027', '镇原县', '621000'), +('621100', '定西市', '620000'), +('621102', '安定区', '621100'), +('621121', '通渭县', '621100'), +('621122', '陇西县', '621100'), +('621123', '渭源县', '621100'), +('621124', '临洮县', '621100'), +('621125', '漳县', '621100'), +('621126', '岷县', '621100'), +('621200', '陇南市', '620000'), +('621202', '武都区', '621200'), +('621221', '成县', '621200'), +('621222', '文县', '621200'), +('621223', '宕昌县', '621200'), +('621224', '康县', '621200'), +('621225', '西和县', '621200'), +('621226', '礼县', '621200'), +('621227', '徽县', '621200'), +('621228', '两当县', '621200'), +('622900', '临夏回族自治州', '620000'), +('622901', '临夏市', '622900'), +('622921', '临夏县', '622900'), +('622922', '康乐县', '622900'), +('622923', '永靖县', '622900'), +('622924', '广河县', '622900'), +('622925', '和政县', '622900'), +('622926', '东乡族自治县', '622900'), +('622927', '积石山保安族东乡族撒拉族自治县', '622900'), +('623000', '甘南藏族自治州', '620000'), +('623001', '合作市', '623000'), +('623021', '临潭县', '623000'), +('623022', '卓尼县', '623000'), +('623023', '舟曲县', '623000'), +('623024', '迭部县', '623000'), +('623025', '玛曲县', '623000'), +('623026', '碌曲县', '623000'), +('623027', '夏河县', '623000'), +('630000', '青海省', null), +('630100', '西宁市', '630000'), +('630102', '城东区', '630100'), +('630103', '城中区', '630100'), +('630104', '城西区', '630100'), +('630105', '城北区', '630100'), +('630121', '大通回族土族自治县', '630100'), +('630122', '湟中县', '630100'), +('630123', '湟源县', '630100'), +('630200', '海东市', '630000'), +('630202', '乐都区', '630200'), +('630203', '平安区', '630200'), +('630222', '民和回族土族自治县', '630200'), +('630223', '互助土族自治县', '630200'), +('630224', '化隆回族自治县', '630200'), +('630225', '循化撒拉族自治县', '630200'), +('632200', '海北藏族自治州', '630000'), +('632221', '门源回族自治县', '632200'), +('632222', '祁连县', '632200'), +('632223', '海晏县', '632200'), +('632224', '刚察县', '632200'), +('632300', '黄南藏族自治州', '630000'), +('632321', '同仁县', '632300'), +('632322', '尖扎县', '632300'), +('632323', '泽库县', '632300'), +('632324', '河南蒙古族自治县', '632300'), +('632500', '海南藏族自治州', '630000'), +('632521', '共和县', '632500'), +('632522', '同德县', '632500'), +('632523', '贵德县', '632500'), +('632524', '兴海县', '632500'), +('632525', '贵南县', '632500'), +('632600', '果洛藏族自治州', '630000'), +('632621', '玛沁县', '632600'), +('632622', '班玛县', '632600'), +('632623', '甘德县', '632600'), +('632624', '达日县', '632600'), +('632625', '久治县', '632600'), +('632626', '玛多县', '632600'), +('632700', '玉树藏族自治州', '630000'), +('632701', '玉树市', '632700'), +('632722', '杂多县', '632700'), +('632723', '称多县', '632700'), +('632724', '治多县', '632700'), +('632725', '囊谦县', '632700'), +('632726', '曲麻莱县', '632700'), +('632800', '海西蒙古族藏族自治州', '630000'), +('632801', '格尔木市', '632800'), +('632802', '德令哈市', '632800'), +('632821', '乌兰县', '632800'), +('632822', '都兰县', '632800'), +('632823', '天峻县', '632800'), +('640000', '宁夏回族自治区', null), +('640100', '银川市', '640000'), +('640104', '兴庆区', '640100'), +('640105', '西夏区', '640100'), +('640106', '金凤区', '640100'), +('640121', '永宁县', '640100'), +('640122', '贺兰县', '640100'), +('640181', '灵武市', '640100'), +('640200', '石嘴山市', '640000'), +('640202', '大武口区', '640200'), +('640205', '惠农区', '640200'), +('640221', '平罗县', '640200'), +('640300', '吴忠市', '640000'), +('640302', '利通区', '640300'), +('640303', '红寺堡区', '640300'), +('640323', '盐池县', '640300'), +('640324', '同心县', '640300'), +('640381', '青铜峡市', '640300'), +('640400', '固原市', '640000'), +('640402', '原州区', '640400'), +('640422', '西吉县', '640400'), +('640423', '隆德县', '640400'), +('640424', '泾源县', '640400'), +('640425', '彭阳县', '640400'), +('640500', '中卫市', '640000'), +('640502', '沙坡头区', '640500'), +('640521', '中宁县', '640500'), +('640522', '海原县', '640500'), +('650000', '新疆维吾尔自治区', null), +('650100', '乌鲁木齐市', '650000'), +('650102', '天山区', '650100'), +('650103', '沙依巴克区', '650100'), +('650104', '新市区', '650100'), +('650105', '水磨沟区', '650100'), +('650106', '头屯河区', '650100'), +('650107', '达坂城区', '650100'), +('650109', '米东区', '650100'), +('650121', '乌鲁木齐县', '650100'), +('650200', '克拉玛依市', '650000'), +('650202', '独山子区', '650200'), +('650203', '克拉玛依区', '650200'), +('650204', '白碱滩区', '650200'), +('650205', '乌尔禾区', '650200'), +('650400', '吐鲁番市', '650000'), +('650402', '高昌区', '650400'), +('650421', '鄯善县', '650400'), +('650422', '托克逊县', '650400'), +('650500', '哈密市', '650000'), +('650502', '伊州区', '650500'), +('650521', '巴里坤哈萨克自治县', '650500'), +('650522', '伊吾县', '650500'), +('652300', '昌吉回族自治州', '650000'), +('652301', '昌吉市', '652300'), +('652302', '阜康市', '652300'), +('652323', '呼图壁县', '652300'), +('652324', '玛纳斯县', '652300'), +('652325', '奇台县', '652300'), +('652327', '吉木萨尔县', '652300'), +('652328', '木垒哈萨克自治县', '652300'), +('652700', '博尔塔拉蒙古自治州', '650000'), +('652701', '博乐市', '652700'), +('652702', '阿拉山口市', '652700'), +('652722', '精河县', '652700'), +('652723', '温泉县', '652700'), +('652800', '巴音郭楞蒙古自治州', '650000'), +('652801', '库尔勒市', '652800'), +('652822', '轮台县', '652800'), +('652823', '尉犁县', '652800'), +('652824', '若羌县', '652800'), +('652825', '且末县', '652800'), +('652826', '焉耆回族自治县', '652800'), +('652827', '和静县', '652800'), +('652828', '和硕县', '652800'), +('652829', '博湖县', '652800'), +('652900', '阿克苏地区', '650000'), +('652901', '阿克苏市', '652900'), +('652922', '温宿县', '652900'), +('652923', '库车县', '652900'), +('652924', '沙雅县', '652900'), +('652925', '新和县', '652900'), +('652926', '拜城县', '652900'), +('652927', '乌什县', '652900'), +('652928', '阿瓦提县', '652900'), +('652929', '柯坪县', '652900'), +('653000', '克孜勒苏柯尔克孜自治州', '650000'), +('653001', '阿图什市', '653000'), +('653022', '阿克陶县', '653000'), +('653023', '阿合奇县', '653000'), +('653024', '乌恰县', '653000'), +('653100', '喀什地区', '650000'), +('653101', '喀什市', '653100'), +('653121', '疏附县', '653100'), +('653122', '疏勒县', '653100'), +('653123', '英吉沙县', '653100'), +('653124', '泽普县', '653100'), +('653125', '莎车县', '653100'), +('653126', '叶城县', '653100'), +('653127', '麦盖提县', '653100'), +('653128', '岳普湖县', '653100'), +('653129', '伽师县', '653100'), +('653130', '巴楚县', '653100'), +('653131', '塔什库尔干塔吉克自治县', '653100'), +('653200', '和田地区', '650000'), +('653201', '和田市', '653200'), +('653221', '和田县', '653200'), +('653222', '墨玉县', '653200'), +('653223', '皮山县', '653200'), +('653224', '洛浦县', '653200'), +('653225', '策勒县', '653200'), +('653226', '于田县', '653200'), +('653227', '民丰县', '653200'), +('654000', '伊犁哈萨克自治州', '650000'), +('654002', '伊宁市', '654000'), +('654003', '奎屯市', '654000'), +('654004', '霍尔果斯市', '654000'), +('654021', '伊宁县', '654000'), +('654022', '察布查尔锡伯自治县', '654000'), +('654023', '霍城县', '654000'), +('654024', '巩留县', '654000'), +('654025', '新源县', '654000'), +('654026', '昭苏县', '654000'), +('654027', '特克斯县', '654000'), +('654028', '尼勒克县', '654000'), +('654200', '塔城地区', '650000'), +('654201', '塔城市', '654200'), +('654202', '乌苏市', '654200'), +('654221', '额敏县', '654200'), +('654223', '沙湾县', '654200'), +('654224', '托里县', '654200'), +('654225', '裕民县', '654200'), +('654226', '和布克赛尔蒙古自治县', '654200'), +('654300', '阿勒泰地区', '650000'), +('654301', '阿勒泰市', '654300'), +('654321', '布尔津县', '654300'), +('654322', '富蕴县', '654300'), +('654323', '福海县', '654300'), +('654324', '哈巴河县', '654300'), +('654325', '青河县', '654300'), +('654326', '吉木乃县', '654300'), +('659000', '自治区直辖县级行政区划', '650000'), +('659001', '石河子市', '659000'), +('659002', '阿拉尔市', '659000'), +('659003', '图木舒克市', '659000'), +('659004', '五家渠市', '659000'), +('659006', '铁门关市', '659000'), +('710000', '台湾省', null), +('810000', '香港特别行政区', null), +('820000', '澳门特别行政区', null); + +-- 更新热门城市 +update `tb_district` set `ishot`=1 where `distid` in ('110100', '120100', '310100', '500100', '510100', '440300', '440100', '330100', '420100', '210200', '410100', '430100', '530100', '220100', '450100', '130100'); + +-- 插入户型数据 +insert into `tb_house_type` (`typeid`, `name`) values +(1, '单间'), (2, '一室一厅'), (3, '两室一厅'), (4, '两室两厅'), (5, '三室一厅'), (6, '三室两厅'), (7, '四室两厅'), (8, '别墅'), (9, '其他'); + +-- 插入用户数据 +insert into `tb_user` (`username`, `password`, `realname`, `sex`, `tel`, `email`, `regdate`, `point`, `is_authenticated`) values +('jackfrued', 'e10adc3949ba59abbe56e057f20f883e', '骆昊', 1, '13512345678', 'jackfrued@126.com', now(), 100, 0), +('wangdachui', '4297f44b13955235245b2497399d7a93', '王大锤', 1, '13811223344', 'wangdachui@qq.com', now(), 0, 0), +('hellokitty', '4297f44b13955235245b2497399d7a93', '白元芳', 1, '13800112233', 'baiyuanfang@163.com', now(), 50, 0), +('wuzetian', 'e10adc3949ba59abbe56e057f20f883e', '武则天', 0, '13190908080', '13190908080@163.com', now(), 0, 0); + +-- 插入经济人数据 +insert into `tb_agent` (`agentid`, `name`, `tel`, `servstar`, `realstar`, `profstar`, `certificated`) values +(1, '袁晓孟', '158173555285', 5, 4, 4, 1), +(2, '杨伟', '13352939550', 3, 4, 2, 0), +(3, '谭笛', '13088898249', 5, 4, 5, 1), +(4, '郭志鹏', '13686810707', 4, 4, 4, 1), +(5, '宋伟英', '13713584047', 5, 5, 5, 1), +(6, '肖利丽', '13040813886', 4, 4, 4, 0), +(7, '赵嘉茵', '15889757173', 4, 4, 4, 1); + +-- 插入楼盘数据 +insert into `tb_estate` (`estateid`, `distid`, `name`, `hot`) values +(1, 440303, '今日家园', 20), +(2, 440303, '翡翠园', 30), +(3, 440304, '万科城市花园', 22), +(4, 440306, '万象新天', 28), +(5, 440306, '汇庭居', 35), +(6, 440303, '幸福里', 300), +(7, 440303, '信兴广场', 77), +(8, 440303, '罗湖大厦', 50), +(9, 440303, '中海天钻 ', 68), +(10, 440306, '宏发前城一期', 15), +(11, 440306, '灵芝新村', 20), +(12, 440303, '名仕阁', 90), +(13, 440303, '太白居', 66), +(14, 440303, '都市名园', 15), +(15, 440303, '骏庭名园', 12), +(16, 440303, '金豪花园', 6); + + +-- 插入经纪人楼盘数据 +insert into `tb_agent_estate` (`estateid`, `agentid`) values +(1, 1), (2, 1), (3, 1), (4, 2), (6, 2), (3, 3), (5, 3), (6, 4), (7, 4), (7, 5), (10, 5), (11, 6), (8, 7), (9, 7); + +-- 插入标签数据 +insert into `tb_tag` (`tagid`, `content`) values +(1, '家电齐全'), (2, '拎包入住'), (3, '豪华装修'), (4, '配套齐全'), (5, '随时入住'), (6, '交通便利'), (7, '阳光充足'), (8, '地铁沿线'); + +-- 插入房源信息数据 +insert into `tb_house_info` (`houseid`, `title`, `area`, `floor`, `totalfloor`, `direction`, `price`, `priceunit`, `detail`, `mainphoto`, `pubdate`, `street`, `hassubway`, `isshared`, `hasagentfees`, `typeid`, `userid`, `distid2`, `distid3`, `estateid`, `agentid`) values +(1, '113平米采光好,拎包随时就可以入住!', 113, 15, 32, '朝东南', 9800, '元/月', '拥有以上的绿化率,堪称天然氧吧,有客户称在此园能多活几十年。有专门到达公交车站,上班方便。这套房子是东南向向的2房,户型超好,大厅主卧朝向合理,每个房间都很大,客厅空间很大,敞亮,采光相当好,从太阳升起来到落下一直都有采光。', 'images/0af7d2a60ab711e9996760f81da8d840.jpg', '2018-12-28 23:04:13', '深南东道5002号', 0, 0, 1, 6, 1, 440300, 440303, 7, 5), +(2, '万象城旁,君悦酒店隔壁。幸福里精装三房,南北通透,拎包入住', 146, 10, 49, '朝东南', 22000, '元/月', '罗湖口岸紧挨万象城金光华国贸等大型购物商场前面是各种奢侈品舰店旁边是深圳六酒店(君悦酒店),周围还聚集了中国招商工商建设等银行.滨河高中等。是深圳的地段。幸福里户型方正互不遮挡带有花园式小区会所泳池健身房等设施。', 'images/1d1df6220ab711e9996760f81da8d840.jpg', '2018-12-28 22:58:33', '宝安南路1881号', 1, 0, 1, 5, 1, 440300, 440303, 6, 4), +(3, '中海天钻 精装3房2卫 租金13000起 近幸福里 万象城', 100, 10, 30, '朝南', 13000, '元/月', '本项目为深圳市鹿丹村旧改项目,罗湖区万象城,项目周边配套成熟完善,项目南侧为香港米铺保护区,自然景观资源优越。', 'images/04d9a6920ab711e9996760f81da8d840.jpg', '2018-12-28 23:22:02', '桂园街道滨河路与红岭路交汇处东南侧', 1, 0, 1, 4, 1, 440300, 440303, 9, 7), +(4, '地铁9号。靠罗湖口岸,周边出行方便', 40, 20, 35, '朝南', 5000, '元/月', '房子中层,南向,装修很好,家私家电全部配齐而且都是新的,只要带衣服入住就行了。', 'images/1090e95a0ab711e9996760f81da8d840.jpg', '2018-12-28 23:14:00', '罗湖东门建设路', 1, 0, 1, 3, 2, 440300, 440303, 8, 6), +(5, '幸福里精装三房,拎包入住!万象城旁,近口岸', 143, 15, 49, '朝南', 21000, '元/月', '罗湖口岸紧挨万象城金光华国贸等大型购物商场前面是各种奢侈品舰店旁边是深圳六酒店(君悦酒店),周围还聚集了中国招商工商建设等银行.滨河高中等。是深圳的地段。幸福里户型方正互不遮挡带有花园式小区会所泳池健身房等设施。', 'images/1587c1d60ab711e9996760f81da8d840.jpg', '2018-12-28 23:19:48', '宝安南路1881号', 1, 0, 1, 5, 1, 440300, 440303, 6, 6), +(6, '幸福里豪宅 精装修家私全齐两房 看房方便 万象城商圈', 95, 12, 35, '朝北', 17000, '元/月', '小区介绍幸福里位于万象城南侧,是华润中心的住宅部分,具备商务特征的城市资源高尚住宅。', 'images/f044f6aa0ab611e9996760f81da8d840.jpg', '2018-12-28 23:17:53', '宝安南路1881号', 1, 0, 1, 3, 2, 440300, 440303, 6, 4), +(7, '幸福里豪宅,豪华欧式全新三房,拎包入住', 143, 9, 49, '朝南', 24000, '元/月', '罗湖口岸紧挨万象城金光华国贸等大型购物商场前面是各种奢侈品舰店旁边是深圳六酒店(君悦酒店),周围还聚集了中国招商工商建设等银行.滨河高中等。是深圳的地段。幸福里户型方正互不遮挡带有花园式小区会所泳池健身房等设施。', 'images/f91d6cc60ab611e9996760f81da8d840.jpg', '2018-12-28 23:09:51', '宝安南路1881号', 1, 0, 1, 5, 1, 440300, 440303, 10, 3), +(8, '前城 豪华装修大三房 家私电器全齐 户型优雅', 89, 10, 30, '朝东南', 6200, '元/月', '宝安一号线好楼盘,全新出租住起来超舒服便利的楼盘,可随时入住,正规三房两卫,全新简欧装修,标准空房自己任性搭配。', 'images/235f8d0c0ab711e9996760f81da8d840.jpg', '2018-12-28 23:34:01', '深圳宝安大道与海城路交汇处', 1, 1, 1, 4, 2, 440300, 440306, 2, 2), +(9, '灵芝新村,精装三房,灵芝公园,5号环中线灵芝地铁站', 86, 10, 30, '朝南', 5300, '元/月', '大型小区,生活气氛浓厚。前进路旁边,前后双公园(灵芝公园,新安公园)近灵芝地铁口,交通便利。该物业位于宝安老城区位置,待拆迁物业。', 'images/6d89ad720ab711e9996760f81da8d840.jpg', '2018-12-28 23:36:16', '前进路和兴华二路交汇处', 1, 1, 1, 6, 2, 440300, 440306, 11, 3); + +-- 插入房源标签数据 +insert into `tb_house_tag` (`tagid`,`houseid`) values +(1, 1), (3, 1), (4, 1), (1, 2), (2, 2), (6, 2), (2, 3), (3, 3), (5, 3), (6, 3), (7, 3), (2, 4), (4, 4), (6, 4), (3, 5), (5, 5), (7, 5), (4, 6), (5, 6), (4, 7), (7, 7); + +-- 插入角色数据 +insert into `tb_role` (`roleid`, `rolename`) values +(1, '普通用户'), (2, '房东'), (3, '经纪人'), (4, '管理员'); + +-- 插入用户角色数据 +insert into tb_user_role (userid, roleid) values +(1, 4), (2, 1), (3, 3), (4, 2); + +-- 插入权限数据 +insert into tb_privilege (privid, url, method) values +(1, '/api/districts/', 'GET'), +(2, '/api/estates/', 'GET'), +(3, '/api/estates/', 'POST'), +(4, '/api/estates/', 'PUT'), +(5, '/api/estates/', 'DELETE'), +(6, '/api/housetypes/', 'GET'), +(7, '/api/housetypes/', 'POST'), +(8, '/api/housetypes/', 'PUT'), +(9, '/api/housetypes/', 'DELETE'), +(10, '/api/houseinfos/', 'GET'), +(11, '/api/houseinfos/', 'POST'), +(12, '/api/houseinfos/', 'PUT'), +(13, '/api/houseinfos/', 'DELETE'), +(14, '/api/tags/', 'GET'), +(15, '/api/tags/', 'POST'), +(16, '/api/tags/', 'PUT'), +(17, '/api/tags/', 'DELETE'), +(18, '/api/agents/', 'GET'), +(19, '/api/agents/', 'POST'), +(20, '/api/agents/', 'PUT'), +(21, '/api/agents/', 'DELETE'), +(22, '/api/users/', 'GET'), +(23, '/api/users/', 'POST'), +(24, '/api/users/', 'PUT'), +(25, '/api/users/', 'DELETE'), +(26, '/api/roles/', 'GET'), +(27, '/api/roles/', 'POST'), +(28, '/api/roles/', 'PUT'), +(29, '/api/roles/', 'DELETE'), +(30, '/api/privs/', 'GET'), +(31, '/api/privs/', 'POST'), +(32, '/api/privs/', 'PUT'), +(33, '/api/privs/', 'DELETE'), +(34, '/api/loginlogs/', 'GET'), +(35, '/api/loginlogs/', 'POST'), +(36, '/api/loginlogs/', 'PUT'), +(37, '/api/loginlogs/', 'DELETE'), +(38, '/api/emps/', 'GET'), +(39, '/api/emps/', 'POST'), +(40, '/api/emps/', 'PUT'), +(41, '/api/emps/', 'DELETE'), +(42, '/api/depts/', 'GET'), +(43, '/api/depts/', 'POST'), +(44, '/api/depts/', 'PUT'), +(45, '/api/depts/', 'DELETE'); + +-- 插入角色权限数据 +insert into tb_role_privilege (roleid, privid) values +(1, 1), (1, 2), (1, 6), (1, 10), (1, 14), (1, 18), (2, 1), (2, 2), (2, 6), (2, 7), (2, 10), (2, 11), (2, 12), (2, 13), (2, 14), (2, 18), (3, 1), (3, 2), (3, 3), (3, 4), (3, 6), (3, 7), (3, 8), (3, 10), (3, 11), (3, 12), (3, 14), (3, 15),(3, 16), (3, 18), (4, 1), (4, 2), (4, 3), (4, 4), (4, 5), (4, 6), (4, 7), (4, 8), (4, 9), (4, 10), (4, 13), (4, 14), (4, 15), (4, 16), (4, 17), (4, 18), (4, 19), (4, 20), (4, 21), (4, 22), (4, 23), (4, 24), (4, 25), (4, 26), (4, 27), (4, 28), (4, 29), (4, 30), (4, 31), (4, 32), (4, 33), (4, 34), (4, 35), (4, 36), (4, 37), (4, 38), (4, 39), (4, 40), (4, 41), (4, 42), (4, 43), (4, 44), (4, 45); diff --git a/Day36-40/code/学校选课系统.spf b/Day36-40/code/学校选课系统.spf index 373bb6d..1f60a4a 100644 --- a/Day36-40/code/学校选课系统.spf +++ b/Day36-40/code/学校选课系统.spf @@ -10,8 +10,6 @@ connection - database - school host 120.77.222.217 kcid @@ -47,22 +45,17 @@ 1 contentSelection - YnBsaXN0MDDUAQIDBAUGOTpYJHZlcnNpb25YJG9iamVjdHNZJGFy - Y2hpdmVyVCR0b3ASAAGGoK0HCBUWFxgZHSQoLDE2VSRudWxs0wkK - CwwQFFdOUy5rZXlzWk5TLm9iamVjdHNWJGNsYXNzow0OD4ACgAOA - BKMREhOABYAGgAiADFR0eXBlVHJvd3NUa2V5c18QJlNlbGVjdGlv - bkRldGFpbFR5cGVQcmltYXJ5S2V5ZWREZXRhaWxz0wkKCxobHKCg - gAfSHh8gIVokY2xhc3NuYW1lWCRjbGFzc2VzXxATTlNNdXRhYmxl - RGljdGlvbmFyeaMgIiNcTlNEaWN0aW9uYXJ5WE5TT2JqZWN00goL - JSehJoAJgAvSCykqK1lOUy5zdHJpbmeAClRzY2lk0h4fLS5fEA9O - U011dGFibGVTdHJpbmejLS8wWE5TU3RyaW5nWE5TT2JqZWN00h4f - MjNeTlNNdXRhYmxlQXJyYXmjMjQ1V05TQXJyYXlYTlNPYmplY3TS - Hh8iN6IiOFhOU09iamVjdF8QD05TS2V5ZWRBcmNoaXZlctE7PFRk - YXRhgAEACAARABoAIwAtADIANwBFAEsAUgBaAGUAbABwAHIAdAB2 - AHoAfAB+AIAAggCHAIwAkQC6AMEAwgDDAMUAygDVAN4A9AD4AQUB - DgETARUBFwEZAR4BKAEqAS8BNAFGAUoBUwFcAWEBcAF0AXwBhQGK - AY0BlgGoAasBsAAAAAAAAAIBAAAAAAAAAD0AAAAAAAAAAAAAAAAA - AAGy + YnBsaXN0MDDUAQIDBAUGJSZYJHZlcnNpb25YJG9iamVjdHNZJGFy + Y2hpdmVyVCR0b3ASAAGGoKgHCBMUFRYaIVUkbnVsbNMJCgsMDxJX + TlMua2V5c1pOUy5vYmplY3RzViRjbGFzc6INDoACgAOiEBGABIAF + gAdUdHlwZVRyb3dzXxAdU2VsZWN0aW9uRGV0YWlsVHlwZU5TSW5k + ZXhTZXTSFwsYGVxOU1JhbmdlQ291bnQQAIAG0hscHR5aJGNsYXNz + bmFtZVgkY2xhc3Nlc1pOU0luZGV4U2V0oh8gWk5TSW5kZXhTZXRY + TlNPYmplY3TSGxwiI1xOU0RpY3Rpb25hcnmiIiRYTlNPYmplY3Rf + EA9OU0tleWVkQXJjaGl2ZXLRJyhUZGF0YYABAAgAEQAaACMALQAy + ADcAQABGAE0AVQBgAGcAagBsAG4AcQBzAHUAdwB8AIEAoQCmALMA + tQC3ALwAxwDQANsA3gDpAPIA9wEEAQcBEAEiASUBKgAAAAAAAAIB + AAAAAAAAACkAAAAAAAAAAAAAAAAAAAEs contentSortColIsAsc @@ -289,7 +282,7 @@ select stuname as 姓名, year(now())-year(stubirth) as 年龄 from tb_student w ); -- 查询选了两门以上的课程的学生姓名(子查询/分组条件/集合运算) -select stuname from tb_student where stuid=( +explain select stuname from tb_student where stuid in ( select stuid from tb_score group by stuid having count(stuid)>2 ) @@ -314,8 +307,6 @@ select stuname, avgmark from tb_student t1 inner join -- 查询每个学生的姓名和选课数量(左外连接和子查询) select stuname, ifnull(total, 0) from tb_student t1 left outer join (select stuid, count(stuid) as total from tb_score group by stuid) t2 on t1.stuid=t2.stuid; - table - tb_score view SP_VIEW_CUSTOMQUERY windowVerticalDividerPosition @@ -330,6 +321,137 @@ select stuname, ifnull(total, 0) from tb_student t1 left outer join (select stui queryHistory + -- 查询选了两门以上的课程的学生姓名(子查询/分组条件/集合运算) +explain select stuname from tb_student where stuid=any( + select stuid from tb_score group by stuid having count(stuid)>2 +) + explain select stuname from tb_student where stuid in ( + select stuid from tb_score group by stuid having count(stuid)>2 +) + select stuname from tb_student where stuid in ( + select stuid from tb_score group by stuid having count(stuid)>2 +) + select stuname from tb_student where stuid=( + select stuid from tb_score group by stuid having count(stuid)>2 +) + -- 如果存在名为school的数据库就删除它 +drop database if exists school; +-- 创建名为school的数据库并设置默认的字符集和排序方式 +create database school default charset utf8 collate utf8_bin; +-- 切换到school数据库上下文环境 +use school; +-- 创建学院表 +create table tb_college +( +collid int not null auto_increment comment '编号', +collname varchar(50) not null comment '名称', +collmaster varchar(20) not null comment '院长', +collweb varchar(511) default '' comment '网站', +primary key (collid) +); +-- 创建学生表 +create table tb_student +( +stuid int not null comment '学号', +stuname varchar(20) not null comment '姓名', +stusex bit default 1 comment '性别', +stubirth date not null comment '出生日期', +stuaddr varchar(255) default '' comment '籍贯', +collid int not null comment '所属学院', +primary key (stuid), +foreign key (collid) references tb_college (collid) +); +-- alter table tb_student add constraint fk_student_collid foreign key (collid) references tb_college (collid); + +-- 创建教师表 +create table tb_teacher +( +teaid int not null comment '工号', +teaname varchar(20) not null comment '姓名', +teatitle varchar(10) default '助教' comment '职称', +collid int not null comment '所属学院', +primary key (teaid), +foreign key (collid) references tb_college (collid) +); +-- 创建课程表 +create table tb_course +( +couid int not null comment '编号', +couname varchar(50) not null comment '名称', +coucredit int not null comment '学分', +teaid int not null comment '授课老师', +primary key (couid), +foreign key (teaid) references tb_teacher (teaid) +); +-- 创建选课记录表 +create table tb_score +( +scid int auto_increment comment '选课记录编号', +stuid int not null comment '选课学生', +couid int not null comment '所选课程', +scdate datetime comment '选课时间日期', +scmark decimal(4,1) comment '考试成绩', +primary key (scid), +foreign key (stuid) references tb_student (stuid), +foreign key (couid) references tb_course (couid) +); +-- 添加唯一性约束(一个学生选某个课程只能选一次) +alter table tb_score add constraint uni_score_stuid_couid unique (stuid, couid); +-- 插入学院数据 +insert into tb_college (collname, collmaster, collweb) values +('计算机学院', '左冷禅', 'http://www.abc.com'), +('外国语学院', '岳不群', 'http://www.xyz.com'), +('经济管理学院', '风清扬', 'http://www.foo.com'); +-- 插入学生数据 +insert into tb_student (stuid, stuname, stusex, stubirth, stuaddr, collid) values +(1001, '杨逍', 1, '1990-3-4', '四川成都', 1), +(1002, '任我行', 1, '1992-2-2', '湖南长沙', 1), +(1033, '王语嫣', 0, '1989-12-3', '四川成都', 1), +(1572, '岳不群', 1, '1993-7-19', '陕西咸阳', 1), +(1378, '纪嫣然', 0, '1995-8-12', '四川绵阳', 1), +(1954, '林平之', 1, '1994-9-20', '福建莆田', 1), +(2035, '东方不败', 1, '1988-6-30', null, 2), +(3011, '林震南', 1, '1985-12-12', '福建莆田', 3), +(3755, '项少龙', 1, '1993-1-25', null, 3), +(3923, '杨不悔', 0, '1985-4-17', '四川成都', 3); +-- 插入老师数据 +insert into tb_teacher (teaid, teaname, teatitle, collid) values +(1122, '张三丰', '教授', 1), +(1133, '宋远桥', '副教授', 1), +(1144, '杨逍', '副教授', 1), +(2255, '范遥', '副教授', 2), +(3366, '韦一笑', '讲师', 3); +-- 插入课程数据 +insert into tb_course (couid, couname, coucredit, teaid) values +(1111, 'Python程序设计', 3, 1122), +(2222, 'Web前端开发', 2, 1122), +(3333, '操作系统', 4, 1122), +(4444, '计算机网络', 2, 1133), +(5555, '编译原理', 4, 1144), +(6666, '算法和数据结构', 3, 1144), +(7777, '经贸法语', 3, 2255), +(8888, '成本会计', 2, 3366), +(9999, '审计学', 3, 3366); +-- 插入选课数据 +insert into tb_score (stuid, couid, scdate, scmark) values +(1001, 1111, '2017-09-01', 95), +(1001, 2222, '2017-09-01', 87.5), +(1001, 3333, '2017-09-01', 100), +(1001, 4444, '2018-09-03', null), +(1001, 6666, '2017-09-02', 100), +(1002, 1111, '2017-09-03', 65), +(1002, 5555, '2017-09-01', 42), +(1033, 1111, '2017-09-03', 92.5), +(1033, 4444, '2017-09-01', 78), +(1033, 5555, '2017-09-01', 82.5), +(1572, 1111, '2017-09-02', 78), +(1378, 1111, '2017-09-05', 82), +(1378, 7777, '2017-09-02', 65.5), +(2035, 7777, '2018-09-03', 88), +(2035, 9999, curdate(), null), +(3755, 1111, date(now()), null), +(3755, 8888, date(now()), null), +(3755, 9999, '2017-09-01', 92) select stuname, couname, scmark from tb_student t1 inner join tb_score t3 on t1.stuid=t3.stuid inner join tb_course t2 on t2.couid=t3.couid where scmark is not null order by scmark desc limit 5 offset 10 select stuname, couname, scmark from tb_student t1 inner join tb_score t3 on t1.stuid=t3.stuid inner join tb_course t2 on t2.couid=t3.couid where scmark is not null order by scmark desc limit 10, 5 select stuname, couname, scmark from tb_student t1 inner join tb_score t3 on t1.stuid=t3.stuid inner join tb_course t2 on t2.couid=t3.couid where scmark is not null order by scmark desc limit 5, 5 @@ -347,29 +469,11 @@ select stuname, couname, scmark from tb_student t1, tb_course t2, tb_score t3 wh select stuname, avgmark from tb_student t1, (select stuid, avg(scmark) as avgmark from tb_score group by stuid) t2 where t1.stuid=t2.stuid select stuname, ifnull(total, 0) from tb_student t1 left outer join (select stuid, count(stuid) as total from tb_score group by stuid) t2 on t1.stuid=t2.stuid select stuname, ifnull(total,0) from tb_student t1 left outer join (select stuid, count(stuid) as total from tb_score group by stuid) t2 on t1.stuid=t2.stuid - -- 查询选了两门以上的课程的学生姓名(子查询/分组条件/集合运算) -select stuname from tb_student where stuid=( - select stuid from tb_score group by stuid having count(stuid)>2 -) - --- 查询学生姓名、课程名称以及成绩(连接查询) - --- 查询选课学生的姓名和平均成绩(子查询和连接查询) - --- 外连接(outer join):左外连接 / 右外连接 / 全外连接 --- 查询每个学生的姓名和选课数量(左外连接和子查询) -select stuname, ifnull(total, 0) from tb_student t1 left outer join (select stuid, count(stuid) as total from tb_score group by stuid) t2 on t1.stuid=t2.stuid - select stuname, total from tb_student t1 left outer join -(select stuid, count(stuid) as total from tb_score group by stuid) t2 on t1.stuid=t2.stuid - select stuname, total from tb_student t1 inner join -(select stuid, count(stuid) as total from tb_score group by stuid) t2 on t1.stuid=t2.stuid - select stuid, count(stuid) from tb_score group by stuid - select stuname, couname, scmark from tb_student t1 inner join tb_score t3 on t1.stuid=t3.stuid inner join tb_course t2 on t2.couid=t3.couid rdbms_type mysql rdbms_version - 5.5.60-MariaDB + 5.7.26 version 1 diff --git a/Day36-40/关系型数据库MySQL.md b/Day36-40/关系型数据库MySQL.md index 57e7dce..af3f860 100644 --- a/Day36-40/关系型数据库MySQL.md +++ b/Day36-40/关系型数据库MySQL.md @@ -69,61 +69,53 @@ - 启动MySQL服务。 - 先修改MySQL的配置文件(`/etc/my.cnf`)添加一行`skip-grant-tables`,可以设置不进行身份验证即可连接MySQL服务器,然后就可以以超级管理员(root)身份登录。 - - ```Shell - vim /etc/my.cnf - ``` - - ```INI - [mysqld] - skip-grant-tables - - datadir=/var/lib/mysql - socket=/var/lib/mysql/mysql.sock - - symbolic-links=0 - - log-error=/var/log/mysqld.log - pid-file=/var/run/mysqld/mysqld.pid - ``` - - 接下来可以使用下面的命令来启动MySQL。 + 可以使用下面的命令来启动MySQL。 ```Shell service mysqld start ``` - 在CentOS 7中建议使用下面的命令来启动MySQL。 + 在CentOS 7中,更推荐使用下面的命令来启动MySQL。 ```Shell systemctl start mysqld ``` + 启动MySQL成功后,可以通过下面的命令来检查网络端口使用情况,MySQL默认使用3306端口。 + + ```Shell + netstat -nap | grep mysql + ``` + - 使用MySQL客户端工具连接服务器。 命令行工具: ```Shell - mysql -u root - ``` - - 修改超级管理员(root)的访问口令为i_LOVE_macos_123。 - - ```SQL - use mysql; - update user set authentication_string=password('i_LOVE_macos_123') where user='root'; - flush privileges; - ``` - - 将MySQL配置文件中的`skip-grant-tables`去掉,然后重启服务器,重新登录。这一次需要提供用户名和口令才能连接MySQL服务器。 - - ```Shell - systemctl restart mysqld mysql -u root -p ``` - 也可以选择图形化的客户端工具来连接MySQL服务器,可以选择下列工具之一: + > 说明:启动客户端时,`-u`参数用来指定用户名,MySQL默认的超级管理账号为`root`;`-p`表示要输入密码(用户口令);如果连接的是其他主机而非本机,可以用`-h`来指定连接主机的主机名或IP地址。 + + 如果是首次安装MySQL,可以使用下面的命令来找到默认的初始密码。 + + ```Shell + cat /var/log/mysqld.log | grep password + ``` + + 上面的命令会查看MySQL的日志带有password的行,在显示的结果中`root@localhost:`后面的部分就是默认设置的初始密码。 + + 修改超级管理员(root)的访问口令为`123456`。 + + ```SQL + set global validate_password_policy=0; + set global validate_password_length=6; + alter user 'root'@'localhost' identified by '123456'; + ``` + + > 说明:MySQL默认不允许使用弱口令作为用户口令,所以我们通过上面的前两条命令修改了验证用户口令的策略和口令的长度。事实上我们不应该使用弱口令,因为存在用户口令被暴力破解的风险。近年来,攻击数据库窃取数据和劫持数据库勒索比特币的事件屡见不鲜,要避免这些潜在的风险,最为重要的一点是不要让数据库服务器暴露在公网上(最好的做法是将数据库置于内网,至少要做到不向公网开放数据库服务器的访问端口),另外要保管好`root`账号的口令,应用系统需要访问数据库时,通常不使用`root`账号进行访问,而是创建其他拥有适当权限的账号来访问。 + + 再次使用客户端工具连接MySQL服务器时,就可以使用新设置的口令了。在实际开发中,为了方便用户操作,可以选择图形化的客户端工具来连接MySQL服务器,包括: - MySQL Workbench(官方提供的工具) - Navicat for MySQL(界面简单优雅,功能直观强大) @@ -401,7 +393,7 @@ ); -- 查询选了两门以上的课程的学生姓名(子查询/分组条件/集合运算) - select stuname from tb_student where stuid=( + select stuname from tb_student where stuid in ( select stuid from tb_score group by stuid having count(stuid)>2 ) @@ -696,4 +688,4 @@ insert into tb_emp values if __name__ == '__main__': main() - ``` \ No newline at end of file + ``` diff --git a/Day41-55/03.静态资源和Ajax请求.md b/Day41-55/03.静态资源和Ajax请求.md index e3bd4d0..8ee7fb3 100644 --- a/Day41-55/03.静态资源和Ajax请求.md +++ b/Day41-55/03.静态资源和Ajax请求.md @@ -122,7 +122,7 @@ def show_subjects(request): -

所有学科

+

千锋互联所有学科信息


{% for subject in subjects %} @@ -167,7 +167,7 @@ def show_teachers(request): -

{{ subject.name }}的老师信息

+

{{ subject.name }}学科老师信息


{% if teachers %}
@@ -231,7 +231,7 @@ urlpatterns = [ 启动服务器运行项目,进入首页查看学科信息。 -![](/Users/Hao/Desktop/Python-100-Days/Day41-55/res/show-subjects.png) +![](./res/show-subjects.png) 点击学科查看老师信息。 @@ -301,4 +301,4 @@ def praise_or_criticize(request): ### 小结 -到此为止,这个投票项目的核心功能已然完成,在下一个章节中我们要求用户必须登录才能投票,没有账号的用户可以通过注册功能注册一个账号。 \ No newline at end of file +到此为止,这个投票项目的核心功能已然完成,在下面的章节中我们会要求用户必须登录才能投票,没有账号的用户可以通过注册功能注册一个账号。 \ No newline at end of file diff --git a/Day41-55/04.表单的应用.md b/Day41-55/04.表单的应用.md index 2780739..8a2f9e0 100644 --- a/Day41-55/04.表单的应用.md +++ b/Day41-55/04.表单的应用.md @@ -62,7 +62,9 @@ python manage.py migrate ``` -注意,在上面的表单中,我们使用了模板指令`{% csrf_token %}`,它的作用是在表单中生成一个随机令牌(token)来防范[跨站请求伪造]()(通常简称为CSRF),这也是Django在提交表单时的硬性要求,除非我们专门设置了免除CSRF令牌。 +注意,在上面的表单中,我们使用了模板指令`{% csrf_token %}`为表单添加一个隐藏域(type属性值为hidden的input标签),它的作用是在表单中生成一个随机令牌(token)来防范[跨站请求伪造]()(通常简称为CSRF),这也是Django在提交表单时的硬性要求,除非我们专门设置了免除CSRF令牌。下图是一个关于CSRF简单生动的例子,它来自于[维基百科]()。 + +![](./res/CSRF.png) 用户在提交注册表单时,我们还需要对用户的输入进行验证,例如我们的网站要求用户名必须由字母、数字、下划线构成且长度在4-20个字符之间,密码的长度为8-20个字符,确认密码必须跟密码保持一致。这些验证操作首先可以通过浏览器中的JavaScript代码来完成,但是即便如此,在服务器端仍然要对用户输入再次进行验证来避免将无效的数据库交给数据库,因为用户可能会禁用浏览器的JavaScript功能,也有可能绕过浏览器的输入检查将注册数据提交给服务器,所以服务器端的用户输入检查仍然是必要的。 @@ -97,7 +99,7 @@ class RegisterForm(forms.ModelForm): exclude = ('no', 'regdate') ``` -上面,我们定义了一个与User模型绑定的表单(继承自ModelForm),我们排除了用户编号(no)和注册日期(regdate)这两个属性,并添加了一个repassword属性用来接收从用户表单传给服务器的确认密码。我们在定义User模型时已经对用户名的最大长度进行了限制,上面我们又对确认密码的最小和最大长度进行了限制,但是这些都不足以完成我们对用户输入的验证。上面以`clean_`打头的方法就是我们自定义的验证规则。很明显,`clean_username`是对用户名的检查,而`clean_password`是对密码的检查。由于数据库二维表中不应该保存密码的原文,所以对密码做了一个简单的MD5摘要处理(实际开发中这样处理还不太够,因为有被实施反向查表法(利用彩虹表反向查询)破解用户密码的风险)。生成MD5摘要的代码如下所示。 +上面,我们定义了一个与User模型绑定的表单(继承自ModelForm),我们排除了用户编号(no)和注册日期(regdate)这两个属性,并添加了一个repassword属性用来接收从用户表单传给服务器的确认密码。我们在定义User模型时已经对用户名的最大长度进行了限制,上面我们又对确认密码的最小和最大长度进行了限制,但是这些都不足以完成我们对用户输入的验证。上面以`clean_`打头的方法就是我们自定义的验证规则。很明显,`clean_username`是对用户名的检查,而`clean_password`是对密码的检查。由于数据库二维表中不应该保存密码的原文,所以对密码做了一个简单的MD5摘要处理,实际开发中这样处理还不太够,因为有被实施反向查表法(利用彩虹表反向查询)破解用户密码的风险。为字符串生成MD5摘要的代码如下所示。 ```Python def to_md5_hex(message): @@ -381,6 +383,8 @@ def random_color(start=0, end=255, opacity=255): return red, green, blue, opacity ``` +> 说明:上面的代码在生成验证码图片时用到了三种字体文件,使用上面的代码时需要添加字体文件到应用目录下的fonts目录中。 + 下面的视图函数用来生成验证码并通过HttpResponse对象输出到用户浏览器中。 ```Python diff --git a/Day41-55/05.Cookie和Session.md b/Day41-55/05.Cookie和Session.md index 77e9a3c..cf31b52 100644 --- a/Day41-55/05.Cookie和Session.md +++ b/Day41-55/05.Cookie和Session.md @@ -1,3 +1,185 @@ ## Cookie和Session +### 实现用户跟踪 +如今,一个网站如果不通过某种方式记住你是谁以及你之前在网站的活动情况,失去的就是网站的可用性和便利性,继而很有可能导致网站用户的流式,所以记住一个用户(更专业的说法叫**用户跟踪**)对绝大多数Web应用来说都是必需的功能。 + +在服务器端,我们想记住一个用户最简单的办法就是创建一个对象,通过这个对象就可以把用户相关的信息都保存起来,这个对象就是我们常说的session(用户会话对象)。那么问题来了,HTTP本身是一个无连接(每次请求和响应的过程中,服务器一旦完成对客户端请求的响应之后就断开连接)、无状态(客户端再次发起对服务器的请求时,服务器无法得知这个客户端之前的任何信息)的协议,即便服务器通过session对象保留了用户数据,还得通过某种方式来确定当前的请求与之前保存过的哪一个session是有关联的。相信很多人都能想到,我们可以给每个session对象分配一个全局唯一的标识符来识别session对象,我们姑且称之为sessionid,每次客户端发起请求时,只要携带上这个sessionid,就有办法找到与之对应的session对象,从而实现在两次请求之间记住该用户的信息,也就是我们之前说的用户跟踪。 + +要让客户端记住并在每次请求时带上sessionid又有以下几种做法: + +1. URL重写。所谓URL重写就是在URL中携带sessionid,例如:`http://www.example.com/index.html?sessionid=123456`,服务器通过获取sessionid参数的值来取到与之对应的session对象。 + +2. 隐藏域(隐式表单域)。在提交表单的时候,可以通过在表单中设置隐藏域向服务器发送额外的数据。例如:``。 + +3. Cookie。Cookie是保存在浏览器临时文件中的数据,每次请求时,请求头中会携带本站点的cookie到服务器,那么只要将sessionid写入cookie,下次请求时服务器只要读取请求头中的cookie就能够获得这个sessionid,如下图所示: + + ![](./res/sessionid_from_cookie.png) + +需要说明的是,在HTML5时代要想在浏览器中保存数据,除了使用cookie之外,还可以使用新的本地存储API,包括localStorage、sessionStorage、IndexedDB等,如下图所示。 + +![](./res/cookie_xstorage_indexeddb.png) + +### Django框架对session的支持 + +在创建Django项目时,默认的配置文件`settings.py`文件中已经激活了一个名为`SessionMiddleware`的中间件(关于中间件的知识我们在下一个章节做详细的讲解,这里只需要知道它的存在即可),因为这个中间件的存在,我们可以直接通过请求对象的`session`属性来操作会话对象。`session`属性是一个像字典一样可以读写数据的容器对象,因此我们可以使用“键值对”的方式来保留用户数据。与此同时,`SessionMiddleware`中间件还封装了对cookie的操作,在cookie中保存了sessionid,就如同我们之前描述的那样。 + +在默认情况下,Django将session的数据序列化后保存在关系型数据库中,在Django 1.6以后的版本中,默认的序列化数据的方式是JSON序列化,而在此之前一直使用Pickle序列化。JSON序列化和Pickle序列化的差别在于前者将对象序列化为字符串(字符形式),而后者将对象序列化为字节串(二进制形式),因为安全方面的原因,JSON序列化成为了目前Django框架默认序列化数据的方式,这就要求在我们保存在session中的数据必须是能够JSON序列化的,否则就会引发异常。还有一点需要说明的是,使用关系型数据库保存session中的数据在大多数时候并不是最好的选择,因为数据库可能会承受巨大的压力而成为系统性能的瓶颈,在后面的章节中我们会告诉大家如何将session的数据保存到缓存服务中。 + +我们继续完善之前的投票应用,前一个章节中我们实现了用户的登录和注册,下面我们首先完善登录时对验证码的检查。 + +```Python +def get_captcha(request): + """验证码""" + captcha_text = random_captcha_text() + request.session['captcha'] = captcha_text + image_data = Captcha.instance().generate(captcha_text) + return HttpResponse(image_data, content_type='image/png') +``` + +注意上面代码中的第4行,我们将随机生成的验证码字符串保存到session中,稍后用户登录时,我们要将保存在session中的验证码字符串和用户输入的验证码字符串进行比对,如果用户输入了正确的验证码才能够执行后续的登录流程,代码如下所示。 + +```Python +def login(request: HttpRequest): + """登录""" + hint = '' + if request.method == 'POST': + form = LoginForm(request.POST) + if form.is_valid(): + # 对验证码的正确性进行验证 + captcha_from_user = form.cleaned_data['captcha'] + captcha_from_sess = request.session.get('captcha', '') + if captcha_from_sess.lower() != captcha_from_user.lower(): + hint = '请输入正确的验证码' + else: + username = form.cleaned_data['username'] + password = form.cleaned_data['password'] + user = User.objects.filter(username=username, password=password).first() + if user: + # 登录成功后将用户编号和用户名保存在session中 + request.session['no'] = user.no + request.session['username'] = user.username + return redirect('/') + else: + hint = '用户名或密码错误' + else: + hint = '请输入有效的登录信息' + return render(request, 'login.html', {'hint': hint}) +``` + +上面的代码中,我们设定了登录成功后会在session中保存用户的编号(`no`)和用户名(`username`),页面会重定向到首页。接下来我们可以稍微对首页的代码进行调整,在页面的右上角显示出登录用户的用户名。我们将这段代码单独写成了一个名为header.html的HTML文件,首页中可以通过在``标签中添加`{% include 'header.html' %}`来包含这个页面,代码如下所示。 + +```HTML +
+ {% if request.session.no %} + {{ request.session.username }} + 注销 + {% else %} + 登录   + {% endif %} + 注册 +
+``` + +如果用户没有登录,页面会显示登录和注册的超链接;而用户登录成功后,页面上会显示用户名和注销的链接,注销链接对应的视图函数如下所示。 + +```Python +def logout(request): + """注销""" + request.session.flush() + return redirect('/') +``` + +上面的代码通过session对象`flush`方法来销毁session,一方面清除了服务器上session对象保存的用户数据,一方面将保存在浏览器cookie中的sessionid删除掉,稍后我们会对如何读写cookie的操作加以说明。 + +我们可以通过项目使用的数据库中名为`django_session` 的表来找到所有的session,该表的结构如下所示: + +| session_key | session_data | expire_date | +| -------------------------------- | ------------------------------- | -------------------------- | +| c9g2gt5cxo0k2evykgpejhic5ae7bfpl | MmI4YzViYjJhOGMyMDJkY2M5Yzg3... | 2019-05-25 23:16:13.898522 | + +其中,第1列就是浏览器cookie中保存的sessionid;第2列是经过BASE64编码后的session中的数据,如果使用Python的`base64`对其进行解码,解码的过程和结果如下所示。 + +```Python +>>> import base64 +>>> base64.b64decode('MmI4YzViYjJhOGMyMDJkY2M5Yzg3ZWIyZGViZmUzYmYxNzdlNDdmZjp7ImNhcHRjaGEiOiJzS3d0Iiwibm8iOjEsInVzZXJuYW1lIjoiamFja2ZydWVkIn0=') +'2b8c5bb2a8c202dcc9c87eb2debfe3bf177e47ff:{"captcha":"sKwt","no":1,"username":"jackfrued"}' +``` + +第3列是session的过期时间,session过期后浏览器保存的cookie中的sessionid就会失效,但是数据库中的这条对应的记录仍然会存在,如果想清除过期的数据,可以使用下面的命令。 + +```Shell +python manage.py clearsessions +``` + +Django框架默认的session过期时间为两周(1209600秒),如果想修改这个时间,可以在项目的配置文件中添加如下所示的代码。 + +```Python +# 配置会话的超时时间为1天(86400秒) +SESSION_COOKIE_AGE = 86400 +``` + +有很多对安全性要求较高的应用都必须在关闭浏览器窗口时让会话过期,不再保留用户的任何信息,如果希望在关闭浏览器窗口时就让会话过期(cookie中的sessionid失效),可以加入如下所示的配置。 + +```Python +# 设置为True在关闭浏览器窗口时session就过期 +SESSION_EXPIRE_AT_BROWSER_CLOSE = True +``` + +如果不希望将session的数据保存在数据库中,可以将其放入缓存中,对应的配置如下所示,缓存的配置和使用我们在后面讲解。 + +```Python +# 配置将会话对象放到缓存中存储 +SESSION_ENGINE = 'django.contrib.sessions.backends.cache' +# 配置使用哪一组缓存来保存会话 +SESSION_CACHE_ALIAS = 'default' +``` + +如果要修改session数据默认的序列化方式,可以将默认的`JSONSerializer`修改为`PickleSerializer`。 + +```Python +SESSION_SERIALIZER = 'django.contrib.sessions.serializers.PickleSerializer' +``` + +### 在视图函数中读写cookie + +Django封装的`HttpRequest`和`HttpResponse`对象分别提供了读写cookie的操作。 + +HttpRequest封装的属性和方法: + +1. `COOKIES`属性 - 该属性包含了HTTP请求携带的所有cookie。 +2. `get_signed_cookie`方法 - 获取带签名的cookie,如果签名验证失败,会产生`BadSignature`异常。 + +HttpResponse封装的方法: + +1. `set_cookie`方法 - 该方法可以设置一组键值对并将其最终将写入浏览器。 +2. `set_signed_cookie`方法 - 跟上面的方法作用相似,但是会对cookie进行签名来达到防篡改的作用。因为如果篡改了cookie中的数据,在不知道[密钥]()和[盐]()的情况下是无法生成有效的签名,这样服务器在读取cookie时会发现数据与签名不一致从而产生`BadSignature`异常。需要说明的是,这里所说的密钥就是我们在Django项目配置文件中指定的`SECRET_KEY`,而盐是程序中设定的一个字符串,你愿意设定为什么都可以,只要是一个有效的字符串。 + +上面提到的方法,如果不清楚它们的具体用法,可以自己查阅一下Django的[官方文档](),没有什么资料比官方文档能够更清楚的告诉你这些方法到底如何使用。 + +刚才我们说过了,激活`SessionMiddleware`之后,每个`HttpRequest`对象都会绑定一个session属性,它是一个类似字典的对象,除了保存用户数据之外还提供了检测浏览器是否支持cookie的方法,包括: + +1. `set_test_cookie`方法 - 设置用于测试的cookie。 +2. `test_cookie_worked`方法 - 检测测试cookie是否工作。 +3. `delete_test_cookie`方法 - 删除用于测试的cookie。 +4. `set_expiry`方法 - 设置会话的过期时间。 +5. `get_expire_age`/`get_expire_date`方法 - 获取会话的过期时间。 +6. `clear_expired`方法 - 清理过期的会话。 + +下面是在执行登录之前检查浏览器是否支持cookie的代码。 + +```Python +def login(request): + if request.method == 'POST': + if request.session.test_cookie_worked(): + request.session.delete_test_cookie() + # Add your code to perform login process here + else: + return HttpResponse("Please enable cookies and try again.") + request.session.set_test_cookie() + return render_to_response('login.html') +``` + +### Cookie的替代品 + +之前我们说过了,cookie的名声一直都不怎么好,当然我们在实际开发中是不会在cookie中保存用户的敏感信息(如用户的密码、信用卡的账号等)的,而且保存在cookie中的数据一般也会做好编码和签名的工作。即便如此,HTML5中还是给出了用于替代cookie的技术方案,其中使用得最为广泛的就是localStorage和sessionStorage,相信从名字上你就能听出二者的差别,存储在`localStorage`的数据可以长期保留;而存储在`sessionStorage`的数据会在浏览器关闭时会被清除 。关于这些cookie替代品的用法,建议大家查阅[MDN]()来进行了解。 \ No newline at end of file diff --git a/Day41-55/06.中间件的应用.md b/Day41-55/06.中间件的应用.md index 4c70b77..fb39beb 100644 --- a/Day41-55/06.中间件的应用.md +++ b/Day41-55/06.中间件的应用.md @@ -1,4 +1,135 @@ ## 中间件的应用 +我们继续来完善投票应用。在上一个章节中,我们在用户登录成功后通过session保留了用户信息,接下来我们可以应用做一些调整,要求在为老师投票时必须要先登录,登录过的用户可以投票,否则就将用户引导到登录页面,为此我们可以这样修改视图函数。 + +```Python +def praise_or_criticize(request: HttpRequest): + """投票""" + if 'username' in request.session: + try: + tno = int(request.GET.get('tno', '0')) + teacher = Teacher.objects.get(no=tno) + if request.path.startswith('/vote/praise'): + teacher.good_count += 1 + else: + teacher.bad_count += 1 + teacher.save() + data = {'code': 200, 'message': '操作成功'} + except (ValueError, Teacher.DoesNotExist): + data = {'code': 404, 'message': '操作失败'} + else: + data = {'code': 401, 'message': '请先登录'} + return JsonResponse(data) +``` + +前端页面在收到`{'code': 401, 'message': '请先登录'}`后,可以将用户引导到登录页面,修改后的teacher.html页面的JavaScript代码部门如下所示。 + +```HTML + +``` + +> 注意:为了在登录成功之后能够回到刚才投票的页面,我们在跳转登录时设置了一个`backurl`参数,把当前浏览器中的URL作为返回的页面地址。 + +这样我们已经实现了用户必须登录才能投票的限制,但是一个新的问题来了。如果我们的应用中有很多功能都需要用户先登录才能执行,那么我们是不是需要在每个视图函数中添加代码来检查session中是否包含了登录用户的信息呢?答案是否定的,如果这样做了,我们的视图函数中必然会充斥着大量的重复代码。编程大师*Martin Fowler*曾经说过:**代码有很多种坏味道,重复是最坏的一种**。我们可以把验证用户是否登录这样的代码放到Django的中间件中。 + +### Django中间件概述 + +中间件是安插在Web应用请求和响应过程之间的组件,它在整个Web应用中扮演了拦截过滤器的角色,通过中间件可以拦截请求和响应,并对请求和响应进行过滤(简单的说就是执行额外的处理)。通常,一个中间件组件只专注于完成一件特定的事,例如:Django框架通过`SessionMiddleware`中间件实现了对session的支持,又通过`AuthenticationMiddleware`中间件实现了基于session的请求认证。通过把多个中间件组合在一起,我们可以完成更为复杂的任务,Django框架就是这么做的。 + +Django项目的配置文件中就包含了对中间件的配置,代码如下所示。 + +```Python +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] +``` + +我们稍微为大家解释一下这些中间件的作用: + +1. CommonMiddleware - 基础设置中间件,可以处理以下一些配置参数。 + - DISALLOWED_USER_AGENTS - 不被允许的用户代理(浏览器) + - APPEND_SLASH - 是否追加`/` + - USE_ETAG - 浏览器缓存相关 +2. SecurityMiddleware - 安全相关中间件,可以处理和安全相关的配置项。 + - SECURE_HSTS_SECONDS - 强制使用HTTPS的时间 + - SECURE_HSTS_INCLUDE_SUBDOMAINS - HTTPS是否覆盖子域名 + - SECURE_CONTENT_TYPE_NOSNIFF - 是否允许浏览器推断内容类型 + - SECURE_BROWSER_XSS_FILTER - 是否启用跨站脚本攻击过滤器 + - SECURE_SSL_REDIRECT - 是否重定向到HTTPS连接 + - SECURE_REDIRECT_EXEMPT - 免除重定向到HTTPS +3. SessionMiddleware - 会话中间件。 +4. CsrfViewMiddleware - 通过生成令牌,防范跨请求份伪的造中间件。 +5. XFrameOptionsMiddleware - 通过设置请求头参数,防范点击劫持攻击的中间件。 + +在请求的过程中,上面的中间件会按照书写的顺序从上到下执行,然后是URL解析,最后请求才会来到视图函数;在响应的过程中,上面的中间件会按照书写的顺序从下到上执行,与请求时中间件执行的顺序正好相反。 + +### 自定义中间件 + +Django中的中间件有两种实现方式:基于类的实现方式和基于函数的实现方式,后者更接近于装饰器的写法。装饰器实际上是代理模式的应用,将横切关注功能(与正常业务逻辑没有必然联系的功能,例如:身份认证、日志记录、编码转换之类的功能)置于代理中,由代理对象来完成被代理对象的行为并添加额外的功能。中间件对用户请求和响应进行拦截过滤并增加额外的处理,在这一点上它跟装饰器是完全一致的,所以基于函数的写法来实现中间件就跟装饰器的写法几乎一模一样。下面我们用自定义的中间件来实现对用户进行登录验证的功能。 + +```Python +""" +middlewares.py +""" +from django.shortcuts import redirect +def check_login_middleware(func): + + def wrapper(request, *args, **kwargs): + # 获取请求的资源路径 + path = request.path + # 如果请求的资源路径在设定的元组中就表示需要登录验证 + if path in ('/vote/praise/', '/vote/criticize/'): + if 'username' not in request.session: + # session中没有username就重定向到登录页 + return redirect('login') + return func(request, *args, **kwargs) + + return wrapper +``` + +修改配置文件,激活中间件使其生效。 + +```Python +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', + 'debug_toolbar.middleware.DebugToolbarMiddleware', + 'vote.middlewares.check_login_middleware', +] +``` + diff --git a/Day41-55/res/CSRF.png b/Day41-55/res/CSRF.png new file mode 100644 index 0000000..6e87482 Binary files /dev/null and b/Day41-55/res/CSRF.png differ diff --git a/Day41-55/res/cookie_xstorage_indexeddb.png b/Day41-55/res/cookie_xstorage_indexeddb.png new file mode 100644 index 0000000..a08c257 Binary files /dev/null and b/Day41-55/res/cookie_xstorage_indexeddb.png differ diff --git a/Day41-55/res/sessionid_from_cookie.png b/Day41-55/res/sessionid_from_cookie.png new file mode 100644 index 0000000..6dfc76e Binary files /dev/null and b/Day41-55/res/sessionid_from_cookie.png differ diff --git a/Day76-90/02.Pandas的应用.md b/Day76-90/02.Pandas的应用.md index 9a101cf..3115ad5 100644 --- a/Day76-90/02.Pandas的应用.md +++ b/Day76-90/02.Pandas的应用.md @@ -1,2 +1,25 @@ ## Pandas的应用 +### 1、pandas入门 + +### 2、pandas索引 + +### 3、pandas数据清洗之空数据 + +[数据挖掘之空数据处理(有史以来最全面)]: https://blog.csdn.net/Soft_Po/article/details/89302887 + +### 4、pandas多层索引 + +### 5、pandas多层索引计算 + +### 6、pandas数据集成concat + +### 7、pandas数据集成merge + +### 8、pandas分组聚合操作 + +### 9、pandas数据集成实战 + +### 10、美国大选项目 + +[2012美国大选政治献金项目数据分析(有史以来最全面)]: https://blog.csdn.net/Soft_Po/article/details/89283382 \ No newline at end of file diff --git a/Day76-90/code/1-pandas入门.ipynb b/Day76-90/code/1-pandas入门.ipynb new file mode 100644 index 0000000..2f25670 --- /dev/null +++ b/Day76-90/code/1-pandas入门.ipynb @@ -0,0 +1,631 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np\n", + "\n", + "import pandas as pd" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "from pandas import Series,DataFrame" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "scrolled": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "Math 120\n", + "Python 136\n", + "En 128\n", + "Chinese 99\n", + "dtype: int64" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# 创建\n", + "# Series是一维的数据\n", + "s = Series(data = [120,136,128,99],index = ['Math','Python','En','Chinese'])\n", + "s" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(4,)" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "s.shape" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([120, 136, 128, 99], dtype=int64)" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "v = s.values\n", + "v" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "numpy.ndarray" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "type(v)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "120.75" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "s.mean()" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "136" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "s.max()" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "15.903353943953666" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "s.std()" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "collapsed": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "Math 14400\n", + "Python 18496\n", + "En 16384\n", + "Chinese 9801\n", + "dtype: int64" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "s.pow(2)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "collapsed": true + }, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
PythonEnMath
a11311675
b1914523
c57107113
d95366
e28121120
f14185132
h1243910
i803517
j689931
k741211
\n", + "
" + ], + "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" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# 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" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "(10, 3)" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.shape" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": { + "collapsed": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[113, 116, 75],\n", + " [ 19, 145, 23],\n", + " [ 57, 107, 113],\n", + " [ 95, 3, 66],\n", + " [ 28, 121, 120],\n", + " [141, 85, 132],\n", + " [124, 39, 10],\n", + " [ 80, 35, 17],\n", + " [ 68, 99, 31],\n", + " [ 74, 12, 11]])" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "v = df.values\n", + "v" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "Python 79.9\n", + "En 76.2\n", + "Math 59.8\n", + "dtype: float64" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.mean()" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "Python 141\n", + "En 145\n", + "Math 132\n", + "dtype: int32" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.max()" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
PythonEnMath
a11311675
b1914523
c57107113
d95366
e28121120
f14185132
h1243910
i803517
j689931
k741211
\n", + "
" + ], + "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" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "Python 79.9\n", + "En 76.2\n", + "Math 59.8\n", + "dtype: float64" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.mean(axis = 0)" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "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", + "dtype: float64" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.mean(axis = 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.6.5" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/Day76-90/code/2-pandas-索引.ipynb b/Day76-90/code/2-pandas-索引.ipynb new file mode 100644 index 0000000..ddbde0a --- /dev/null +++ b/Day76-90/code/2-pandas-索引.ipynb @@ -0,0 +1,2082 @@ +{ + "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": 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" + } + ], + "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": 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, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "34" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "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" + } + ], + "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" + } + ], + "source": [ + "# 切片操作\n", + "s[10:20]" + ] + }, + { + "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" + } + ], + "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" + } + ], + "source": [ + "s[::-2]" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "34" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# 可以使用pandas为开发者提供方法,去进行检索\n", + "s.loc[10]" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "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" + } + ], + "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" + } + ], + "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" + } + ], + "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" + } + ], + "source": [ + "s.loc[::-2]" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "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" + } + ], + "source": [ + "s.index" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "34" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# iloc 索引从0开始,数字化自然索引\n", + "s.iloc[0]" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "10 34\n", + "20 32\n", + "Name: Python, dtype: int16" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "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" + } + ], + "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" + } + ], + "source": [ + "s.iloc[::-2]" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": { + "collapsed": true + }, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
PythonEnMath
A1035698
B13565135
C1379146
D4724145
E899716
F6426109
H4846111
I164997
J122126100
K6013662
\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" + } + ], + "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": 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'" + ] + } + ], + "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" + } + ], + "source": [ + "df['Python']" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": { + "collapsed": true + }, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
PythonEn
A10356
B13565
C1379
D4724
E8997
F6426
H4846
I1649
J122126
K60136
\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" + } + ], + "source": [ + "df[['Python','En']]" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
PythonEnMath
\n", + "
" + ], + "text/plain": [ + "Empty DataFrame\n", + "Columns: [Python, En, Math]\n", + "Index: []" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df['Python':'Math']" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": { + "collapsed": true + }, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
PythonEnMath
A1035698
B13565135
C1379146
D4724145
\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" + } + ], + "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'" + ] + } + ], + "source": [ + "df.loc['Python']" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "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" + } + ], + "source": [ + "df.loc['A']" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
PythonEnMath
A1035698
H4846111
\n", + "
" + ], + "text/plain": [ + " Python En Math\n", + "A 103 56 98\n", + "H 48 46 111" + ] + }, + "execution_count": 29, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.loc[['A','H']]" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
PythonEnMath
A1035698
B13565135
C1379146
D4724145
E899716
\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" + } + ], + "source": [ + "df.loc['A':'E']" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
PythonEnMath
A1035698
C1379146
E899716
H4846111
J122126100
\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" + } + ], + "source": [ + "df.loc[::2]" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": { + "collapsed": true + }, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
PythonEnMath
K6013662
I164997
F6426109
D4724145
B13565135
\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" + } + ], + "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" + ] + } + ], + "source": [ + "df.iloc['A']" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "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" + } + ], + "source": [ + "df.iloc[0]" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
PythonEnMath
A1035698
F6426109
\n", + "
" + ], + "text/plain": [ + " Python En Math\n", + "A 103 56 98\n", + "F 64 26 109" + ] + }, + "execution_count": 35, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.iloc[[0,5]]" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": { + "collapsed": true + }, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
PythonEnMath
A1035698
B13565135
C1379146
D4724145
E899716
\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" + } + ], + "source": [ + "df.iloc[0:5]" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
PythonEnMath
K6013662
I164997
F6426109
D4724145
B13565135
\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" + } + ], + "source": [ + "df.iloc[::-2]" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
PythonEnMath
A1035698
B13565135
C1379146
D4724145
E899716
F6426109
H4846111
I164997
J122126100
K6013662
\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" + } + ], + "source": [ + "df" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
EnMath
A5698
C79146
E9716
H46111
J126100
\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" + } + ], + "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.6.5" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/Day76-90/code/3-pandas数据清洗之空数据.ipynb b/Day76-90/code/3-pandas数据清洗之空数据.ipynb new file mode 100644 index 0000000..dde9ec6 --- /dev/null +++ b/Day76-90/code/3-pandas数据清洗之空数据.ipynb @@ -0,0 +1,6285 @@ +{ + "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": { + "collapsed": true + }, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
PythonEnMathPhysicChem
1001221052857
101741291611426
102971211222965
103141731201471
1041261328611617
1058534212166
10614265112483
10713614112286113
1081537124110102
1096330446958
110593811310916
1115518758126
1125397763745
1134214810797143
114701386968134
115471361132294
1163113762028
117148741344124
1181028113812832
11927111137022
1202893121684
12113643259719
12211170123858
12396103147868
12410104663149
1257759710831
12688614511655
12733741065046
12874282610076
1297618101126133
..................
170144124779282
1713698484380
17251143683474
17314911718141120
1748139146112122
17511510164629
17610714045148
17765436810918
1783110011049123
1792946695790
18014686182246
18171504090140
1824100147116110
1835587937834
18451091248782
185101181395051
18632127136124
187941613813149
1886510112312886
18943941029132
190681359428125
1913060982715
1928916101354
193104139972917
194529419991
195191021354140
19658100708264
19784971297613
19813115744114
199793795128116
\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" + } + ], + "source": [ + "df = DataFrame(np.random.randint(0,150,size = (100,5)),index = np.arange(100,200),columns=['Python','En','Math','Physic','Chem'])\n", + "df" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "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" + } + ], + "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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
PythonEnMathPhysicChem
100122.010.05.028.057.0
101NaN129.016.0114.026.0
10297.0121.0122.029.065.0
103141.073.0120.0147.01.0
104126.0NaN86.0116.017.0
10585.0NaN42.0121.066.0
106142.065.01.0124.083.0
107136.0141.0NaN86.0113.0
10815.037.0124.0110.0102.0
10963.030.0NaN69.058.0
110NaNNaN113.0109.016.0
1115.051.087.058.0126.0
11253.097.076.037.045.0
11342.0148.0NaN97.0NaN
11470.0138.069.068.0134.0
115NaN136.0113.022.094.0
11631.0137.06.020.028.0
117148.074.0134.04.0124.0
118102.081.0138.0128.032.0
11927.0111.013.0NaN22.0
12028.093.0121.0NaN4.0
121136.0NaN25.097.019.0
122111.070.012.038.058.0
123NaN103.0147.086.08.0
12410.010.046.063.0149.0
1257.075.097.0108.031.0
12688.06.0NaNNaN55.0
12733.074.0106.050.046.0
12874.028.026.0100.076.0
12976.018.0101.0NaNNaN
..................
170144.0124.077.092.082.0
17136.098.0NaN43.080.0
17251.0NaN68.034.074.0
173149.0NaN18.0141.0NaN
1748.0139.0146.0112.0NaN
175115.0NaN64.062.09.0
176NaN7.0140.045.0148.0
177NaN43.068.0109.018.0
17831.0100.0NaN49.0123.0
17929.046.069.057.090.0
180146.086.018.022.046.0
18171.050.040.0NaN140.0
1824.0100.0147.0116.0110.0
18355.087.093.0NaN34.0
184NaN109.0124.087.082.0
18510.0118.0139.050.051.0
18632.012.071.036.0NaN
18794.0NaN138.013.0149.0
18865.0101.0123.0128.086.0
18943.094.0NaN29.0132.0
19068.0135.094.028.0125.0
19130.060.098.0NaN15.0
19289.016.010.0135.04.0
193104.0139.097.029.017.0
1945.029.041.099.0NaN
19519.0102.0135.041.040.0
19658.0NaN70.082.064.0
197NaN97.0129.076.013.0
198131.015.0NaN44.0114.0
19979.0NaN95.0128.0NaN
\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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
PythonEnMathPhysicChem
100122.010.05.028.057.0
101100.0129.016.0114.026.0
10297.0121.0122.029.065.0
103141.073.0120.0147.01.0
104126.0100.086.0116.017.0
10585.0100.042.0121.066.0
106142.065.01.0124.083.0
107136.0141.0100.086.0113.0
10815.037.0124.0110.0102.0
10963.030.0100.069.058.0
110100.0100.0113.0109.016.0
1115.051.087.058.0126.0
11253.097.076.037.045.0
11342.0148.0100.097.0100.0
11470.0138.069.068.0134.0
115100.0136.0113.022.094.0
11631.0137.06.020.028.0
117148.074.0134.04.0124.0
118102.081.0138.0128.032.0
11927.0111.013.0100.022.0
12028.093.0121.0100.04.0
121136.0100.025.097.019.0
122111.070.012.038.058.0
123100.0103.0147.086.08.0
12410.010.046.063.0149.0
1257.075.097.0108.031.0
12688.06.0100.0100.055.0
12733.074.0106.050.046.0
12874.028.026.0100.076.0
12976.018.0101.0100.0100.0
..................
170144.0124.077.092.082.0
17136.098.0100.043.080.0
17251.0100.068.034.074.0
173149.0100.018.0141.0100.0
1748.0139.0146.0112.0100.0
175115.0100.064.062.09.0
176100.07.0140.045.0148.0
177100.043.068.0109.018.0
17831.0100.0100.049.0123.0
17929.046.069.057.090.0
180146.086.018.022.046.0
18171.050.040.0100.0140.0
1824.0100.0147.0116.0110.0
18355.087.093.0100.034.0
184100.0109.0124.087.082.0
18510.0118.0139.050.051.0
18632.012.071.036.0100.0
18794.0100.0138.013.0149.0
18865.0101.0123.0128.086.0
18943.094.0100.029.0132.0
19068.0135.094.028.0125.0
19130.060.098.0100.015.0
19289.016.010.0135.04.0
193104.0139.097.029.017.0
1945.029.041.099.0100.0
19519.0102.0135.041.040.0
19658.0100.070.082.064.0
197100.097.0129.076.013.0
198131.015.0100.044.0114.0
19979.0100.095.0128.0100.0
\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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
PythonEnMathPhysicChem
1001221052857
101711291611426
102971211222965
103141731201471
104126758611617
10585754212166
10614265112483
1071361417786113
1081537124110102
1096330776958
110717511310916
1115518758126
1125397763745
11342148779769
114701386968134
115711361132294
1163113762028
117148741344124
1181028113812832
11927111137322
1202893121734
12113675259719
12211170123858
12371103147868
12410104663149
1257759710831
126886777355
12733741065046
12874282610076
12976181017369
..................
170144124779282
1713698774380
1725175683474
173149751814169
174813914611269
1751157564629
17671714045148
17771436810918
178311007749123
1792946695790
18014686182246
18171504073140
1824100147116110
1835587937334
184711091248782
185101181395051
1863212713669
187947513813149
1886510112312886
18943947729132
190681359428125
1913060987315
1928916101354
193104139972917
194529419969
195191021354140
1965875708264
19771971297613
198131157744114
19979759512869
\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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
PythonEnMathPhysicChem
100122.010.05.028.057.0
10168.0129.016.0114.026.0
10297.0121.0122.029.065.0
103141.073.0120.0147.01.0
104126.082.586.0116.017.0
10585.082.542.0121.066.0
106142.065.01.0124.083.0
107136.0141.086.086.0113.0
10815.037.0124.0110.0102.0
10963.030.086.069.058.0
11068.082.5113.0109.016.0
1115.051.087.058.0126.0
11253.097.076.037.045.0
11342.0148.086.097.065.0
11470.0138.069.068.0134.0
11568.0136.0113.022.094.0
11631.0137.06.020.028.0
117148.074.0134.04.0124.0
118102.081.0138.0128.032.0
11927.0111.013.069.022.0
12028.093.0121.069.04.0
121136.082.525.097.019.0
122111.070.012.038.058.0
12368.0103.0147.086.08.0
12410.010.046.063.0149.0
1257.075.097.0108.031.0
12688.06.086.069.055.0
12733.074.0106.050.046.0
12874.028.026.0100.076.0
12976.018.0101.069.065.0
..................
170144.0124.077.092.082.0
17136.098.086.043.080.0
17251.082.568.034.074.0
173149.082.518.0141.065.0
1748.0139.0146.0112.065.0
175115.082.564.062.09.0
17668.07.0140.045.0148.0
17768.043.068.0109.018.0
17831.0100.086.049.0123.0
17929.046.069.057.090.0
180146.086.018.022.046.0
18171.050.040.069.0140.0
1824.0100.0147.0116.0110.0
18355.087.093.069.034.0
18468.0109.0124.087.082.0
18510.0118.0139.050.051.0
18632.012.071.036.065.0
18794.082.5138.013.0149.0
18865.0101.0123.0128.086.0
18943.094.086.029.0132.0
19068.0135.094.028.0125.0
19130.060.098.069.015.0
19289.016.010.0135.04.0
193104.0139.097.029.017.0
1945.029.041.099.065.0
19519.0102.0135.041.040.0
19658.082.570.082.064.0
19768.097.0129.076.013.0
198131.015.086.044.0114.0
19979.082.595.0128.065.0
\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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
PythonEnMathPhysicChem
100122.010.05.028.057.0
101NaN129.016.0114.026.0
10297.0121.0122.029.065.0
103141.073.0120.0147.01.0
104126.0NaN86.0116.017.0
10585.0NaN42.0121.066.0
106142.065.01.0124.083.0
107136.0141.0NaN86.0113.0
10815.037.0124.0110.0102.0
10963.030.0NaN69.058.0
110NaNNaN113.0109.016.0
1115.051.087.058.0126.0
11253.097.076.037.045.0
11342.0148.0NaN97.0NaN
11470.0138.069.068.0134.0
115NaN136.0113.022.094.0
11631.0137.06.020.028.0
117148.074.0134.04.0124.0
118102.081.0138.0128.032.0
11927.0111.013.0NaN22.0
12028.093.0121.0NaN4.0
121136.0NaN25.097.019.0
122111.070.012.038.058.0
123NaN103.0147.086.08.0
12410.010.046.063.0149.0
1257.075.097.0108.031.0
12688.06.0NaNNaN55.0
12733.074.0106.050.046.0
12874.028.026.0100.076.0
12976.018.0101.0NaNNaN
..................
170144.0124.077.092.082.0
17136.098.0NaN43.080.0
17251.0NaN68.034.074.0
173149.0NaN18.0141.0NaN
1748.0139.0146.0112.0NaN
175115.0NaN64.062.09.0
176NaN7.0140.045.0148.0
177NaN43.068.0109.018.0
17831.0100.0NaN49.0123.0
17929.046.069.057.090.0
180146.086.018.022.046.0
18171.050.040.0NaN140.0
1824.0100.0147.0116.0110.0
18355.087.093.0NaN34.0
184NaN109.0124.087.082.0
18510.0118.0139.050.051.0
18632.012.071.036.0NaN
18794.0NaN138.013.0149.0
18865.0101.0123.0128.086.0
18943.094.0NaN29.0132.0
19068.0135.094.028.0125.0
19130.060.098.0NaN15.0
19289.016.010.0135.04.0
193104.0139.097.029.017.0
1945.029.041.099.0NaN
19519.0102.0135.041.040.0
19658.0NaN70.082.064.0
197NaN97.0129.076.013.0
198131.015.0NaN44.0114.0
19979.0NaN95.0128.0NaN
\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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
PythonEnMathPhysicChem
100828999101125
101431109325
10256103566190
1034710014713899
1043846827544
10518111223126
106562610614139
10731377567144
10835471026063
109861265788149
11019140303533
11176151133
11231549111969
1136437502321
11472571381521
115551201043225
11696248922146
11763086489
11828461258274
119853970132111
12010990447439
121214810311465
12211029998057
123109888113571
12470103134121121
12551921172743
1266929759105
12765905214822
12841291711913
1292410010728139
..................
207012777241631
2071936192822
20721166154861
207347214011234
2074261081233233
207546130135124113
207633181363820
20771071112954119
207884551293787
20799550451984
2080124746514053
20812635149145127
20821921101389
20838410131714
208428741056889
20852393849788
2086861332612513
208721124401155
20882015353137
208996123123564
20902243927860
20911631176058
20926518131334
209369491094058
2094128461082111
20952659854149
209611147909266
209759773140104
2098102675119
209997197714348
\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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
PythonEnMathPhysicChem
10082.089.099.0101.0125.0
1014.031.0109.032.05.0
10256.0103.056.0NaN90.0
10347.0100.0147.0138.099.0
10438.046.0NaN75.044.0
\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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
PythonEnMathPhysicChem
209526.059.08.054.0149.0
2096NaN47.090.092.066.0
20975.097.073.0140.0104.0
2098102.06.07.05.0119.0
209997.019.077.0NaN48.0
\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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
PythonEnMathPhysicChem
10082.089.099.0101.0125.0
1014.031.0109.032.05.0
10256.0103.056.031.090.0
10347.0100.0147.0138.099.0
10438.046.080.075.044.0
10518.011.0122.03.0126.0
10656.026.0106.014.0139.0
1073.0137.075.067.0144.0
10835.047.0102.060.063.0
10986.0126.080.088.0149.0
11019.0140.080.035.033.0
11176.08.05.011.033.0
11231.054.091.0119.069.0
11364.037.050.023.021.0
11472.057.0138.015.021.0
11555.0120.0104.032.025.0
11696.024.089.031.0146.0
11763.08.08.064.089.0
11828.08.0125.082.074.0
11985.039.070.0132.0111.0
120109.090.080.074.039.0
1212.08.0103.0114.065.0
122110.029.099.080.057.0
123109.088.081.0135.071.0
12470.0103.0134.0121.0121.0
12551.092.0117.031.043.0
1266.092.097.059.0105.0
12765.090.052.0148.022.0
1284.0129.017.0119.013.0
12924.0100.0107.028.0139.0
..................
2070127.077.024.016.0125.0
207193.061.09.028.022.0
2072116.061.054.08.061.0
20734.072.0140.031.034.0
2074143.0108.0123.032.033.0
207546.08.0135.0124.0113.0
2076143.018.0136.038.0125.0
2077143.011.0129.054.0119.0
207884.055.0129.037.087.0
207995.050.045.019.084.0
2080124.074.065.031.053.0
208126.035.0149.0145.0127.0
208219.021.0101.03.089.0
208384.08.0131.071.04.0
208428.074.0105.068.089.0
208523.093.084.097.088.0
208686.0133.026.0125.013.0
208721.0124.040.031.05.0
208820.015.035.031.037.0
208996.0123.0123.05.064.0
209022.043.092.078.060.0
209116.031.017.060.058.0
209265.018.013.013.034.0
209369.049.0109.040.058.0
2094128.046.010.082.0111.0
209526.059.08.054.0149.0
2096143.047.090.092.066.0
20975.097.073.0140.0104.0
2098102.06.07.05.0119.0
209997.019.077.031.048.0
\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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
PythonEnMathPhysicChem
10082.089.099.0101.0125.0
1014.031.0109.032.05.0
10256.0103.056.0NaN90.0
10347.0100.0147.0138.099.0
10438.046.0NaN75.044.0
10518.011.0122.03.0126.0
10656.026.0106.014.0139.0
1073.0137.075.067.0144.0
10835.047.0102.060.063.0
10986.0126.0NaN88.0149.0
11019.0140.0NaN35.033.0
11176.0NaN5.011.033.0
11231.054.091.0119.069.0
11364.037.050.023.021.0
11472.057.0138.015.021.0
11555.0120.0104.032.025.0
11696.024.089.0NaN146.0
11763.0NaN8.064.089.0
11828.0NaN125.082.074.0
11985.039.070.0132.0111.0
\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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
PythonEnMathPhysicChem
10082.089.099.0101.0125.0
1014.031.0109.032.05.0
10256.0103.056.090.090.0
10347.0100.0147.0138.099.0
10438.046.075.075.044.0
10518.011.0122.03.0126.0
10656.026.0106.014.0139.0
1073.0137.075.067.0144.0
10835.047.0102.060.063.0
10986.0126.088.088.0149.0
11019.0140.035.035.033.0
11176.05.05.011.033.0
11231.054.091.0119.069.0
11364.037.050.023.021.0
11472.057.0138.015.021.0
11555.0120.0104.032.025.0
11696.024.089.0146.0146.0
11763.08.08.064.089.0
11828.0125.0125.082.074.0
11985.039.070.0132.0111.0
\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.6.5" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/Day76-90/code/4-pandas多层索引.ipynb b/Day76-90/code/4-pandas多层索引.ipynb new file mode 100644 index 0000000..01f9dd6 --- /dev/null +++ b/Day76-90/code/4-pandas多层索引.ipynb @@ -0,0 +1,568 @@ +{ + "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": 4, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
PythonEnMath
张三期中73525
期末373656
李四期中14981142
期末711380
王五期中1194103
期末2512183
\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" + } + ], + "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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
PythonEnMath
张三期中A153117
B8256123
期末A14278
B695017
李四期中A9187143
B12011839
期末A567655
B11105121
王五期中A147781
B128126146
期末A4945114
B1212677
\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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
PythonEnMath
张三期中73525
期末373656
李四期中14981142
期末711380
王五期中1194103
期末2512183
\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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
PythonEnMath
张三期中73525
期末373656
\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.6.5" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/Day76-90/code/5-pandas多层索引计算.ipynb b/Day76-90/code/5-pandas多层索引计算.ipynb new file mode 100644 index 0000000..22e1c8e --- /dev/null +++ b/Day76-90/code/5-pandas多层索引计算.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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
PythonEnMath
期中期末期中期末期中期末
A1311011731517
B6234531012457
C247636117123105
D11246794246122
E661131044510108
F11110844113221
\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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
PythonEnMath
期中期末期中期末期中期末
A1311011731517
B6234531012457
C247636117123105
D11246794246122
E661131044510108
F11110844113221
\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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
PythonEnMath
A116.037.016.0
B48.077.040.5
C50.076.5114.0
D79.060.584.0
E89.574.559.0
F109.522.576.5
\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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
期中期末
A49.063.7
B46.364.0
C61.099.3
D79.070.0
E60.088.7
F82.356.7
\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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
PythonEnMath
期中期末期中期末期中期末
A1311011731517
B6234531012457
C247636117123105
D11246794246122
E661131044510108
F11110844113221
\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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
EnMathPython
A期中115131
期末7317101
B期中532462
期末1015734
C期中3612324
期末11710576
D期中7946112
期末4212246
E期中1041066
期末45108113
F期中4132111
期末4121108
\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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
EnMathPython
ABCDEFABCDEFABCDEF
期中1533679104415241234610132131622411266111
期末73101117424541175710512210821101347646113108
\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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
EnMathPython
期中期末期中期末期中期末
A1731517131101
B5310124576234
C361171231052476
D79424612211246
E104451010866113
F44113221111108
\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.6.5" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/Day76-90/code/6-pandas数据集成.ipynb b/Day76-90/code/6-pandas数据集成.ipynb new file mode 100644 index 0000000..e128ee4 --- /dev/null +++ b/Day76-90/code/6-pandas数据集成.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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
PythonMathEn
A1135380
B1354052
C1441864
\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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
PythonMathEn
D126118146
E1478127
F87631
G359533
H13011791
I12498122
\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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
PythonMathEn
A1135380
B1354052
C1441864
D126118146
E1478127
F87631
G359533
H13011791
I12498122
\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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
PythonMathEn
A1135380
B1354052
C1441864
D126118146
E1478127
F87631
G359533
H13011791
I12498122
\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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
PythonMathEnPythonMathEn
A113.053.080.0NaNNaNNaN
B135.040.052.0NaNNaNNaN
C144.018.064.0NaNNaNNaN
DNaNNaNNaN126.0118.0146.0
ENaNNaNNaN147.081.027.0
FNaNNaNNaN87.063.01.0
GNaNNaNNaN35.095.033.0
HNaNNaNNaN130.0117.091.0
INaNNaNNaN124.098.0122.0
\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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
PythonMathEn
A225813
B995735
C512824
E560111
F13723121
G4978115
\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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
PythonMathEn
A11811381
B5122126
C0115128
E10013094
F4993140
G705994
\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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
PythonMathEn
期中A225813
B995735
C512824
E560111
F13723121
G4978115
期末A11811381
B5122126
C0115128
E10013094
F4993140
G705994
\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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
PythonMathEn
A期中225813
期末11811381
B期中995735
期末5122126
C期中512824
期末0115128
E期中560111
期末10013094
F期中13723121
期末4993140
G期中4978115
期末705994
\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.6.5" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/Day76-90/code/7-pandas数据集成merge.ipynb b/Day76-90/code/7-pandas数据集成merge.ipynb new file mode 100644 index 0000000..8b2eefc --- /dev/null +++ b/Day76-90/code/7-pandas数据集成merge.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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
namesexid
0A1
1B2
2C3
3D4
4E5
5F6
\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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
agesalaryid
022120001
125150002
227200003
321300004
418100005
52980007
\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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
ageidnamesalarysex
0NaN1ANaN
1NaN2BNaN
2NaN3CNaN
3NaN4DNaN
4NaN5ENaN
5NaN6FNaN
022.01NaN12000.0NaN
125.02NaN15000.0NaN
227.03NaN20000.0NaN
321.04NaN30000.0NaN
418.05NaN10000.0NaN
529.07NaN8000.0NaN
\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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
namesexidagesalaryid
0A122120001
1B225150002
2C327200003
3D421300004
4E518100005
5F62980007
\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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
namesexidagesalary
0A12212000
1B22515000
2C32720000
3D42130000
4E51810000
\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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
namesexidagesalary
0A122.012000.0
1B225.015000.0
2C327.020000.0
3D421.030000.0
4E518.010000.0
5F6NaNNaN
6NaNNaN729.08000.0
\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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
PythonMathEn
A401590
B595283
C14138137
D897853
E811013
F757986
\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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
score_mean
Python59.7
Math77.2
En75.3
\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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
PythonMathEn
score_mean59.777.275.3
\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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
PythonMathEn
A40.015.090.0
B59.052.083.0
C14.0138.0137.0
D89.078.053.0
E81.0101.03.0
F75.079.086.0
score_mean59.777.275.3
\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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
score_mean
A48.3
B64.7
C96.3
D73.3
E61.7
F80.0
score_mean70.7
\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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
PythonMathEnscore_mean
A40.015.090.048.3
B59.052.083.064.7
C14.0138.0137.096.3
D89.078.053.073.3
E81.0101.03.061.7
F75.079.086.080.0
score_mean59.777.275.370.7
\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.6.5" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/Day76-90/code/8-pandas分组聚合操作.ipynb b/Day76-90/code/8-pandas分组聚合操作.ipynb new file mode 100644 index 0000000..7c16aff --- /dev/null +++ b/Day76-90/code/8-pandas分组聚合操作.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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
HandSmokesexweightIQ
0rightyesmale80100
1leftyesfemale50120
2leftnofemale4890
3rightnomale75130
4rightyesmale68140
5rightnomale10080
6rightnofemale4094
7rightnofemale90110
8leftnomale88100
9rightyesfemale76160
\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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
weightIQ
Hand
left62.0103.3
right75.6116.3
\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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
weight
Hand
left62.0
right75.6
\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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
weight_mean
075.6
162.0
262.0
375.6
475.6
575.6
675.6
775.6
862.0
975.6
\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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
HandSmokesexweightIQweight_mean
0rightyesmale8010075.6
1leftyesfemale5012062.0
2leftnofemale489062.0
3rightnomale7513075.6
4rightyesmale6814075.6
5rightnomale1008075.6
6rightnofemale409475.6
7rightnofemale9011075.6
8leftnomale8810062.0
9rightyesfemale7616075.6
\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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
IQ
Handsex
leftfemale120
male100
rightfemale160
male140
\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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
IQweight
maxmeanmaxmean
Hand
left120103.38862.0
right160116.310075.6
\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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
IQweight
Hand
left12062.0
right16075.6
\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.6.5" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/Day76-90/code/9-pandas数据集成实战.ipynb b/Day76-90/code/9-pandas数据集成实战.ipynb new file mode 100644 index 0000000..063a939 --- /dev/null +++ b/Day76-90/code/9-pandas数据集成实战.ipynb @@ -0,0 +1,6213 @@ +{ + "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": null, + "metadata": {}, + "outputs": [], + "source": [ + "# csv类型文件呢,文本文件,excel打开,格式化的文件,所以excel可以直接读取成表格\n", + "# 美国人口的一些情况\n", + "# pandas分析一下美国人口数据" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": true + }, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
statearea (sq. mi)
0Alabama52423
1Alaska656425
2Arizona114006
3Arkansas53182
4California163707
5Colorado104100
6Connecticut5544
7Delaware1954
8Florida65758
9Georgia59441
10Hawaii10932
11Idaho83574
12Illinois57918
13Indiana36420
14Iowa56276
15Kansas82282
16Kentucky40411
17Louisiana51843
18Maine35387
19Maryland12407
20Massachusetts10555
21Michigan96810
22Minnesota86943
23Mississippi48434
24Missouri69709
25Montana147046
26Nebraska77358
27Nevada110567
28New Hampshire9351
29New Jersey8722
30New Mexico121593
31New York54475
32North Carolina53821
33North Dakota70704
34Ohio44828
35Oklahoma69903
36Oregon98386
37Pennsylvania46058
38Rhode Island1545
39South Carolina32007
40South Dakota77121
41Tennessee42146
42Texas268601
43Utah84904
44Vermont9615
45Virginia42769
46Washington71303
47West Virginia24231
48Wisconsin65503
49Wyoming97818
50District of Columbia68
51Puerto Rico3515
\n", + "
" + ], + "text/plain": [ + " state area (sq. mi)\n", + "0 Alabama 52423\n", + "1 Alaska 656425\n", + "2 Arizona 114006\n", + "3 Arkansas 53182\n", + "4 California 163707\n", + "5 Colorado 104100\n", + "6 Connecticut 5544\n", + "7 Delaware 1954\n", + "8 Florida 65758\n", + "9 Georgia 59441\n", + "10 Hawaii 10932\n", + "11 Idaho 83574\n", + "12 Illinois 57918\n", + "13 Indiana 36420\n", + "14 Iowa 56276\n", + "15 Kansas 82282\n", + "16 Kentucky 40411\n", + "17 Louisiana 51843\n", + "18 Maine 35387\n", + "19 Maryland 12407\n", + "20 Massachusetts 10555\n", + "21 Michigan 96810\n", + "22 Minnesota 86943\n", + "23 Mississippi 48434\n", + "24 Missouri 69709\n", + "25 Montana 147046\n", + "26 Nebraska 77358\n", + "27 Nevada 110567\n", + "28 New Hampshire 9351\n", + "29 New Jersey 8722\n", + "30 New Mexico 121593\n", + "31 New York 54475\n", + "32 North Carolina 53821\n", + "33 North Dakota 70704\n", + "34 Ohio 44828\n", + "35 Oklahoma 69903\n", + "36 Oregon 98386\n", + "37 Pennsylvania 46058\n", + "38 Rhode Island 1545\n", + "39 South Carolina 32007\n", + "40 South Dakota 77121\n", + "41 Tennessee 42146\n", + "42 Texas 268601\n", + "43 Utah 84904\n", + "44 Vermont 9615\n", + "45 Virginia 42769\n", + "46 Washington 71303\n", + "47 West Virginia 24231\n", + "48 Wisconsin 65503\n", + "49 Wyoming 97818\n", + "50 District of Columbia 68\n", + "51 Puerto Rico 3515" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# 美国各州的面积\n", + "areas = pd.read_csv('./state-areas.csv')\n", + "areas" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(52, 2)" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "areas.shape" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": true + }, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
stateabbreviation
0AlabamaAL
1AlaskaAK
2ArizonaAZ
3ArkansasAR
4CaliforniaCA
5ColoradoCO
6ConnecticutCT
7DelawareDE
8District of ColumbiaDC
9FloridaFL
10GeorgiaGA
11HawaiiHI
12IdahoID
13IllinoisIL
14IndianaIN
15IowaIA
16KansasKS
17KentuckyKY
18LouisianaLA
19MaineME
20MontanaMT
21NebraskaNE
22NevadaNV
23New HampshireNH
24New JerseyNJ
25New MexicoNM
26New YorkNY
27North CarolinaNC
28North DakotaND
29OhioOH
30OklahomaOK
31OregonOR
32MarylandMD
33MassachusettsMA
34MichiganMI
35MinnesotaMN
36MississippiMS
37MissouriMO
38PennsylvaniaPA
39Rhode IslandRI
40South CarolinaSC
41South DakotaSD
42TennesseeTN
43TexasTX
44UtahUT
45VermontVT
46VirginiaVA
47WashingtonWA
48West VirginiaWV
49WisconsinWI
50WyomingWY
\n", + "
" + ], + "text/plain": [ + " state abbreviation\n", + "0 Alabama AL\n", + "1 Alaska AK\n", + "2 Arizona AZ\n", + "3 Arkansas AR\n", + "4 California CA\n", + "5 Colorado CO\n", + "6 Connecticut CT\n", + "7 Delaware DE\n", + "8 District of Columbia DC\n", + "9 Florida FL\n", + "10 Georgia GA\n", + "11 Hawaii HI\n", + "12 Idaho ID\n", + "13 Illinois IL\n", + "14 Indiana IN\n", + "15 Iowa IA\n", + "16 Kansas KS\n", + "17 Kentucky KY\n", + "18 Louisiana LA\n", + "19 Maine ME\n", + "20 Montana MT\n", + "21 Nebraska NE\n", + "22 Nevada NV\n", + "23 New Hampshire NH\n", + "24 New Jersey NJ\n", + "25 New Mexico NM\n", + "26 New York NY\n", + "27 North Carolina NC\n", + "28 North Dakota ND\n", + "29 Ohio OH\n", + "30 Oklahoma OK\n", + "31 Oregon OR\n", + "32 Maryland MD\n", + "33 Massachusetts MA\n", + "34 Michigan MI\n", + "35 Minnesota MN\n", + "36 Mississippi MS\n", + "37 Missouri MO\n", + "38 Pennsylvania PA\n", + "39 Rhode Island RI\n", + "40 South Carolina SC\n", + "41 South Dakota SD\n", + "42 Tennessee TN\n", + "43 Texas TX\n", + "44 Utah UT\n", + "45 Vermont VT\n", + "46 Virginia VA\n", + "47 Washington WA\n", + "48 West Virginia WV\n", + "49 Wisconsin WI\n", + "50 Wyoming WY" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# 美国各州 缩写\n", + "abbrevs = pd.read_csv('./state-abbrevs.csv')\n", + "abbrevs" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(51, 2)" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "abbrevs.shape" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": true + }, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
state/regionagesyearpopulation
0ALunder1820121117489.0
1ALtotal20124817528.0
2ALunder1820101130966.0
3ALtotal20104785570.0
4ALunder1820111125763.0
5ALtotal20114801627.0
6ALtotal20094757938.0
7ALunder1820091134192.0
8ALunder1820131111481.0
9ALtotal20134833722.0
10ALtotal20074672840.0
11ALunder1820071132296.0
12ALtotal20084718206.0
13ALunder1820081134927.0
14ALtotal20054569805.0
15ALunder1820051117229.0
16ALtotal20064628981.0
17ALunder1820061126798.0
18ALtotal20044530729.0
19ALunder1820041113662.0
20ALtotal20034503491.0
21ALunder1820031113083.0
22ALtotal20014467634.0
23ALunder1820011120409.0
24ALtotal20024480089.0
25ALunder1820021116590.0
26ALunder1819991121287.0
27ALtotal19994430141.0
28ALtotal20004452173.0
29ALunder1820001122273.0
...............
2514USAunder18199971946051.0
2515USAtotal2000282162411.0
2516USAunder18200072376189.0
2517USAtotal1999279040181.0
2518USAtotal2001284968955.0
2519USAunder18200172671175.0
2520USAtotal2002287625193.0
2521USAunder18200272936457.0
2522USAtotal2003290107933.0
2523USAunder18200373100758.0
2524USAtotal2004292805298.0
2525USAunder18200473297735.0
2526USAtotal2005295516599.0
2527USAunder18200573523669.0
2528USAtotal2006298379912.0
2529USAunder18200673757714.0
2530USAtotal2007301231207.0
2531USAunder18200774019405.0
2532USAtotal2008304093966.0
2533USAunder18200874104602.0
2534USAunder18201373585872.0
2535USAtotal2013316128839.0
2536USAtotal2009306771529.0
2537USAunder18200974134167.0
2538USAunder18201074119556.0
2539USAtotal2010309326295.0
2540USAunder18201173902222.0
2541USAtotal2011311582564.0
2542USAunder18201273708179.0
2543USAtotal2012313873685.0
\n", + "

2544 rows × 4 columns

\n", + "
" + ], + "text/plain": [ + " state/region ages year population\n", + "0 AL under18 2012 1117489.0\n", + "1 AL total 2012 4817528.0\n", + "2 AL under18 2010 1130966.0\n", + "3 AL total 2010 4785570.0\n", + "4 AL under18 2011 1125763.0\n", + "5 AL total 2011 4801627.0\n", + "6 AL total 2009 4757938.0\n", + "7 AL under18 2009 1134192.0\n", + "8 AL under18 2013 1111481.0\n", + "9 AL total 2013 4833722.0\n", + "10 AL total 2007 4672840.0\n", + "11 AL under18 2007 1132296.0\n", + "12 AL total 2008 4718206.0\n", + "13 AL under18 2008 1134927.0\n", + "14 AL total 2005 4569805.0\n", + "15 AL under18 2005 1117229.0\n", + "16 AL total 2006 4628981.0\n", + "17 AL under18 2006 1126798.0\n", + "18 AL total 2004 4530729.0\n", + "19 AL under18 2004 1113662.0\n", + "20 AL total 2003 4503491.0\n", + "21 AL under18 2003 1113083.0\n", + "22 AL total 2001 4467634.0\n", + "23 AL under18 2001 1120409.0\n", + "24 AL total 2002 4480089.0\n", + "25 AL under18 2002 1116590.0\n", + "26 AL under18 1999 1121287.0\n", + "27 AL total 1999 4430141.0\n", + "28 AL total 2000 4452173.0\n", + "29 AL under18 2000 1122273.0\n", + "... ... ... ... ...\n", + "2514 USA under18 1999 71946051.0\n", + "2515 USA total 2000 282162411.0\n", + "2516 USA under18 2000 72376189.0\n", + "2517 USA total 1999 279040181.0\n", + "2518 USA total 2001 284968955.0\n", + "2519 USA under18 2001 72671175.0\n", + "2520 USA total 2002 287625193.0\n", + "2521 USA under18 2002 72936457.0\n", + "2522 USA total 2003 290107933.0\n", + "2523 USA under18 2003 73100758.0\n", + "2524 USA total 2004 292805298.0\n", + "2525 USA under18 2004 73297735.0\n", + "2526 USA total 2005 295516599.0\n", + "2527 USA under18 2005 73523669.0\n", + "2528 USA total 2006 298379912.0\n", + "2529 USA under18 2006 73757714.0\n", + "2530 USA total 2007 301231207.0\n", + "2531 USA under18 2007 74019405.0\n", + "2532 USA total 2008 304093966.0\n", + "2533 USA under18 2008 74104602.0\n", + "2534 USA under18 2013 73585872.0\n", + "2535 USA total 2013 316128839.0\n", + "2536 USA total 2009 306771529.0\n", + "2537 USA under18 2009 74134167.0\n", + "2538 USA under18 2010 74119556.0\n", + "2539 USA total 2010 309326295.0\n", + "2540 USA under18 2011 73902222.0\n", + "2541 USA total 2011 311582564.0\n", + "2542 USA under18 2012 73708179.0\n", + "2543 USA total 2012 313873685.0\n", + "\n", + "[2544 rows x 4 columns]" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# 美国的人口数据\n", + "pop = pd.read_csv('./state-population.csv')\n", + "pop" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(2544, 4)" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pop.shape" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "scrolled": false + }, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
state/regionagesyearpopulation
0ALunder1820121117489.0
1ALtotal20124817528.0
2ALunder1820101130966.0
3ALtotal20104785570.0
4ALunder1820111125763.0
\n", + "
" + ], + "text/plain": [ + " state/region ages year population\n", + "0 AL under18 2012 1117489.0\n", + "1 AL total 2012 4817528.0\n", + "2 AL under18 2010 1130966.0\n", + "3 AL total 2010 4785570.0\n", + "4 AL under18 2011 1125763.0" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pop.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
stateabbreviation
0AlabamaAL
1AlaskaAK
2ArizonaAZ
3ArkansasAR
4CaliforniaCA
\n", + "
" + ], + "text/plain": [ + " state abbreviation\n", + "0 Alabama AL\n", + "1 Alaska AK\n", + "2 Arizona AZ\n", + "3 Arkansas AR\n", + "4 California CA" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "abbrevs.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "(2544, 4)" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "(51, 2)" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "display(pop.shape,abbrevs.shape)" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "(2544, 6)" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# 级联时,数据变少了96个,哪些数据变少\n", + "# inner内连接,outer叫做外连接\n", + "pop2 = pop.merge(abbrevs,how = 'outer',left_on='state/region',right_on='abbreviation')\n", + "pop2.shape" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "state/region False\n", + "ages False\n", + "year False\n", + "population True\n", + "state True\n", + "abbreviation True\n", + "dtype: bool" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# 前三列没有空值\n", + "pop2.isnull().any()" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": { + "collapsed": true + }, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
state/regionagesyearpopulationstateabbreviation
0ALunder1820121117489.0AlabamaAL
1ALtotal20124817528.0AlabamaAL
2ALunder1820101130966.0AlabamaAL
3ALtotal20104785570.0AlabamaAL
4ALunder1820111125763.0AlabamaAL
\n", + "
" + ], + "text/plain": [ + " state/region ages year population state abbreviation\n", + "0 AL under18 2012 1117489.0 Alabama AL\n", + "1 AL total 2012 4817528.0 Alabama AL\n", + "2 AL under18 2010 1130966.0 Alabama AL\n", + "3 AL total 2010 4785570.0 Alabama AL\n", + "4 AL under18 2011 1125763.0 Alabama AL" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pop2.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [], + "source": [ + "# 删除一列\n", + "pop2.drop(labels = 'abbreviation',axis = 1,inplace=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
state/regionagesyearpopulationstate
0ALunder1820121117489.0Alabama
1ALtotal20124817528.0Alabama
2ALunder1820101130966.0Alabama
3ALtotal20104785570.0Alabama
4ALunder1820111125763.0Alabama
\n", + "
" + ], + "text/plain": [ + " state/region ages year population state\n", + "0 AL under18 2012 1117489.0 Alabama\n", + "1 AL total 2012 4817528.0 Alabama\n", + "2 AL under18 2010 1130966.0 Alabama\n", + "3 AL total 2010 4785570.0 Alabama\n", + "4 AL under18 2011 1125763.0 Alabama" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pop2.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "state/region False\n", + "ages False\n", + "year False\n", + "population True\n", + "state True\n", + "dtype: bool" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pop2.isnull().any()" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": { + "collapsed": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "0 False\n", + "1 False\n", + "2 False\n", + "3 False\n", + "4 False\n", + "5 False\n", + "6 False\n", + "7 False\n", + "8 False\n", + "9 False\n", + "10 False\n", + "11 False\n", + "12 False\n", + "13 False\n", + "14 False\n", + "15 False\n", + "16 False\n", + "17 False\n", + "18 False\n", + "19 False\n", + "20 False\n", + "21 False\n", + "22 False\n", + "23 False\n", + "24 False\n", + "25 False\n", + "26 False\n", + "27 False\n", + "28 False\n", + "29 False\n", + " ... \n", + "2514 True\n", + "2515 True\n", + "2516 True\n", + "2517 True\n", + "2518 True\n", + "2519 True\n", + "2520 True\n", + "2521 True\n", + "2522 True\n", + "2523 True\n", + "2524 True\n", + "2525 True\n", + "2526 True\n", + "2527 True\n", + "2528 True\n", + "2529 True\n", + "2530 True\n", + "2531 True\n", + "2532 True\n", + "2533 True\n", + "2534 True\n", + "2535 True\n", + "2536 True\n", + "2537 True\n", + "2538 True\n", + "2539 True\n", + "2540 True\n", + "2541 True\n", + "2542 True\n", + "2543 True\n", + "Name: state, Length: 2544, dtype: bool" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# 定位为空的数据\n", + "cond = pop2['state'].isnull()\n", + "cond" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array(['PR', 'USA'], dtype=object)" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# 只有当state为空,返回,为空时True\n", + "# 去重操作,非重复值\n", + "pop2[cond]['state/region'].unique()" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "(51, 2)" + ] + }, + "execution_count": 30, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "abbrevs.shape" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(52, 2)" + ] + }, + "execution_count": 31, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "areas.shape" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": { + "collapsed": true + }, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
statearea (sq. mi)
0Alabama52423
1Alaska656425
2Arizona114006
3Arkansas53182
4California163707
5Colorado104100
6Connecticut5544
7Delaware1954
8Florida65758
9Georgia59441
10Hawaii10932
11Idaho83574
12Illinois57918
13Indiana36420
14Iowa56276
15Kansas82282
16Kentucky40411
17Louisiana51843
18Maine35387
19Maryland12407
20Massachusetts10555
21Michigan96810
22Minnesota86943
23Mississippi48434
24Missouri69709
25Montana147046
26Nebraska77358
27Nevada110567
28New Hampshire9351
29New Jersey8722
30New Mexico121593
31New York54475
32North Carolina53821
33North Dakota70704
34Ohio44828
35Oklahoma69903
36Oregon98386
37Pennsylvania46058
38Rhode Island1545
39South Carolina32007
40South Dakota77121
41Tennessee42146
42Texas268601
43Utah84904
44Vermont9615
45Virginia42769
46Washington71303
47West Virginia24231
48Wisconsin65503
49Wyoming97818
50District of Columbia68
51Puerto Rico3515
\n", + "
" + ], + "text/plain": [ + " state area (sq. mi)\n", + "0 Alabama 52423\n", + "1 Alaska 656425\n", + "2 Arizona 114006\n", + "3 Arkansas 53182\n", + "4 California 163707\n", + "5 Colorado 104100\n", + "6 Connecticut 5544\n", + "7 Delaware 1954\n", + "8 Florida 65758\n", + "9 Georgia 59441\n", + "10 Hawaii 10932\n", + "11 Idaho 83574\n", + "12 Illinois 57918\n", + "13 Indiana 36420\n", + "14 Iowa 56276\n", + "15 Kansas 82282\n", + "16 Kentucky 40411\n", + "17 Louisiana 51843\n", + "18 Maine 35387\n", + "19 Maryland 12407\n", + "20 Massachusetts 10555\n", + "21 Michigan 96810\n", + "22 Minnesota 86943\n", + "23 Mississippi 48434\n", + "24 Missouri 69709\n", + "25 Montana 147046\n", + "26 Nebraska 77358\n", + "27 Nevada 110567\n", + "28 New Hampshire 9351\n", + "29 New Jersey 8722\n", + "30 New Mexico 121593\n", + "31 New York 54475\n", + "32 North Carolina 53821\n", + "33 North Dakota 70704\n", + "34 Ohio 44828\n", + "35 Oklahoma 69903\n", + "36 Oregon 98386\n", + "37 Pennsylvania 46058\n", + "38 Rhode Island 1545\n", + "39 South Carolina 32007\n", + "40 South Dakota 77121\n", + "41 Tennessee 42146\n", + "42 Texas 268601\n", + "43 Utah 84904\n", + "44 Vermont 9615\n", + "45 Virginia 42769\n", + "46 Washington 71303\n", + "47 West Virginia 24231\n", + "48 Wisconsin 65503\n", + "49 Wyoming 97818\n", + "50 District of Columbia 68\n", + "51 Puerto Rico 3515" + ] + }, + "execution_count": 32, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "areas" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "metadata": { + "collapsed": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "0 False\n", + "1 False\n", + "2 False\n", + "3 False\n", + "4 False\n", + "5 False\n", + "6 False\n", + "7 False\n", + "8 False\n", + "9 False\n", + "10 False\n", + "11 False\n", + "12 False\n", + "13 False\n", + "14 False\n", + "15 False\n", + "16 False\n", + "17 False\n", + "18 False\n", + "19 False\n", + "20 False\n", + "21 False\n", + "22 False\n", + "23 False\n", + "24 False\n", + "25 False\n", + "26 False\n", + "27 False\n", + "28 False\n", + "29 False\n", + " ... \n", + "2514 False\n", + "2515 False\n", + "2516 False\n", + "2517 False\n", + "2518 False\n", + "2519 False\n", + "2520 False\n", + "2521 False\n", + "2522 False\n", + "2523 False\n", + "2524 False\n", + "2525 False\n", + "2526 False\n", + "2527 False\n", + "2528 False\n", + "2529 False\n", + "2530 False\n", + "2531 False\n", + "2532 False\n", + "2533 False\n", + "2534 False\n", + "2535 False\n", + "2536 False\n", + "2537 False\n", + "2538 False\n", + "2539 False\n", + "2540 False\n", + "2541 False\n", + "2542 False\n", + "2543 False\n", + "Name: state/region, Length: 2544, dtype: bool" + ] + }, + "execution_count": 34, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "cond = pop2['state/region'] == 'PR'\n", + "cond" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "d:\\python36\\lib\\site-packages\\ipykernel_launcher.py:1: SettingWithCopyWarning: \n", + "A value is trying to be set on a copy of a slice from a DataFrame\n", + "\n", + "See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy\n", + " \"\"\"Entry point for launching an IPython kernel.\n" + ] + } + ], + "source": [ + "pop2['state'][cond] = 'Puerto Rico'" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "d:\\python36\\lib\\site-packages\\ipykernel_launcher.py:2: SettingWithCopyWarning: \n", + "A value is trying to be set on a copy of a slice from a DataFrame\n", + "\n", + "See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy\n", + " \n" + ] + } + ], + "source": [ + "cond = pop2['state/region'] == 'USA'\n", + "pop2['state'][cond] = 'United State'" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "state/region False\n", + "ages False\n", + "year False\n", + "population True\n", + "state False\n", + "dtype: bool" + ] + }, + "execution_count": 39, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pop2.isnull().any()" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": { + "scrolled": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "(20, 5)" + ] + }, + "execution_count": 42, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "cond = pop2['population'].isnull()\n", + "pop2[cond].shape" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(2544, 5)" + ] + }, + "execution_count": 43, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pop2.shape" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "metadata": {}, + "outputs": [], + "source": [ + "# 将难于进行补全的空数据进行删除\n", + "pop2.dropna(inplace=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(2524, 5)" + ] + }, + "execution_count": 46, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pop2.shape" + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "state/region False\n", + "ages False\n", + "year False\n", + "population False\n", + "state False\n", + "dtype: bool" + ] + }, + "execution_count": 47, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pop2.isnull().any()" + ] + }, + { + "cell_type": "code", + "execution_count": 48, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "state/region True\n", + "ages True\n", + "year True\n", + "population True\n", + "state True\n", + "dtype: bool" + ] + }, + "execution_count": 48, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pop2.notnull().all()" + ] + }, + { + "cell_type": "code", + "execution_count": 50, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
statearea (sq. mi)
0Alabama52423
1Alaska656425
2Arizona114006
3Arkansas53182
4California163707
\n", + "
" + ], + "text/plain": [ + " state area (sq. mi)\n", + "0 Alabama 52423\n", + "1 Alaska 656425\n", + "2 Arizona 114006\n", + "3 Arkansas 53182\n", + "4 California 163707" + ] + }, + "execution_count": 50, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "areas.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 49, + "metadata": { + "scrolled": false + }, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
state/regionagesyearpopulationstate
0ALunder1820121117489.0Alabama
1ALtotal20124817528.0Alabama
2ALunder1820101130966.0Alabama
3ALtotal20104785570.0Alabama
4ALunder1820111125763.0Alabama
\n", + "
" + ], + "text/plain": [ + " state/region ages year population state\n", + "0 AL under18 2012 1117489.0 Alabama\n", + "1 AL total 2012 4817528.0 Alabama\n", + "2 AL under18 2010 1130966.0 Alabama\n", + "3 AL total 2010 4785570.0 Alabama\n", + "4 AL under18 2011 1125763.0 Alabama" + ] + }, + "execution_count": 49, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pop2.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(2524, 6)" + ] + }, + "execution_count": 51, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pop3 = pop2.merge(areas,how = 'outer')\n", + "pop3.shape" + ] + }, + { + "cell_type": "code", + "execution_count": 52, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
state/regionagesyearpopulationstatearea (sq. mi)
0ALunder1820121117489.0Alabama52423.0
1ALtotal20124817528.0Alabama52423.0
2ALunder1820101130966.0Alabama52423.0
3ALtotal20104785570.0Alabama52423.0
4ALunder1820111125763.0Alabama52423.0
\n", + "
" + ], + "text/plain": [ + " state/region ages year population state area (sq. mi)\n", + "0 AL under18 2012 1117489.0 Alabama 52423.0\n", + "1 AL total 2012 4817528.0 Alabama 52423.0\n", + "2 AL under18 2010 1130966.0 Alabama 52423.0\n", + "3 AL total 2010 4785570.0 Alabama 52423.0\n", + "4 AL under18 2011 1125763.0 Alabama 52423.0" + ] + }, + "execution_count": 52, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pop3.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 53, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "state/region False\n", + "ages False\n", + "year False\n", + "population False\n", + "state False\n", + "area (sq. mi) True\n", + "dtype: bool" + ] + }, + "execution_count": 53, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pop3.isnull().any()" + ] + }, + { + "cell_type": "code", + "execution_count": 54, + "metadata": { + "collapsed": true + }, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
state/regionagesyearpopulationstatearea (sq. mi)
2476USAunder18199064218512.0United StateNaN
2477USAtotal1990249622814.0United StateNaN
2478USAtotal1991252980942.0United StateNaN
2479USAunder18199165313018.0United StateNaN
2480USAunder18199266509177.0United StateNaN
2481USAtotal1992256514231.0United StateNaN
2482USAtotal1993259918595.0United StateNaN
2483USAunder18199367594938.0United StateNaN
2484USAunder18199468640936.0United StateNaN
2485USAtotal1994263125826.0United StateNaN
2486USAunder18199569473140.0United StateNaN
2487USAunder18199670233512.0United StateNaN
2488USAtotal1995266278403.0United StateNaN
2489USAtotal1996269394291.0United StateNaN
2490USAtotal1997272646932.0United StateNaN
2491USAunder18199770920738.0United StateNaN
2492USAunder18199871431406.0United StateNaN
2493USAtotal1998275854116.0United StateNaN
2494USAunder18199971946051.0United StateNaN
2495USAtotal2000282162411.0United StateNaN
2496USAunder18200072376189.0United StateNaN
2497USAtotal1999279040181.0United StateNaN
2498USAtotal2001284968955.0United StateNaN
2499USAunder18200172671175.0United StateNaN
2500USAtotal2002287625193.0United StateNaN
2501USAunder18200272936457.0United StateNaN
2502USAtotal2003290107933.0United StateNaN
2503USAunder18200373100758.0United StateNaN
2504USAtotal2004292805298.0United StateNaN
2505USAunder18200473297735.0United StateNaN
2506USAtotal2005295516599.0United StateNaN
2507USAunder18200573523669.0United StateNaN
2508USAtotal2006298379912.0United StateNaN
2509USAunder18200673757714.0United StateNaN
2510USAtotal2007301231207.0United StateNaN
2511USAunder18200774019405.0United StateNaN
2512USAtotal2008304093966.0United StateNaN
2513USAunder18200874104602.0United StateNaN
2514USAunder18201373585872.0United StateNaN
2515USAtotal2013316128839.0United StateNaN
2516USAtotal2009306771529.0United StateNaN
2517USAunder18200974134167.0United StateNaN
2518USAunder18201074119556.0United StateNaN
2519USAtotal2010309326295.0United StateNaN
2520USAunder18201173902222.0United StateNaN
2521USAtotal2011311582564.0United StateNaN
2522USAunder18201273708179.0United StateNaN
2523USAtotal2012313873685.0United StateNaN
\n", + "
" + ], + "text/plain": [ + " state/region ages year population state area (sq. mi)\n", + "2476 USA under18 1990 64218512.0 United State NaN\n", + "2477 USA total 1990 249622814.0 United State NaN\n", + "2478 USA total 1991 252980942.0 United State NaN\n", + "2479 USA under18 1991 65313018.0 United State NaN\n", + "2480 USA under18 1992 66509177.0 United State NaN\n", + "2481 USA total 1992 256514231.0 United State NaN\n", + "2482 USA total 1993 259918595.0 United State NaN\n", + "2483 USA under18 1993 67594938.0 United State NaN\n", + "2484 USA under18 1994 68640936.0 United State NaN\n", + "2485 USA total 1994 263125826.0 United State NaN\n", + "2486 USA under18 1995 69473140.0 United State NaN\n", + "2487 USA under18 1996 70233512.0 United State NaN\n", + "2488 USA total 1995 266278403.0 United State NaN\n", + "2489 USA total 1996 269394291.0 United State NaN\n", + "2490 USA total 1997 272646932.0 United State NaN\n", + "2491 USA under18 1997 70920738.0 United State NaN\n", + "2492 USA under18 1998 71431406.0 United State NaN\n", + "2493 USA total 1998 275854116.0 United State NaN\n", + "2494 USA under18 1999 71946051.0 United State NaN\n", + "2495 USA total 2000 282162411.0 United State NaN\n", + "2496 USA under18 2000 72376189.0 United State NaN\n", + "2497 USA total 1999 279040181.0 United State NaN\n", + "2498 USA total 2001 284968955.0 United State NaN\n", + "2499 USA under18 2001 72671175.0 United State NaN\n", + "2500 USA total 2002 287625193.0 United State NaN\n", + "2501 USA under18 2002 72936457.0 United State NaN\n", + "2502 USA total 2003 290107933.0 United State NaN\n", + "2503 USA under18 2003 73100758.0 United State NaN\n", + "2504 USA total 2004 292805298.0 United State NaN\n", + "2505 USA under18 2004 73297735.0 United State NaN\n", + "2506 USA total 2005 295516599.0 United State NaN\n", + "2507 USA under18 2005 73523669.0 United State NaN\n", + "2508 USA total 2006 298379912.0 United State NaN\n", + "2509 USA under18 2006 73757714.0 United State NaN\n", + "2510 USA total 2007 301231207.0 United State NaN\n", + "2511 USA under18 2007 74019405.0 United State NaN\n", + "2512 USA total 2008 304093966.0 United State NaN\n", + "2513 USA under18 2008 74104602.0 United State NaN\n", + "2514 USA under18 2013 73585872.0 United State NaN\n", + "2515 USA total 2013 316128839.0 United State NaN\n", + "2516 USA total 2009 306771529.0 United State NaN\n", + "2517 USA under18 2009 74134167.0 United State NaN\n", + "2518 USA under18 2010 74119556.0 United State NaN\n", + "2519 USA total 2010 309326295.0 United State NaN\n", + "2520 USA under18 2011 73902222.0 United State NaN\n", + "2521 USA total 2011 311582564.0 United State NaN\n", + "2522 USA under18 2012 73708179.0 United State NaN\n", + "2523 USA total 2012 313873685.0 United State NaN" + ] + }, + "execution_count": 54, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "cond = pop3['area (sq. mi)'].isnull()\n", + "pop3[cond]" + ] + }, + { + "cell_type": "code", + "execution_count": 58, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3790399" + ] + }, + "execution_count": 58, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a = areas['area (sq. mi)'].sum()\n", + "a" + ] + }, + { + "cell_type": "code", + "execution_count": 60, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "d:\\python36\\lib\\site-packages\\ipykernel_launcher.py:3: SettingWithCopyWarning: \n", + "A value is trying to be set on a copy of a slice from a DataFrame\n", + "\n", + "See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy\n", + " This is separate from the ipykernel package so we can avoid doing imports until\n" + ] + } + ], + "source": [ + "cond = pop3['state'] == \"United State\"\n", + "\n", + "pop3['area (sq. mi)'][cond] = a" + ] + }, + { + "cell_type": "code", + "execution_count": 61, + "metadata": { + "collapsed": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "state/region True\n", + "ages True\n", + "year True\n", + "population True\n", + "state True\n", + "area (sq. mi) True\n", + "dtype: bool" + ] + }, + "execution_count": 61, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pop3.notnull().all()" + ] + }, + { + "cell_type": "code", + "execution_count": 62, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
state/regionagesyearpopulationstatearea (sq. mi)
0ALunder1820121117489.0Alabama52423.0
1ALtotal20124817528.0Alabama52423.0
2ALunder1820101130966.0Alabama52423.0
3ALtotal20104785570.0Alabama52423.0
4ALunder1820111125763.0Alabama52423.0
\n", + "
" + ], + "text/plain": [ + " state/region ages year population state area (sq. mi)\n", + "0 AL under18 2012 1117489.0 Alabama 52423.0\n", + "1 AL total 2012 4817528.0 Alabama 52423.0\n", + "2 AL under18 2010 1130966.0 Alabama 52423.0\n", + "3 AL total 2010 4785570.0 Alabama 52423.0\n", + "4 AL under18 2011 1125763.0 Alabama 52423.0" + ] + }, + "execution_count": 62, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pop3.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 66, + "metadata": { + "collapsed": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "0 21.3\n", + "1 91.9\n", + "2 21.6\n", + "3 91.3\n", + "4 21.5\n", + "5 91.6\n", + "6 90.8\n", + "7 21.6\n", + "8 21.2\n", + "9 92.2\n", + "10 89.1\n", + "11 21.6\n", + "12 90.0\n", + "13 21.6\n", + "14 87.2\n", + "15 21.3\n", + "16 88.3\n", + "17 21.5\n", + "18 86.4\n", + "19 21.2\n", + "20 85.9\n", + "21 21.2\n", + "22 85.2\n", + "23 21.4\n", + "24 85.5\n", + "25 21.3\n", + "26 21.4\n", + "27 84.5\n", + "28 84.9\n", + "29 21.4\n", + " ... \n", + "2494 19.0\n", + "2495 74.4\n", + "2496 19.1\n", + "2497 73.6\n", + "2498 75.2\n", + "2499 19.2\n", + "2500 75.9\n", + "2501 19.2\n", + "2502 76.5\n", + "2503 19.3\n", + "2504 77.2\n", + "2505 19.3\n", + "2506 78.0\n", + "2507 19.4\n", + "2508 78.7\n", + "2509 19.5\n", + "2510 79.5\n", + "2511 19.5\n", + "2512 80.2\n", + "2513 19.6\n", + "2514 19.4\n", + "2515 83.4\n", + "2516 80.9\n", + "2517 19.6\n", + "2518 19.6\n", + "2519 81.6\n", + "2520 19.5\n", + "2521 82.2\n", + "2522 19.4\n", + "2523 82.8\n", + "Length: 2524, dtype: float64" + ] + }, + "execution_count": 66, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pop_density = (pop3['population']/pop3['area (sq. mi)']).round(1)\n", + "pop_density" + ] + }, + { + "cell_type": "code", + "execution_count": 67, + "metadata": { + "collapsed": true + }, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
0
021.3
191.9
221.6
391.3
421.5
591.6
690.8
721.6
821.2
992.2
1089.1
1121.6
1290.0
1321.6
1487.2
1521.3
1688.3
1721.5
1886.4
1921.2
2085.9
2121.2
2285.2
2321.4
2485.5
2521.3
2621.4
2784.5
2884.9
2921.4
......
249419.0
249574.4
249619.1
249773.6
249875.2
249919.2
250075.9
250119.2
250276.5
250319.3
250477.2
250519.3
250678.0
250719.4
250878.7
250919.5
251079.5
251119.5
251280.2
251319.6
251419.4
251583.4
251680.9
251719.6
251819.6
251981.6
252019.5
252182.2
252219.4
252382.8
\n", + "

2524 rows × 1 columns

\n", + "
" + ], + "text/plain": [ + " 0\n", + "0 21.3\n", + "1 91.9\n", + "2 21.6\n", + "3 91.3\n", + "4 21.5\n", + "5 91.6\n", + "6 90.8\n", + "7 21.6\n", + "8 21.2\n", + "9 92.2\n", + "10 89.1\n", + "11 21.6\n", + "12 90.0\n", + "13 21.6\n", + "14 87.2\n", + "15 21.3\n", + "16 88.3\n", + "17 21.5\n", + "18 86.4\n", + "19 21.2\n", + "20 85.9\n", + "21 21.2\n", + "22 85.2\n", + "23 21.4\n", + "24 85.5\n", + "25 21.3\n", + "26 21.4\n", + "27 84.5\n", + "28 84.9\n", + "29 21.4\n", + "... ...\n", + "2494 19.0\n", + "2495 74.4\n", + "2496 19.1\n", + "2497 73.6\n", + "2498 75.2\n", + "2499 19.2\n", + "2500 75.9\n", + "2501 19.2\n", + "2502 76.5\n", + "2503 19.3\n", + "2504 77.2\n", + "2505 19.3\n", + "2506 78.0\n", + "2507 19.4\n", + "2508 78.7\n", + "2509 19.5\n", + "2510 79.5\n", + "2511 19.5\n", + "2512 80.2\n", + "2513 19.6\n", + "2514 19.4\n", + "2515 83.4\n", + "2516 80.9\n", + "2517 19.6\n", + "2518 19.6\n", + "2519 81.6\n", + "2520 19.5\n", + "2521 82.2\n", + "2522 19.4\n", + "2523 82.8\n", + "\n", + "[2524 rows x 1 columns]" + ] + }, + "execution_count": 67, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pop_density = DataFrame(pop_density)\n", + "pop_density" + ] + }, + { + "cell_type": "code", + "execution_count": 68, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
pop_density
021.3
191.9
221.6
391.3
421.5
\n", + "
" + ], + "text/plain": [ + " pop_density\n", + "0 21.3\n", + "1 91.9\n", + "2 21.6\n", + "3 91.3\n", + "4 21.5" + ] + }, + "execution_count": 68, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pop_density.columns = ['pop_density']\n", + "pop_density.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 69, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
state/regionagesyearpopulationstatearea (sq. mi)pop_density
0ALunder1820121117489.0Alabama52423.021.3
1ALtotal20124817528.0Alabama52423.091.9
2ALunder1820101130966.0Alabama52423.021.6
3ALtotal20104785570.0Alabama52423.091.3
4ALunder1820111125763.0Alabama52423.021.5
\n", + "
" + ], + "text/plain": [ + " state/region ages year population state area (sq. mi) pop_density\n", + "0 AL under18 2012 1117489.0 Alabama 52423.0 21.3\n", + "1 AL total 2012 4817528.0 Alabama 52423.0 91.9\n", + "2 AL under18 2010 1130966.0 Alabama 52423.0 21.6\n", + "3 AL total 2010 4785570.0 Alabama 52423.0 91.3\n", + "4 AL under18 2011 1125763.0 Alabama 52423.0 21.5" + ] + }, + "execution_count": 69, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pop4 = pop3.merge(pop_density,left_index=True,right_index=True)\n", + "pop4.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 70, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "array([2012, 2010, 2011, 2009, 2013, 2007, 2008, 2005, 2006, 2004, 2003,\n", + " 2001, 2002, 1999, 2000, 1998, 1997, 1996, 1995, 1994, 1993, 1992,\n", + " 1991, 1990], dtype=int64)" + ] + }, + "execution_count": 70, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pop4['year'].unique()" + ] + }, + { + "cell_type": "code", + "execution_count": 71, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array(['under18', 'total'], dtype=object)" + ] + }, + "execution_count": 71, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pop4['ages'].unique()" + ] + }, + { + "cell_type": "code", + "execution_count": 73, + "metadata": { + "collapsed": true + }, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
state/regionagesyearpopulationstatearea (sq. mi)pop_density
1ALtotal20124817528.0Alabama52423.091.9
95AKtotal2012730307.0Alaska656425.01.1
97AZtotal20126551149.0Arizona114006.057.5
191ARtotal20122949828.0Arkansas53182.055.5
193CAtotal201237999878.0California163707.0232.1
287COtotal20125189458.0Colorado104100.049.9
289CTtotal20123591765.0Connecticut5544.0647.9
383DEtotal2012917053.0Delaware1954.0469.3
385DCtotal2012633427.0District of Columbia68.09315.1
479FLtotal201219320749.0Florida65758.0293.8
480GAtotal20129915646.0Georgia59441.0166.8
575HItotal20121390090.0Hawaii10932.0127.2
576IDtotal20121595590.0Idaho83574.019.1
671ILtotal201212868192.0Illinois57918.0222.2
672INtotal20126537782.0Indiana36420.0179.5
767IAtotal20123075039.0Iowa56276.054.6
768KStotal20122885398.0Kansas82282.035.1
863KYtotal20124379730.0Kentucky40411.0108.4
864LAtotal20124602134.0Louisiana51843.088.8
959MEtotal20121328501.0Maine35387.037.5
960MDtotal20125884868.0Maryland12407.0474.3
1055MAtotal20126645303.0Massachusetts10555.0629.6
1056MItotal20129882519.0Michigan96810.0102.1
1151MNtotal20125379646.0Minnesota86943.061.9
1152MStotal20122986450.0Mississippi48434.061.7
1247MOtotal20126024522.0Missouri69709.086.4
1248MTtotal20121005494.0Montana147046.06.8
1343NEtotal20121855350.0Nebraska77358.024.0
1344NVtotal20122754354.0Nevada110567.024.9
1439NHtotal20121321617.0New Hampshire9351.0141.3
1440NJtotal20128867749.0New Jersey8722.01016.7
1535NMtotal20122083540.0New Mexico121593.017.1
1536NYtotal201219576125.0New York54475.0359.4
1631NCtotal20129748364.0North Carolina53821.0181.1
1632NDtotal2012701345.0North Dakota70704.09.9
1727OHtotal201211553031.0Ohio44828.0257.7
1728OKtotal20123815780.0Oklahoma69903.054.6
1823ORtotal20123899801.0Oregon98386.039.6
1824PAtotal201212764475.0Pennsylvania46058.0277.1
1919RItotal20121050304.0Rhode Island1545.0679.8
1920SCtotal20124723417.0South Carolina32007.0147.6
2015SDtotal2012834047.0South Dakota77121.010.8
2016TNtotal20126454914.0Tennessee42146.0153.2
2111TXtotal201226060796.0Texas268601.097.0
2112UTtotal20122854871.0Utah84904.033.6
2207VTtotal2012625953.0Vermont9615.065.1
2208VAtotal20128186628.0Virginia42769.0191.4
2303WAtotal20126895318.0Washington71303.096.7
2304WVtotal20121856680.0West Virginia24231.076.6
2399WItotal20125724554.0Wisconsin65503.087.4
2400WYtotal2012576626.0Wyoming97818.05.9
2475PRtotal20123651545.0Puerto Rico3515.01038.8
2523USAtotal2012313873685.0United State3790399.082.8
\n", + "
" + ], + "text/plain": [ + " state/region ages year population state area (sq. mi) pop_density\n", + "1 AL total 2012 4817528.0 Alabama 52423.0 91.9\n", + "95 AK total 2012 730307.0 Alaska 656425.0 1.1\n", + "97 AZ total 2012 6551149.0 Arizona 114006.0 57.5\n", + "191 AR total 2012 2949828.0 Arkansas 53182.0 55.5\n", + "193 CA total 2012 37999878.0 California 163707.0 232.1\n", + "287 CO total 2012 5189458.0 Colorado 104100.0 49.9\n", + "289 CT total 2012 3591765.0 Connecticut 5544.0 647.9\n", + "383 DE total 2012 917053.0 Delaware 1954.0 469.3\n", + "385 DC total 2012 633427.0 District of Columbia 68.0 9315.1\n", + "479 FL total 2012 19320749.0 Florida 65758.0 293.8\n", + "480 GA total 2012 9915646.0 Georgia 59441.0 166.8\n", + "575 HI total 2012 1390090.0 Hawaii 10932.0 127.2\n", + "576 ID total 2012 1595590.0 Idaho 83574.0 19.1\n", + "671 IL total 2012 12868192.0 Illinois 57918.0 222.2\n", + "672 IN total 2012 6537782.0 Indiana 36420.0 179.5\n", + "767 IA total 2012 3075039.0 Iowa 56276.0 54.6\n", + "768 KS total 2012 2885398.0 Kansas 82282.0 35.1\n", + "863 KY total 2012 4379730.0 Kentucky 40411.0 108.4\n", + "864 LA total 2012 4602134.0 Louisiana 51843.0 88.8\n", + "959 ME total 2012 1328501.0 Maine 35387.0 37.5\n", + "960 MD total 2012 5884868.0 Maryland 12407.0 474.3\n", + "1055 MA total 2012 6645303.0 Massachusetts 10555.0 629.6\n", + "1056 MI total 2012 9882519.0 Michigan 96810.0 102.1\n", + "1151 MN total 2012 5379646.0 Minnesota 86943.0 61.9\n", + "1152 MS total 2012 2986450.0 Mississippi 48434.0 61.7\n", + "1247 MO total 2012 6024522.0 Missouri 69709.0 86.4\n", + "1248 MT total 2012 1005494.0 Montana 147046.0 6.8\n", + "1343 NE total 2012 1855350.0 Nebraska 77358.0 24.0\n", + "1344 NV total 2012 2754354.0 Nevada 110567.0 24.9\n", + "1439 NH total 2012 1321617.0 New Hampshire 9351.0 141.3\n", + "1440 NJ total 2012 8867749.0 New Jersey 8722.0 1016.7\n", + "1535 NM total 2012 2083540.0 New Mexico 121593.0 17.1\n", + "1536 NY total 2012 19576125.0 New York 54475.0 359.4\n", + "1631 NC total 2012 9748364.0 North Carolina 53821.0 181.1\n", + "1632 ND total 2012 701345.0 North Dakota 70704.0 9.9\n", + "1727 OH total 2012 11553031.0 Ohio 44828.0 257.7\n", + "1728 OK total 2012 3815780.0 Oklahoma 69903.0 54.6\n", + "1823 OR total 2012 3899801.0 Oregon 98386.0 39.6\n", + "1824 PA total 2012 12764475.0 Pennsylvania 46058.0 277.1\n", + "1919 RI total 2012 1050304.0 Rhode Island 1545.0 679.8\n", + "1920 SC total 2012 4723417.0 South Carolina 32007.0 147.6\n", + "2015 SD total 2012 834047.0 South Dakota 77121.0 10.8\n", + "2016 TN total 2012 6454914.0 Tennessee 42146.0 153.2\n", + "2111 TX total 2012 26060796.0 Texas 268601.0 97.0\n", + "2112 UT total 2012 2854871.0 Utah 84904.0 33.6\n", + "2207 VT total 2012 625953.0 Vermont 9615.0 65.1\n", + "2208 VA total 2012 8186628.0 Virginia 42769.0 191.4\n", + "2303 WA total 2012 6895318.0 Washington 71303.0 96.7\n", + "2304 WV total 2012 1856680.0 West Virginia 24231.0 76.6\n", + "2399 WI total 2012 5724554.0 Wisconsin 65503.0 87.4\n", + "2400 WY total 2012 576626.0 Wyoming 97818.0 5.9\n", + "2475 PR total 2012 3651545.0 Puerto Rico 3515.0 1038.8\n", + "2523 USA total 2012 313873685.0 United State 3790399.0 82.8" + ] + }, + "execution_count": 73, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# 查找2012年美国各州的全民人口数据\n", + "\n", + "# pandas非常强大的,可以像查询数据库一样进行数据查询\n", + "\n", + "pop5 = pop4.query(\"year == 2012 and ages == 'total'\")\n", + "pop5" + ] + }, + { + "cell_type": "code", + "execution_count": 78, + "metadata": {}, + "outputs": [], + "source": [ + "pop5.set_index(keys = 'state/region',inplace=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 80, + "metadata": { + "collapsed": true + }, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
agesyearpopulationstatearea (sq. mi)pop_density
state/region
AKtotal2012730307.0Alaska656425.01.1
WYtotal2012576626.0Wyoming97818.05.9
MTtotal20121005494.0Montana147046.06.8
NDtotal2012701345.0North Dakota70704.09.9
SDtotal2012834047.0South Dakota77121.010.8
NMtotal20122083540.0New Mexico121593.017.1
IDtotal20121595590.0Idaho83574.019.1
NEtotal20121855350.0Nebraska77358.024.0
NVtotal20122754354.0Nevada110567.024.9
UTtotal20122854871.0Utah84904.033.6
KStotal20122885398.0Kansas82282.035.1
MEtotal20121328501.0Maine35387.037.5
ORtotal20123899801.0Oregon98386.039.6
COtotal20125189458.0Colorado104100.049.9
IAtotal20123075039.0Iowa56276.054.6
OKtotal20123815780.0Oklahoma69903.054.6
ARtotal20122949828.0Arkansas53182.055.5
AZtotal20126551149.0Arizona114006.057.5
MStotal20122986450.0Mississippi48434.061.7
MNtotal20125379646.0Minnesota86943.061.9
VTtotal2012625953.0Vermont9615.065.1
WVtotal20121856680.0West Virginia24231.076.6
USAtotal2012313873685.0United State3790399.082.8
MOtotal20126024522.0Missouri69709.086.4
WItotal20125724554.0Wisconsin65503.087.4
LAtotal20124602134.0Louisiana51843.088.8
ALtotal20124817528.0Alabama52423.091.9
WAtotal20126895318.0Washington71303.096.7
TXtotal201226060796.0Texas268601.097.0
MItotal20129882519.0Michigan96810.0102.1
KYtotal20124379730.0Kentucky40411.0108.4
HItotal20121390090.0Hawaii10932.0127.2
NHtotal20121321617.0New Hampshire9351.0141.3
SCtotal20124723417.0South Carolina32007.0147.6
TNtotal20126454914.0Tennessee42146.0153.2
GAtotal20129915646.0Georgia59441.0166.8
INtotal20126537782.0Indiana36420.0179.5
NCtotal20129748364.0North Carolina53821.0181.1
VAtotal20128186628.0Virginia42769.0191.4
ILtotal201212868192.0Illinois57918.0222.2
CAtotal201237999878.0California163707.0232.1
OHtotal201211553031.0Ohio44828.0257.7
PAtotal201212764475.0Pennsylvania46058.0277.1
FLtotal201219320749.0Florida65758.0293.8
NYtotal201219576125.0New York54475.0359.4
DEtotal2012917053.0Delaware1954.0469.3
MDtotal20125884868.0Maryland12407.0474.3
MAtotal20126645303.0Massachusetts10555.0629.6
CTtotal20123591765.0Connecticut5544.0647.9
RItotal20121050304.0Rhode Island1545.0679.8
NJtotal20128867749.0New Jersey8722.01016.7
PRtotal20123651545.0Puerto Rico3515.01038.8
DCtotal2012633427.0District of Columbia68.09315.1
\n", + "
" + ], + "text/plain": [ + " ages year population state area (sq. mi) pop_density\n", + "state/region \n", + "AK total 2012 730307.0 Alaska 656425.0 1.1\n", + "WY total 2012 576626.0 Wyoming 97818.0 5.9\n", + "MT total 2012 1005494.0 Montana 147046.0 6.8\n", + "ND total 2012 701345.0 North Dakota 70704.0 9.9\n", + "SD total 2012 834047.0 South Dakota 77121.0 10.8\n", + "NM total 2012 2083540.0 New Mexico 121593.0 17.1\n", + "ID total 2012 1595590.0 Idaho 83574.0 19.1\n", + "NE total 2012 1855350.0 Nebraska 77358.0 24.0\n", + "NV total 2012 2754354.0 Nevada 110567.0 24.9\n", + "UT total 2012 2854871.0 Utah 84904.0 33.6\n", + "KS total 2012 2885398.0 Kansas 82282.0 35.1\n", + "ME total 2012 1328501.0 Maine 35387.0 37.5\n", + "OR total 2012 3899801.0 Oregon 98386.0 39.6\n", + "CO total 2012 5189458.0 Colorado 104100.0 49.9\n", + "IA total 2012 3075039.0 Iowa 56276.0 54.6\n", + "OK total 2012 3815780.0 Oklahoma 69903.0 54.6\n", + "AR total 2012 2949828.0 Arkansas 53182.0 55.5\n", + "AZ total 2012 6551149.0 Arizona 114006.0 57.5\n", + "MS total 2012 2986450.0 Mississippi 48434.0 61.7\n", + "MN total 2012 5379646.0 Minnesota 86943.0 61.9\n", + "VT total 2012 625953.0 Vermont 9615.0 65.1\n", + "WV total 2012 1856680.0 West Virginia 24231.0 76.6\n", + "USA total 2012 313873685.0 United State 3790399.0 82.8\n", + "MO total 2012 6024522.0 Missouri 69709.0 86.4\n", + "WI total 2012 5724554.0 Wisconsin 65503.0 87.4\n", + "LA total 2012 4602134.0 Louisiana 51843.0 88.8\n", + "AL total 2012 4817528.0 Alabama 52423.0 91.9\n", + "WA total 2012 6895318.0 Washington 71303.0 96.7\n", + "TX total 2012 26060796.0 Texas 268601.0 97.0\n", + "MI total 2012 9882519.0 Michigan 96810.0 102.1\n", + "KY total 2012 4379730.0 Kentucky 40411.0 108.4\n", + "HI total 2012 1390090.0 Hawaii 10932.0 127.2\n", + "NH total 2012 1321617.0 New Hampshire 9351.0 141.3\n", + "SC total 2012 4723417.0 South Carolina 32007.0 147.6\n", + "TN total 2012 6454914.0 Tennessee 42146.0 153.2\n", + "GA total 2012 9915646.0 Georgia 59441.0 166.8\n", + "IN total 2012 6537782.0 Indiana 36420.0 179.5\n", + "NC total 2012 9748364.0 North Carolina 53821.0 181.1\n", + "VA total 2012 8186628.0 Virginia 42769.0 191.4\n", + "IL total 2012 12868192.0 Illinois 57918.0 222.2\n", + "CA total 2012 37999878.0 California 163707.0 232.1\n", + "OH total 2012 11553031.0 Ohio 44828.0 257.7\n", + "PA total 2012 12764475.0 Pennsylvania 46058.0 277.1\n", + "FL total 2012 19320749.0 Florida 65758.0 293.8\n", + "NY total 2012 19576125.0 New York 54475.0 359.4\n", + "DE total 2012 917053.0 Delaware 1954.0 469.3\n", + "MD total 2012 5884868.0 Maryland 12407.0 474.3\n", + "MA total 2012 6645303.0 Massachusetts 10555.0 629.6\n", + "CT total 2012 3591765.0 Connecticut 5544.0 647.9\n", + "RI total 2012 1050304.0 Rhode Island 1545.0 679.8\n", + "NJ total 2012 8867749.0 New Jersey 8722.0 1016.7\n", + "PR total 2012 3651545.0 Puerto Rico 3515.0 1038.8\n", + "DC total 2012 633427.0 District of Columbia 68.0 9315.1" + ] + }, + "execution_count": 80, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pop5.sort_values(by = 'pop_density')" + ] + }, + { + "cell_type": "code", + "execution_count": 81, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
agesyearpopulationstatearea (sq. mi)pop_density
state/region
DCtotal2012633427.0District of Columbia68.09315.1
PRtotal20123651545.0Puerto Rico3515.01038.8
NJtotal20128867749.0New Jersey8722.01016.7
RItotal20121050304.0Rhode Island1545.0679.8
CTtotal20123591765.0Connecticut5544.0647.9
MAtotal20126645303.0Massachusetts10555.0629.6
MDtotal20125884868.0Maryland12407.0474.3
DEtotal2012917053.0Delaware1954.0469.3
NYtotal201219576125.0New York54475.0359.4
FLtotal201219320749.0Florida65758.0293.8
PAtotal201212764475.0Pennsylvania46058.0277.1
OHtotal201211553031.0Ohio44828.0257.7
CAtotal201237999878.0California163707.0232.1
ILtotal201212868192.0Illinois57918.0222.2
VAtotal20128186628.0Virginia42769.0191.4
NCtotal20129748364.0North Carolina53821.0181.1
INtotal20126537782.0Indiana36420.0179.5
GAtotal20129915646.0Georgia59441.0166.8
TNtotal20126454914.0Tennessee42146.0153.2
SCtotal20124723417.0South Carolina32007.0147.6
NHtotal20121321617.0New Hampshire9351.0141.3
HItotal20121390090.0Hawaii10932.0127.2
KYtotal20124379730.0Kentucky40411.0108.4
MItotal20129882519.0Michigan96810.0102.1
TXtotal201226060796.0Texas268601.097.0
WAtotal20126895318.0Washington71303.096.7
ALtotal20124817528.0Alabama52423.091.9
LAtotal20124602134.0Louisiana51843.088.8
WItotal20125724554.0Wisconsin65503.087.4
MOtotal20126024522.0Missouri69709.086.4
USAtotal2012313873685.0United State3790399.082.8
WVtotal20121856680.0West Virginia24231.076.6
VTtotal2012625953.0Vermont9615.065.1
MNtotal20125379646.0Minnesota86943.061.9
MStotal20122986450.0Mississippi48434.061.7
AZtotal20126551149.0Arizona114006.057.5
ARtotal20122949828.0Arkansas53182.055.5
OKtotal20123815780.0Oklahoma69903.054.6
IAtotal20123075039.0Iowa56276.054.6
COtotal20125189458.0Colorado104100.049.9
ORtotal20123899801.0Oregon98386.039.6
MEtotal20121328501.0Maine35387.037.5
KStotal20122885398.0Kansas82282.035.1
UTtotal20122854871.0Utah84904.033.6
NVtotal20122754354.0Nevada110567.024.9
NEtotal20121855350.0Nebraska77358.024.0
IDtotal20121595590.0Idaho83574.019.1
NMtotal20122083540.0New Mexico121593.017.1
SDtotal2012834047.0South Dakota77121.010.8
NDtotal2012701345.0North Dakota70704.09.9
MTtotal20121005494.0Montana147046.06.8
WYtotal2012576626.0Wyoming97818.05.9
AKtotal2012730307.0Alaska656425.01.1
\n", + "
" + ], + "text/plain": [ + " ages year population state area (sq. mi) pop_density\n", + "state/region \n", + "DC total 2012 633427.0 District of Columbia 68.0 9315.1\n", + "PR total 2012 3651545.0 Puerto Rico 3515.0 1038.8\n", + "NJ total 2012 8867749.0 New Jersey 8722.0 1016.7\n", + "RI total 2012 1050304.0 Rhode Island 1545.0 679.8\n", + "CT total 2012 3591765.0 Connecticut 5544.0 647.9\n", + "MA total 2012 6645303.0 Massachusetts 10555.0 629.6\n", + "MD total 2012 5884868.0 Maryland 12407.0 474.3\n", + "DE total 2012 917053.0 Delaware 1954.0 469.3\n", + "NY total 2012 19576125.0 New York 54475.0 359.4\n", + "FL total 2012 19320749.0 Florida 65758.0 293.8\n", + "PA total 2012 12764475.0 Pennsylvania 46058.0 277.1\n", + "OH total 2012 11553031.0 Ohio 44828.0 257.7\n", + "CA total 2012 37999878.0 California 163707.0 232.1\n", + "IL total 2012 12868192.0 Illinois 57918.0 222.2\n", + "VA total 2012 8186628.0 Virginia 42769.0 191.4\n", + "NC total 2012 9748364.0 North Carolina 53821.0 181.1\n", + "IN total 2012 6537782.0 Indiana 36420.0 179.5\n", + "GA total 2012 9915646.0 Georgia 59441.0 166.8\n", + "TN total 2012 6454914.0 Tennessee 42146.0 153.2\n", + "SC total 2012 4723417.0 South Carolina 32007.0 147.6\n", + "NH total 2012 1321617.0 New Hampshire 9351.0 141.3\n", + "HI total 2012 1390090.0 Hawaii 10932.0 127.2\n", + "KY total 2012 4379730.0 Kentucky 40411.0 108.4\n", + "MI total 2012 9882519.0 Michigan 96810.0 102.1\n", + "TX total 2012 26060796.0 Texas 268601.0 97.0\n", + "WA total 2012 6895318.0 Washington 71303.0 96.7\n", + "AL total 2012 4817528.0 Alabama 52423.0 91.9\n", + "LA total 2012 4602134.0 Louisiana 51843.0 88.8\n", + "WI total 2012 5724554.0 Wisconsin 65503.0 87.4\n", + "MO total 2012 6024522.0 Missouri 69709.0 86.4\n", + "USA total 2012 313873685.0 United State 3790399.0 82.8\n", + "WV total 2012 1856680.0 West Virginia 24231.0 76.6\n", + "VT total 2012 625953.0 Vermont 9615.0 65.1\n", + "MN total 2012 5379646.0 Minnesota 86943.0 61.9\n", + "MS total 2012 2986450.0 Mississippi 48434.0 61.7\n", + "AZ total 2012 6551149.0 Arizona 114006.0 57.5\n", + "AR total 2012 2949828.0 Arkansas 53182.0 55.5\n", + "OK total 2012 3815780.0 Oklahoma 69903.0 54.6\n", + "IA total 2012 3075039.0 Iowa 56276.0 54.6\n", + "CO total 2012 5189458.0 Colorado 104100.0 49.9\n", + "OR total 2012 3899801.0 Oregon 98386.0 39.6\n", + "ME total 2012 1328501.0 Maine 35387.0 37.5\n", + "KS total 2012 2885398.0 Kansas 82282.0 35.1\n", + "UT total 2012 2854871.0 Utah 84904.0 33.6\n", + "NV total 2012 2754354.0 Nevada 110567.0 24.9\n", + "NE total 2012 1855350.0 Nebraska 77358.0 24.0\n", + "ID total 2012 1595590.0 Idaho 83574.0 19.1\n", + "NM total 2012 2083540.0 New Mexico 121593.0 17.1\n", + "SD total 2012 834047.0 South Dakota 77121.0 10.8\n", + "ND total 2012 701345.0 North Dakota 70704.0 9.9\n", + "MT total 2012 1005494.0 Montana 147046.0 6.8\n", + "WY total 2012 576626.0 Wyoming 97818.0 5.9\n", + "AK total 2012 730307.0 Alaska 656425.0 1.1" + ] + }, + "execution_count": 81, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pop5.sort_values(by='pop_density',ascending=False)" + ] + } + ], + "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.6.5" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/Day76-90/code/cancer_predict.npy b/Day76-90/code/cancer_predict.npy new file mode 100644 index 0000000..a6bf034 Binary files /dev/null and b/Day76-90/code/cancer_predict.npy differ diff --git a/Day76-90/code/cancer_true.npy b/Day76-90/code/cancer_true.npy new file mode 100644 index 0000000..97e4b66 Binary files /dev/null and b/Day76-90/code/cancer_true.npy differ diff --git a/Day76-90/code/state-abbrevs.csv b/Day76-90/code/state-abbrevs.csv new file mode 100644 index 0000000..6d4db36 --- /dev/null +++ b/Day76-90/code/state-abbrevs.csv @@ -0,0 +1,52 @@ +"state","abbreviation" +"Alabama","AL" +"Alaska","AK" +"Arizona","AZ" +"Arkansas","AR" +"California","CA" +"Colorado","CO" +"Connecticut","CT" +"Delaware","DE" +"District of Columbia","DC" +"Florida","FL" +"Georgia","GA" +"Hawaii","HI" +"Idaho","ID" +"Illinois","IL" +"Indiana","IN" +"Iowa","IA" +"Kansas","KS" +"Kentucky","KY" +"Louisiana","LA" +"Maine","ME" +"Montana","MT" +"Nebraska","NE" +"Nevada","NV" +"New Hampshire","NH" +"New Jersey","NJ" +"New Mexico","NM" +"New York","NY" +"North Carolina","NC" +"North Dakota","ND" +"Ohio","OH" +"Oklahoma","OK" +"Oregon","OR" +"Maryland","MD" +"Massachusetts","MA" +"Michigan","MI" +"Minnesota","MN" +"Mississippi","MS" +"Missouri","MO" +"Pennsylvania","PA" +"Rhode Island","RI" +"South Carolina","SC" +"South Dakota","SD" +"Tennessee","TN" +"Texas","TX" +"Utah","UT" +"Vermont","VT" +"Virginia","VA" +"Washington","WA" +"West Virginia","WV" +"Wisconsin","WI" +"Wyoming","WY" \ No newline at end of file diff --git a/Day76-90/code/state-areas.csv b/Day76-90/code/state-areas.csv new file mode 100644 index 0000000..322345c --- /dev/null +++ b/Day76-90/code/state-areas.csv @@ -0,0 +1,53 @@ +state,area (sq. mi) +Alabama,52423 +Alaska,656425 +Arizona,114006 +Arkansas,53182 +California,163707 +Colorado,104100 +Connecticut,5544 +Delaware,1954 +Florida,65758 +Georgia,59441 +Hawaii,10932 +Idaho,83574 +Illinois,57918 +Indiana,36420 +Iowa,56276 +Kansas,82282 +Kentucky,40411 +Louisiana,51843 +Maine,35387 +Maryland,12407 +Massachusetts,10555 +Michigan,96810 +Minnesota,86943 +Mississippi,48434 +Missouri,69709 +Montana,147046 +Nebraska,77358 +Nevada,110567 +New Hampshire,9351 +New Jersey,8722 +New Mexico,121593 +New York,54475 +North Carolina,53821 +North Dakota,70704 +Ohio,44828 +Oklahoma,69903 +Oregon,98386 +Pennsylvania,46058 +Rhode Island,1545 +South Carolina,32007 +South Dakota,77121 +Tennessee,42146 +Texas,268601 +Utah,84904 +Vermont,9615 +Virginia,42769 +Washington,71303 +West Virginia,24231 +Wisconsin,65503 +Wyoming,97818 +District of Columbia,68 +Puerto Rico,3515 diff --git a/Day76-90/code/state-population.csv b/Day76-90/code/state-population.csv new file mode 100644 index 0000000..c76110e --- /dev/null +++ b/Day76-90/code/state-population.csv @@ -0,0 +1,2545 @@ +state/region,ages,year,population +AL,under18,2012,1117489 +AL,total,2012,4817528 +AL,under18,2010,1130966 +AL,total,2010,4785570 +AL,under18,2011,1125763 +AL,total,2011,4801627 +AL,total,2009,4757938 +AL,under18,2009,1134192 +AL,under18,2013,1111481 +AL,total,2013,4833722 +AL,total,2007,4672840 +AL,under18,2007,1132296 +AL,total,2008,4718206 +AL,under18,2008,1134927 +AL,total,2005,4569805 +AL,under18,2005,1117229 +AL,total,2006,4628981 +AL,under18,2006,1126798 +AL,total,2004,4530729 +AL,under18,2004,1113662 +AL,total,2003,4503491 +AL,under18,2003,1113083 +AL,total,2001,4467634 +AL,under18,2001,1120409 +AL,total,2002,4480089 +AL,under18,2002,1116590 +AL,under18,1999,1121287 +AL,total,1999,4430141 +AL,total,2000,4452173 +AL,under18,2000,1122273 +AL,total,1998,4404701 +AL,under18,1998,1118252 +AL,under18,1997,1122893 +AL,total,1997,4367935 +AL,total,1996,4331103 +AL,total,1995,4296800 +AL,under18,1995,1110553 +AL,under18,1996,1112092 +AL,total,1994,4260229 +AL,total,1993,4214202 +AL,under18,1993,1085606 +AL,under18,1994,1097180 +AL,under18,1992,1072873 +AL,total,1992,4154014 +AL,total,1991,4099156 +AL,under18,1991,1060794 +AL,under18,1990,1050041 +AL,total,1990,4050055 +AK,total,1990,553290 +AK,under18,1990,177502 +AK,total,1992,588736 +AK,under18,1991,182180 +AK,under18,1992,184878 +AK,total,1994,603308 +AK,under18,1994,187439 +AK,total,1991,570193 +AK,total,1993,599434 +AK,under18,1993,187190 +AK,total,1995,604412 +AK,under18,1995,184990 +AK,total,1996,608569 +AK,under18,1996,185360 +AK,under18,1997,188280 +AK,under18,1998,192636 +AK,total,1998,619933 +AK,total,1997,612968 +AK,under18,1999,191422 +AK,total,1999,624779 +AK,total,2000,627963 +AK,under18,2000,190615 +AK,total,2001,633714 +AK,under18,2001,188771 +AK,total,2002,642337 +AK,under18,2002,188482 +AK,total,2003,648414 +AK,under18,2003,186843 +AK,total,2004,659286 +AK,under18,2004,186335 +AK,total,2005,666946 +AK,under18,2005,185304 +AK,total,2006,675302 +AK,under18,2006,185580 +AK,total,2007,680300 +AK,under18,2007,184344 +AK,total,2008,687455 +AK,under18,2008,183124 +AK,under18,2013,188132 +AK,total,2013,735132 +AK,total,2009,698895 +AK,under18,2009,186351 +AK,under18,2010,187902 +AK,total,2010,713868 +AK,under18,2011,188329 +AK,total,2011,723375 +AK,under18,2012,188162 +AK,total,2012,730307 +AZ,under18,2012,1617149 +AZ,total,2012,6551149 +AZ,under18,2011,1616353 +AZ,total,2011,6468796 +AZ,under18,2010,1628563 +AZ,total,2010,6408790 +AZ,under18,2013,1616814 +AZ,total,2013,6626624 +AZ,total,2009,6343154 +AZ,under18,2009,1627343 +AZ,total,2007,6167681 +AZ,under18,2007,1607895 +AZ,total,2008,6280362 +AZ,under18,2008,1628651 +AZ,total,2005,5839077 +AZ,under18,2005,1529168 +AZ,total,2006,6029141 +AZ,under18,2006,1574867 +AZ,total,2004,5652404 +AZ,under18,2004,1484454 +AZ,total,2003,5510364 +AZ,under18,2003,1453671 +AZ,total,2001,5273477 +AZ,under18,2001,1399015 +AZ,total,2002,5396255 +AZ,under18,2002,1427938 +AZ,under18,1999,1332396 +AZ,total,1999,5023823 +AZ,total,2000,5160586 +AZ,under18,2000,1373414 +AZ,total,1998,4883342 +AZ,under18,1998,1285794 +AZ,total,1997,4736990 +AZ,under18,1997,1237159 +AZ,under18,1996,1215285 +AZ,total,1996,4586940 +AZ,total,1995,4432499 +AZ,under18,1995,1173391 +AZ,total,1993,4065440 +AZ,under18,1993,1094233 +AZ,under18,1994,1119857 +AZ,total,1994,4245089 +AZ,under18,1992,1055572 +AZ,under18,1991,1028285 +AZ,total,1991,3788576 +AZ,total,1992,3915740 +AZ,under18,1990,1006040 +AZ,total,1990,3684097 +AR,under18,1990,620933 +AR,total,1990,2356586 +AR,total,1991,2383144 +AR,under18,1991,626212 +AR,under18,1992,638269 +AR,total,1992,2415984 +AR,under18,1994,653842 +AR,total,1994,2494019 +AR,total,1993,2456303 +AR,under18,1993,643474 +AR,under18,1995,667671 +AR,total,1995,2535399 +AR,under18,1996,677912 +AR,total,1996,2572109 +AR,under18,1998,683637 +AR,total,1997,2601091 +AR,under18,1997,680203 +AR,total,1998,2626289 +AR,total,2000,2678588 +AR,under18,2000,680378 +AR,under18,1999,681940 +AR,total,1999,2651860 +AR,total,2002,2705927 +AR,under18,2002,678798 +AR,total,2001,2691571 +AR,under18,2001,679606 +AR,total,2004,2749686 +AR,under18,2004,683166 +AR,total,2003,2724816 +AR,under18,2003,679579 +AR,total,2006,2821761 +AR,under18,2006,697842 +AR,total,2005,2781097 +AR,under18,2005,689787 +AR,total,2008,2874554 +AR,under18,2008,705725 +AR,total,2007,2848650 +AR,under18,2007,702737 +AR,total,2009,2896843 +AR,under18,2009,707886 +AR,under18,2013,709866 +AR,total,2013,2959373 +AR,under18,2011,710576 +AR,total,2011,2938506 +AR,under18,2010,711947 +AR,total,2010,2922280 +AR,under18,2012,710471 +AR,total,2012,2949828 +CA,under18,2012,9209007 +CA,total,2012,37999878 +CA,under18,2011,9252336 +CA,total,2011,37668681 +CA,under18,2010,9284094 +CA,total,2010,37333601 +CA,under18,2013,9174877 +CA,total,2013,38332521 +CA,total,2009,36961229 +CA,under18,2009,9294501 +CA,total,2007,36250311 +CA,under18,2007,9335620 +CA,total,2008,36604337 +CA,under18,2008,9321621 +CA,total,2005,35827943 +CA,under18,2005,9405565 +CA,total,2006,36021202 +CA,under18,2006,9370884 +CA,total,2003,35253159 +CA,under18,2003,9404594 +CA,total,2004,35574576 +CA,under18,2004,9418497 +CA,total,2001,34479458 +CA,under18,2001,9325466 +CA,total,2002,34871843 +CA,under18,2002,9365142 +CA,under18,1999,9207878 +CA,total,1999,33499204 +CA,total,2000,33987977 +CA,under18,2000,9267089 +CA,under18,1998,9163238 +CA,total,1998,32987675 +CA,under18,1997,9135359 +CA,total,1997,32486010 +CA,under18,1996,9079519 +CA,total,1996,32018834 +CA,total,1995,31696582 +CA,under18,1995,8920578 +CA,total,1993,31274928 +CA,under18,1993,8624810 +CA,under18,1994,8790058 +CA,total,1994,31484435 +CA,total,1991,30470736 +CA,under18,1991,8245605 +CA,under18,1992,8439647 +CA,total,1992,30974659 +CA,under18,1990,7980501 +CA,total,1990,29959515 +CO,total,1990,3307618 +CO,under18,1990,881640 +CO,total,1992,3495939 +CO,under18,1992,925577 +CO,under18,1991,896537 +CO,total,1991,3387119 +CO,total,1994,3724168 +CO,under18,1994,966412 +CO,under18,1993,947806 +CO,total,1993,3613734 +CO,under18,1995,984310 +CO,total,1995,3826653 +CO,total,1996,3919972 +CO,under18,1996,1003946 +CO,under18,1997,1030557 +CO,total,1997,4018293 +CO,total,1998,4116639 +CO,under18,1998,1060066 +CO,total,2000,4326921 +CO,under18,2000,1106676 +CO,total,1999,4226018 +CO,under18,1999,1083938 +CO,total,2002,4490406 +CO,under18,2002,1138273 +CO,total,2001,4425687 +CO,under18,2001,1126647 +CO,total,2004,4575013 +CO,under18,2004,1146369 +CO,total,2003,4528732 +CO,under18,2003,1144597 +CO,total,2006,4720423 +CO,under18,2006,1171832 +CO,total,2005,4631888 +CO,under18,2005,1156399 +CO,total,2008,4889730 +CO,under18,2008,1203289 +CO,total,2007,4803868 +CO,under18,2007,1189434 +CO,total,2009,4972195 +CO,under18,2009,1217213 +CO,under18,2013,1237932 +CO,total,2013,5268367 +CO,under18,2010,1226619 +CO,total,2010,5048196 +CO,under18,2011,1230178 +CO,total,2011,5118400 +CO,under18,2012,1232864 +CO,total,2012,5189458 +CT,under18,2012,794959 +CT,total,2012,3591765 +CT,under18,2011,805109 +CT,total,2011,3588948 +CT,under18,2010,814187 +CT,total,2010,3579210 +CT,under18,2013,785566 +CT,total,2013,3596080 +CT,total,2009,3561807 +CT,under18,2009,820839 +CT,total,2007,3527270 +CT,under18,2007,833484 +CT,total,2008,3545579 +CT,under18,2008,826626 +CT,total,2005,3506956 +CT,under18,2005,844034 +CT,total,2006,3517460 +CT,under18,2006,839372 +CT,total,2003,3484336 +CT,under18,2003,851115 +CT,total,2004,3496094 +CT,under18,2004,848979 +CT,total,2001,3432835 +CT,under18,2001,845850 +CT,total,2002,3458749 +CT,under18,2002,848877 +CT,total,1999,3386401 +CT,under18,1999,834654 +CT,total,2000,3411777 +CT,under18,2000,842242 +CT,under18,1998,824600 +CT,total,1998,3365352 +CT,total,1997,3349348 +CT,under18,1997,814373 +CT,under18,1996,811855 +CT,total,1996,3336685 +CT,total,1995,3324144 +CT,under18,1995,808623 +CT,total,1993,3309175 +CT,under18,1993,790749 +CT,under18,1994,801231 +CT,total,1994,3316121 +CT,under18,1991,766304 +CT,total,1991,3302895 +CT,under18,1992,777264 +CT,total,1992,3300712 +CT,total,1990,3291967 +CT,under18,1990,752666 +DE,under18,1990,165628 +DE,total,1990,669567 +DE,under18,1992,174166 +DE,total,1992,694927 +DE,total,1991,683080 +DE,under18,1991,169910 +DE,total,1994,717545 +DE,under18,1994,180833 +DE,total,1993,706378 +DE,under18,1993,176916 +DE,under18,1995,181736 +DE,total,1995,729735 +DE,total,1996,740978 +DE,under18,1996,184021 +DE,under18,1997,186607 +DE,total,1997,751487 +DE,total,1998,763335 +DE,under18,1998,189302 +DE,total,2000,786373 +DE,under18,2000,194914 +DE,total,1999,774990 +DE,under18,1999,192510 +DE,total,2002,806169 +DE,under18,2002,196946 +DE,total,2001,795699 +DE,under18,2001,196038 +DE,total,2004,830803 +DE,under18,2004,199631 +DE,total,2003,818003 +DE,under18,2003,198045 +DE,total,2006,859268 +DE,under18,2006,203729 +DE,total,2005,845150 +DE,under18,2005,201988 +DE,total,2008,883874 +DE,under18,2008,206116 +DE,total,2007,871749 +DE,under18,2007,205155 +DE,under18,2013,203558 +DE,total,2013,925749 +DE,total,2009,891730 +DE,under18,2009,206213 +DE,under18,2010,205478 +DE,total,2010,899711 +DE,under18,2011,204801 +DE,total,2011,907985 +DE,under18,2012,204586 +DE,total,2012,917053 +DC,under18,2012,107642 +DC,total,2012,633427 +DC,under18,2011,103906 +DC,total,2011,619624 +DC,under18,2010,101309 +DC,total,2010,605125 +DC,under18,2013,111474 +DC,total,2013,646449 +DC,total,2009,592228 +DC,under18,2009,102098 +DC,total,2007,574404 +DC,under18,2007,104126 +DC,total,2008,580236 +DC,under18,2008,102257 +DC,total,2005,567136 +DC,under18,2005,107187 +DC,total,2006,570681 +DC,under18,2006,105651 +DC,total,2003,568502 +DC,under18,2003,111403 +DC,total,2004,567754 +DC,under18,2004,109756 +DC,total,2001,574504 +DC,under18,2001,114625 +DC,total,2002,573158 +DC,under18,2002,113822 +DC,total,1999,570220 +DC,under18,1999,115003 +DC,total,2000,572046 +DC,under18,2000,114503 +DC,under18,1998,113839 +DC,total,1998,565232 +DC,under18,1997,119531 +DC,total,1997,567739 +DC,under18,1996,121210 +DC,total,1996,572379 +DC,total,1995,580519 +DC,under18,1995,123620 +DC,total,1993,595302 +DC,under18,1993,120471 +DC,under18,1994,122170 +DC,total,1994,589240 +DC,total,1991,600870 +DC,under18,1991,116825 +DC,under18,1992,118636 +DC,total,1992,597567 +DC,under18,1990,112632 +DC,total,1990,605321 +FL,total,1990,13033307 +FL,under18,1990,2988807 +FL,under18,1991,3045638 +FL,total,1991,13369798 +FL,total,1994,14239444 +FL,under18,1994,3299887 +FL,under18,1993,3214066 +FL,total,1993,13927185 +FL,total,1992,13650553 +FL,under18,1992,3120439 +FL,under18,1995,3366468 +FL,total,1995,14537875 +FL,total,1996,14853360 +FL,under18,1996,3431695 +FL,under18,1998,3557561 +FL,under18,1997,3502269 +FL,total,1997,15186304 +FL,total,1998,15486559 +FL,total,1999,15759421 +FL,under18,1999,3611711 +FL,total,2000,16047515 +FL,under18,2000,3654880 +FL,total,2001,16356966 +FL,under18,2001,3714439 +FL,total,2002,16689370 +FL,under18,2002,3774624 +FL,total,2003,17004085 +FL,under18,2003,3820876 +FL,total,2004,17415318 +FL,under18,2004,3890734 +FL,total,2005,17842038 +FL,under18,2005,3968178 +FL,total,2006,18166990 +FL,under18,2006,4022912 +FL,total,2007,18367842 +FL,under18,2007,4031098 +FL,total,2008,18527305 +FL,under18,2008,4018372 +FL,total,2009,18652644 +FL,under18,2009,3997283 +FL,under18,2013,4026674 +FL,total,2013,19552860 +FL,under18,2010,3999532 +FL,total,2010,18846054 +FL,under18,2011,4002550 +FL,total,2011,19083482 +FL,under18,2012,4012421 +FL,total,2012,19320749 +GA,total,2012,9915646 +GA,under18,2012,2487831 +GA,under18,2011,2488898 +GA,total,2011,9810181 +GA,under18,2010,2490884 +GA,total,2010,9713248 +GA,total,2013,9992167 +GA,total,2009,9620846 +GA,under18,2009,2485781 +GA,under18,2013,2489709 +GA,total,2007,9349988 +GA,under18,2007,2456249 +GA,total,2008,9504843 +GA,under18,2008,2479097 +GA,total,2005,8925922 +GA,under18,2005,2353604 +GA,total,2006,9155813 +GA,under18,2006,2406014 +GA,total,2003,8622793 +GA,under18,2003,2278710 +GA,total,2004,8769252 +GA,under18,2004,2308855 +GA,total,2001,8377038 +GA,under18,2001,2215390 +GA,total,2002,8508256 +GA,under18,2002,2249784 +GA,total,1999,8045965 +GA,under18,1999,2130698 +GA,total,2000,8227303 +GA,under18,2000,2176576 +GA,total,1997,7685099 +GA,under18,1997,2034163 +GA,under18,1998,2078998 +GA,total,1998,7863536 +GA,under18,1996,1993171 +GA,total,1996,7501069 +GA,total,1995,7328413 +GA,under18,1995,1949818 +GA,under18,1992,1817781 +GA,total,1992,6817203 +GA,total,1993,6978240 +GA,under18,1993,1865021 +GA,under18,1994,1906539 +GA,total,1994,7157165 +GA,total,1991,6653005 +GA,under18,1991,1773675 +GA,under18,1990,1747363 +GA,total,1990,6512602 +HI,under18,1990,279983 +HI,total,1990,1113491 +HI,total,1991,1136754 +HI,under18,1991,287871 +HI,under18,1994,307517 +HI,total,1994,1187536 +HI,total,1993,1172838 +HI,under18,1993,301473 +HI,under18,1992,295124 +HI,total,1992,1158613 +HI,total,1995,1196854 +HI,under18,1995,310325 +HI,under18,1996,311213 +HI,total,1996,1203755 +HI,under18,1998,304576 +HI,total,1998,1215233 +HI,total,1997,1211640 +HI,under18,1997,309465 +HI,total,2000,1213519 +HI,under18,2000,295352 +HI,total,1999,1210300 +HI,under18,1999,299680 +HI,total,2002,1239613 +HI,under18,2002,293600 +HI,total,2001,1225948 +HI,under18,2001,294133 +HI,total,2004,1273569 +HI,under18,2004,298103 +HI,total,2003,1251154 +HI,under18,2003,294519 +HI,total,2006,1309731 +HI,under18,2006,299313 +HI,total,2005,1292729 +HI,under18,2005,298497 +HI,total,2008,1332213 +HI,under18,2008,301094 +HI,total,2007,1315675 +HI,under18,2007,300207 +HI,under18,2013,307266 +HI,total,2009,1346717 +HI,under18,2009,302796 +HI,total,2013,1404054 +HI,total,2010,1363731 +HI,under18,2010,303812 +HI,total,2011,1376897 +HI,under18,2011,305396 +HI,under18,2012,305981 +HI,total,2012,1390090 +ID,total,2012,1595590 +ID,under18,2012,427177 +ID,under18,2011,428535 +ID,total,2011,1583930 +ID,under18,2010,428961 +ID,total,2010,1570718 +ID,total,2013,1612136 +ID,total,2009,1554439 +ID,under18,2009,426076 +ID,under18,2013,427781 +ID,total,2007,1505105 +ID,under18,2007,415024 +ID,total,2008,1534320 +ID,under18,2008,422347 +ID,total,2005,1428241 +ID,under18,2005,394651 +ID,total,2006,1468669 +ID,under18,2006,404753 +ID,total,2003,1363380 +ID,under18,2003,379241 +ID,total,2004,1391802 +ID,under18,2004,384692 +ID,total,2001,1319962 +ID,under18,2001,373145 +ID,total,2002,1340372 +ID,under18,2002,375986 +ID,total,1999,1275674 +ID,under18,1999,366689 +ID,total,2000,1299430 +ID,under18,2000,370430 +ID,total,1997,1228520 +ID,under18,1997,357779 +ID,under18,1998,362189 +ID,total,1998,1252330 +ID,under18,1996,353824 +ID,total,1996,1203083 +ID,total,1995,1177322 +ID,under18,1995,349248 +ID,under18,1992,324972 +ID,total,1992,1071685 +ID,total,1993,1108768 +ID,under18,1993,333838 +ID,under18,1994,344242 +ID,total,1994,1145140 +ID,total,1991,1041316 +ID,under18,1991,316732 +ID,under18,1990,313373 +ID,total,1990,1012384 +IL,under18,1990,2940837 +IL,total,1990,11453316 +IL,total,1991,11568964 +IL,under18,1991,2988715 +IL,under18,1994,3110938 +IL,total,1994,11912585 +IL,total,1993,11809579 +IL,under18,1993,3066541 +IL,under18,1992,3033427 +IL,total,1992,11694184 +IL,total,1995,12008437 +IL,under18,1995,3152984 +IL,under18,1996,3192916 +IL,total,1996,12101997 +IL,under18,1998,3225252 +IL,total,1998,12271847 +IL,total,1997,12185715 +IL,under18,1997,3222114 +IL,total,2000,12434161 +IL,under18,2000,3244944 +IL,total,1999,12359020 +IL,under18,1999,3240034 +IL,total,2002,12525556 +IL,under18,2002,3238362 +IL,total,2001,12488445 +IL,under18,2001,3243617 +IL,total,2004,12589773 +IL,under18,2004,3211599 +IL,total,2003,12556006 +IL,under18,2003,3225547 +IL,total,2006,12643955 +IL,under18,2006,3181246 +IL,total,2005,12609903 +IL,under18,2005,3197318 +IL,total,2008,12747038 +IL,under18,2008,3153401 +IL,total,2007,12695866 +IL,under18,2007,3170134 +IL,under18,2013,3023307 +IL,total,2009,12796778 +IL,under18,2009,3138406 +IL,total,2013,12882135 +IL,total,2010,12839695 +IL,under18,2010,3122092 +IL,total,2011,12855970 +IL,under18,2011,3089833 +IL,under18,2012,3057042 +IL,total,2012,12868192 +IN,total,2012,6537782 +IN,under18,2012,1589655 +IN,under18,2011,1598091 +IN,total,2011,6516336 +IN,under18,2010,1605883 +IN,total,2010,6489965 +IN,total,2013,6570902 +IN,total,2009,6459325 +IN,under18,2009,1609704 +IN,under18,2013,1586027 +IN,total,2007,6379599 +IN,under18,2007,1609494 +IN,total,2008,6424806 +IN,under18,2008,1611494 +IN,total,2005,6278616 +IN,under18,2005,1593898 +IN,total,2006,6332669 +IN,under18,2006,1603107 +IN,total,2003,6196638 +IN,under18,2003,1582560 +IN,total,2004,6233007 +IN,under18,2004,1586281 +IN,total,2001,6127760 +IN,under18,2001,1579527 +IN,total,2002,6155967 +IN,under18,2002,1580814 +IN,total,1999,6044970 +IN,under18,1999,1566079 +IN,total,2000,6091866 +IN,under18,2000,1574989 +IN,total,1997,5955267 +IN,under18,1997,1539270 +IN,under18,1998,1551960 +IN,total,1998,5998881 +IN,under18,1996,1517961 +IN,total,1996,5906013 +IN,total,1995,5851459 +IN,under18,1995,1507916 +IN,under18,1992,1461650 +IN,total,1992,5674547 +IN,total,1993,5739019 +IN,under18,1993,1473007 +IN,under18,1994,1491802 +IN,total,1994,5793526 +IN,total,1991,5616388 +IN,under18,1991,1450759 +IN,under18,1990,1437209 +IN,total,1990,5557798 +IA,under18,1990,719366 +IA,total,1990,2781018 +IA,total,1991,2797613 +IA,under18,1991,724446 +IA,under18,1994,728397 +IA,total,1994,2850746 +IA,total,1993,2836972 +IA,under18,1993,727751 +IA,under18,1992,724798 +IA,total,1992,2818401 +IA,total,1995,2867373 +IA,under18,1995,726961 +IA,under18,1996,729177 +IA,total,1996,2880001 +IA,under18,1998,729943 +IA,total,1998,2902872 +IA,total,1997,2891119 +IA,under18,1997,729806 +IA,total,2000,2929067 +IA,under18,2000,733337 +IA,total,1999,2917634 +IA,under18,1999,732671 +IA,total,2002,2934234 +IA,under18,2002,723685 +IA,total,2001,2931997 +IA,under18,2001,728601 +IA,total,2004,2953635 +IA,under18,2004,718708 +IA,total,2003,2941999 +IA,under18,2003,720102 +IA,total,2006,2982644 +IA,under18,2006,721703 +IA,total,2005,2964454 +IA,under18,2005,718488 +IA,total,2008,3016734 +IA,under18,2008,725658 +IA,total,2007,2999212 +IA,under18,2007,723632 +IA,under18,2013,724032 +IA,total,2009,3032870 +IA,under18,2009,726969 +IA,total,2013,3090416 +IA,total,2010,3050314 +IA,under18,2010,727717 +IA,total,2011,3064102 +IA,under18,2011,725522 +IA,under18,2012,723917 +IA,total,2012,3075039 +KS,total,2012,2885398 +KS,under18,2012,726668 +KS,under18,2011,726787 +KS,total,2011,2869548 +KS,under18,2010,727729 +KS,total,2010,2858910 +KS,total,2013,2893957 +KS,total,2009,2832704 +KS,under18,2009,721841 +KS,under18,2013,724092 +KS,total,2007,2783785 +KS,under18,2007,711005 +KS,total,2008,2808076 +KS,under18,2008,714689 +KS,total,2005,2745299 +KS,under18,2005,704689 +KS,total,2006,2762931 +KS,under18,2006,705277 +KS,total,2003,2723004 +KS,under18,2003,707847 +KS,total,2004,2734373 +KS,under18,2004,705456 +KS,total,2001,2702162 +KS,under18,2001,710923 +KS,total,2002,2713535 +KS,under18,2002,709416 +KS,total,1999,2678338 +KS,under18,1999,713022 +KS,total,2000,2693681 +KS,under18,2000,713887 +KS,total,1997,2635292 +KS,under18,1997,704001 +KS,under18,1998,710402 +KS,total,1998,2660598 +KS,under18,1996,696298 +KS,total,1996,2614554 +KS,total,1995,2601008 +KS,under18,1995,694124 +KS,under18,1992,680871 +KS,total,1992,2532395 +KS,total,1993,2556547 +KS,under18,1993,687262 +KS,under18,1994,693673 +KS,total,1994,2580513 +KS,total,1991,2498722 +KS,under18,1991,672033 +KS,under18,1990,662641 +KS,total,1990,2481349 +KY,under18,1990,945951 +KY,total,1990,3694048 +KY,total,1991,3722328 +KY,under18,1991,951512 +KY,under18,1994,981439 +KY,total,1994,3849088 +KY,total,1993,3812206 +KY,under18,1993,971134 +KY,under18,1992,963861 +KY,total,1992,3765469 +KY,total,1995,3887427 +KY,under18,1995,984486 +KY,under18,1996,987062 +KY,total,1996,3919536 +KY,under18,1998,997296 +KY,total,1998,3985391 +KY,total,1997,3952747 +KY,under18,1997,1002609 +KY,total,2000,4049021 +KY,under18,2000,994984 +KY,total,1999,4018053 +KY,under18,1999,996382 +KY,total,2002,4089875 +KY,under18,2002,995251 +KY,total,2001,4068132 +KY,under18,2001,994105 +KY,total,2004,4146101 +KY,under18,2004,998459 +KY,total,2003,4117170 +KY,under18,2003,998485 +KY,total,2006,4219239 +KY,under18,2006,1011295 +KY,total,2005,4182742 +KY,under18,2005,1004020 +KY,total,2008,4289878 +KY,under18,2008,1022001 +KY,total,2007,4256672 +KY,under18,2007,1016288 +KY,under18,2013,1014004 +KY,total,2009,4317074 +KY,under18,2009,1021710 +KY,total,2013,4395295 +KY,total,2010,4347698 +KY,under18,2010,1023679 +KY,total,2011,4366869 +KY,under18,2011,1021926 +KY,under18,2012,1017350 +KY,total,2012,4379730 +LA,total,2012,4602134 +LA,under18,2012,1114620 +LA,under18,2011,1116579 +LA,total,2011,4575197 +LA,under18,2010,1118576 +LA,total,2010,4545392 +LA,total,2013,4625470 +LA,total,2009,4491648 +LA,under18,2009,1114228 +LA,under18,2013,1112957 +LA,total,2007,4375581 +LA,under18,2007,1096642 +LA,total,2008,4435586 +LA,under18,2008,1108728 +LA,total,2005,4576628 +LA,under18,2005,1177954 +LA,total,2006,4302665 +LA,under18,2006,1078779 +LA,total,2003,4521042 +LA,under18,2003,1188070 +LA,total,2004,4552238 +LA,under18,2004,1182731 +LA,total,2001,4477875 +LA,under18,2001,1204187 +LA,total,2002,4497267 +LA,under18,2002,1194819 +LA,total,2000,4471885 +LA,under18,2000,1217670 +LA,total,1999,4460811 +LA,under18,1999,1227167 +LA,total,1997,4421072 +LA,under18,1997,1239665 +LA,under18,1998,1232984 +LA,total,1998,4440344 +LA,under18,1996,1244627 +LA,total,1996,4398877 +LA,total,1995,4378779 +LA,under18,1995,1250112 +LA,under18,1992,1237034 +LA,total,1992,4293003 +LA,total,1993,4316428 +LA,under18,1993,1239161 +LA,under18,1994,1247631 +LA,total,1994,4347481 +LA,total,1991,4253279 +LA,under18,1991,1222330 +LA,under18,1990,1205984 +LA,total,1990,4221532 +ME,under18,1990,308066 +ME,total,1990,1231719 +ME,total,1991,1237081 +ME,under18,1991,309871 +ME,under18,1994,311570 +ME,total,1994,1242662 +ME,total,1993,1242302 +ME,under18,1993,310966 +ME,under18,1992,310679 +ME,total,1992,1238508 +ME,total,1995,1243481 +ME,under18,1995,309173 +ME,under18,1996,307740 +ME,total,1996,1249060 +ME,under18,1998,304496 +ME,total,1998,1259127 +ME,total,1997,1254774 +ME,under18,1997,305097 +ME,total,1999,1266808 +ME,under18,1999,302321 +ME,total,2000,1277072 +ME,under18,2000,301407 +ME,total,2002,1295960 +ME,under18,2002,298595 +ME,total,2001,1285692 +ME,under18,2001,300088 +ME,total,2004,1313688 +ME,under18,2004,294791 +ME,total,2003,1306513 +ME,under18,2003,296786 +ME,total,2006,1323619 +ME,under18,2006,288945 +ME,total,2005,1318787 +ME,under18,2005,292039 +ME,total,2008,1330509 +ME,under18,2008,282204 +ME,total,2007,1327040 +ME,under18,2007,286185 +ME,under18,2013,261276 +ME,total,2009,1329590 +ME,under18,2009,277946 +ME,total,2013,1328302 +ME,total,2010,1327366 +ME,under18,2010,273061 +ME,total,2011,1327844 +ME,under18,2011,268737 +ME,under18,2012,264846 +ME,total,2012,1328501 +MD,total,2012,5884868 +MD,under18,2012,1346235 +MD,under18,2011,1348766 +MD,total,2011,5840241 +MD,under18,2010,1351983 +MD,total,2010,5787193 +MD,total,2013,5928814 +MD,total,2009,5730388 +MD,under18,2009,1353631 +MD,under18,2013,1344522 +MD,total,2007,5653408 +MD,under18,2007,1369563 +MD,total,2008,5684965 +MD,under18,2008,1359214 +MD,total,2005,5592379 +MD,under18,2005,1382966 +MD,total,2006,5627367 +MD,under18,2006,1377756 +MD,total,2003,5496269 +MD,under18,2003,1379641 +MD,total,2004,5546935 +MD,under18,2004,1383450 +MD,total,2001,5374691 +MD,under18,2001,1366552 +MD,total,2002,5440389 +MD,under18,2002,1375354 +MD,total,2000,5311034 +MD,under18,2000,1356961 +MD,total,1999,5254509 +MD,under18,1999,1348659 +MD,total,1997,5157328 +MD,under18,1997,1321306 +MD,under18,1998,1338727 +MD,total,1998,5204464 +MD,under18,1996,1303816 +MD,total,1996,5111986 +MD,total,1995,5070033 +MD,under18,1995,1300695 +MD,under18,1992,1235498 +MD,total,1992,4923369 +MD,total,1993,4971889 +MD,under18,1993,1261738 +MD,under18,1994,1280772 +MD,total,1994,5023060 +MD,total,1991,4867641 +MD,under18,1991,1208898 +MD,under18,1990,1180426 +MD,total,1990,4799770 +MA,under18,1990,1353806 +MA,total,1990,6022639 +MA,total,1991,6018470 +MA,under18,1991,1375110 +MA,under18,1994,1437069 +MA,total,1994,6095241 +MA,total,1993,6060569 +MA,under18,1993,1415724 +MA,under18,1992,1390188 +MA,total,1992,6028709 +MA,total,1995,6141445 +MA,under18,1995,1453489 +MA,under18,1996,1468614 +MA,total,1996,6179756 +MA,under18,1998,1491652 +MA,total,1998,6271838 +MA,total,1997,6226058 +MA,under18,1997,1478203 +MA,total,1999,6317345 +MA,under18,1999,1495818 +MA,total,2000,6361104 +MA,under18,2000,1501334 +MA,total,2001,6397634 +MA,under18,2001,1505028 +MA,total,2002,6417206 +MA,under18,2002,1502652 +MA,total,2004,6412281 +MA,under18,2004,1479541 +MA,total,2003,6422565 +MA,under18,2003,1493372 +MA,total,2006,6410084 +MA,under18,2006,1450202 +MA,total,2005,6403290 +MA,under18,2005,1464140 +MA,total,2008,6468967 +MA,under18,2008,1429727 +MA,total,2007,6431559 +MA,under18,2007,1439757 +MA,under18,2013,1393946 +MA,total,2009,6517613 +MA,under18,2009,1422935 +MA,total,2013,6692824 +MA,total,2010,6563263 +MA,under18,2010,1415962 +MA,total,2011,6606285 +MA,under18,2011,1407240 +MA,under18,2012,1399417 +MA,total,2012,6645303 +MI,total,2012,9882519 +MI,under18,2012,2269365 +MI,under18,2011,2299116 +MI,total,2011,9874589 +MI,under18,2010,2333121 +MI,total,2010,9876149 +MI,total,2013,9895622 +MI,total,2009,9901591 +MI,under18,2009,2372603 +MI,under18,2013,2245201 +MI,total,2007,10001284 +MI,under18,2007,2470063 +MI,total,2008,9946889 +MI,under18,2008,2418879 +MI,total,2005,10051137 +MI,under18,2005,2531839 +MI,total,2006,10036081 +MI,under18,2006,2503548 +MI,total,2003,10041152 +MI,under18,2003,2569080 +MI,total,2004,10055315 +MI,under18,2004,2553314 +MI,total,2002,10015710 +MI,under18,2002,2584310 +MI,total,2001,9991120 +MI,under18,2001,2593310 +MI,total,2000,9952450 +MI,under18,2000,2596114 +MI,total,1999,9897116 +MI,under18,1999,2591944 +MI,total,1997,9809051 +MI,under18,1997,2582270 +MI,under18,1998,2586343 +MI,total,1998,9847942 +MI,under18,1996,2569745 +MI,total,1996,9758645 +MI,total,1995,9676211 +MI,under18,1995,2556799 +MI,under18,1992,2501765 +MI,total,1992,9479065 +MI,total,1993,9540114 +MI,under18,1993,2522249 +MI,under18,1994,2535196 +MI,total,1994,9597737 +MI,total,1991,9400446 +MI,under18,1991,2484957 +MI,under18,1990,2459633 +MI,total,1990,9311319 +MN,under18,1990,1176680 +MN,total,1990,4389857 +MN,total,1991,4440859 +MN,under18,1991,1191207 +MN,under18,1994,1238949 +MN,total,1994,4610355 +MN,total,1993,4555956 +MN,under18,1993,1226723 +MN,under18,1992,1213068 +MN,total,1992,4495572 +MN,total,1995,4660180 +MN,under18,1995,1245932 +MN,under18,1996,1252722 +MN,total,1996,4712827 +MN,under18,1998,1275940 +MN,total,1998,4813412 +MN,total,1997,4763390 +MN,under18,1997,1264250 +MN,total,1999,4873481 +MN,under18,1999,1283102 +MN,total,2000,4933692 +MN,under18,2000,1289715 +MN,total,2001,4982796 +MN,under18,2001,1291261 +MN,total,2002,5018935 +MN,under18,2002,1288795 +MN,total,2004,5087713 +MN,under18,2004,1281946 +MN,total,2003,5053572 +MN,under18,2003,1283687 +MN,total,2006,5163555 +MN,under18,2006,1282381 +MN,total,2005,5119598 +MN,under18,2005,1280557 +MN,total,2008,5247018 +MN,under18,2008,1284179 +MN,total,2007,5207203 +MN,under18,2007,1285074 +MN,under18,2013,1279111 +MN,total,2009,5281203 +MN,under18,2009,1284103 +MN,total,2013,5420380 +MN,total,2010,5310337 +MN,under18,2010,1282693 +MN,total,2011,5347108 +MN,under18,2011,1280424 +MN,under18,2012,1278050 +MN,total,2012,5379646 +MS,total,2012,2986450 +MS,under18,2012,742941 +MS,under18,2011,747742 +MS,total,2011,2977886 +MS,under18,2010,754111 +MS,total,2010,2970047 +MS,total,2013,2991207 +MS,total,2009,2958774 +MS,under18,2009,758539 +MS,under18,2013,737432 +MS,total,2007,2928350 +MS,under18,2007,761171 +MS,total,2008,2947806 +MS,under18,2008,760572 +MS,total,2005,2905943 +MS,under18,2005,760870 +MS,total,2006,2904978 +MS,under18,2006,756990 +MS,total,2003,2868312 +MS,under18,2003,759447 +MS,total,2004,2889010 +MS,under18,2004,760410 +MS,total,2002,2858681 +MS,under18,2002,763148 +MS,total,2001,2852994 +MS,under18,2001,768418 +MS,total,2000,2848353 +MS,under18,2000,774353 +MS,total,1999,2828408 +MS,under18,1999,775662 +MS,total,1997,2777004 +MS,under18,1997,774832 +MS,under18,1998,773721 +MS,total,1998,2804834 +MS,under18,1996,769680 +MS,total,1996,2748085 +MS,total,1995,2722659 +MS,under18,1995,767892 +MS,under18,1992,750224 +MS,total,1992,2623734 +MS,total,1993,2655100 +MS,under18,1993,755820 +MS,under18,1994,763795 +MS,total,1994,2688992 +MS,total,1991,2598733 +MS,under18,1991,738911 +MS,under18,1990,733660 +MS,total,1990,2578897 +MO,under18,1990,1316423 +MO,total,1990,5128880 +MO,total,1991,5170800 +MO,under18,1991,1332306 +MO,under18,1994,1378700 +MO,total,1994,5324497 +MO,total,1993,5271175 +MO,under18,1993,1365903 +MO,under18,1992,1349729 +MO,total,1992,5217101 +MO,under18,1996,1408732 +MO,total,1996,5431553 +MO,total,1995,5378247 +MO,under18,1995,1393554 +MO,under18,1998,1428999 +MO,total,1998,5521765 +MO,total,1997,5481193 +MO,under18,1997,1419837 +MO,total,1999,5561948 +MO,under18,1999,1428047 +MO,total,2000,5607285 +MO,under18,2000,1428383 +MO,total,2001,5641142 +MO,under18,2001,1426575 +MO,total,2002,5674825 +MO,under18,2002,1424513 +MO,total,2004,5747741 +MO,under18,2004,1420956 +MO,total,2003,5709403 +MO,under18,2003,1421927 +MO,total,2006,5842704 +MO,under18,2006,1428324 +MO,total,2005,5790300 +MO,under18,2005,1422978 +MO,total,2008,5923916 +MO,under18,2008,1428945 +MO,total,2007,5887612 +MO,under18,2007,1431346 +MO,under18,2013,1397685 +MO,total,2009,5961088 +MO,under18,2009,1426603 +MO,total,2013,6044171 +MO,total,2010,5996063 +MO,under18,2010,1424042 +MO,total,2011,6010065 +MO,under18,2011,1414444 +MO,under18,2012,1405015 +MO,total,2012,6024522 +MT,total,2012,1005494 +MT,under18,2012,222905 +MT,under18,2011,222977 +MT,total,2011,997600 +MT,under18,2010,223292 +MT,total,2010,990527 +MT,total,2013,1015165 +MT,total,2009,983982 +MT,under18,2009,223675 +MT,under18,2013,223981 +MT,total,2007,964706 +MT,under18,2007,223135 +MT,total,2008,976415 +MT,under18,2008,223814 +MT,total,2005,940102 +MT,under18,2005,221685 +MT,total,2006,952692 +MT,under18,2006,221930 +MT,total,2003,919630 +MT,under18,2003,223012 +MT,total,2004,930009 +MT,under18,2004,221999 +MT,total,2002,911667 +MT,under18,2002,224772 +MT,total,2001,906961 +MT,under18,2001,227118 +MT,total,1999,897508 +MT,under18,1999,231133 +MT,total,2000,903773 +MT,under18,2000,230067 +MT,total,1997,889865 +MT,under18,1997,232813 +MT,under18,1998,231746 +MT,total,1998,892431 +MT,total,1995,876553 +MT,under18,1995,236583 +MT,under18,1996,235294 +MT,total,1996,886254 +MT,under18,1992,230868 +MT,total,1992,825770 +MT,total,1993,844761 +MT,under18,1993,234987 +MT,under18,1994,237289 +MT,total,1994,861306 +MT,total,1991,809680 +MT,under18,1991,225259 +MT,under18,1990,223677 +MT,total,1990,800204 +NE,under18,1990,430068 +NE,total,1990,1581660 +NE,total,1991,1595919 +NE,under18,1991,434525 +NE,under18,1994,442589 +NE,total,1994,1639041 +NE,total,1993,1625590 +NE,under18,1993,439313 +NE,under18,1992,436378 +NE,total,1992,1611687 +NE,under18,1996,446841 +NE,total,1996,1673740 +NE,total,1995,1656993 +NE,under18,1995,444418 +NE,under18,1998,451192 +NE,total,1998,1695817 +NE,total,1997,1686418 +NE,under18,1997,450076 +NE,total,1999,1704764 +NE,under18,1999,451047 +NE,total,2000,1713820 +NE,under18,2000,450380 +NE,total,2001,1719836 +NE,under18,2001,448307 +NE,total,2002,1728292 +NE,under18,2002,447714 +NE,total,2004,1749370 +NE,under18,2004,448360 +NE,total,2003,1738643 +NE,under18,2003,447444 +NE,total,2006,1772693 +NE,under18,2006,450098 +NE,total,2005,1761497 +NE,under18,2005,448918 +NE,total,2008,1796378 +NE,under18,2008,453787 +NE,total,2007,1783440 +NE,under18,2007,451946 +NE,under18,2013,464348 +NE,total,2009,1812683 +NE,under18,2009,456543 +NE,total,2013,1868516 +NE,total,2010,1829838 +NE,under18,2010,459621 +NE,total,2011,1841749 +NE,under18,2011,460872 +NE,under18,2012,462673 +NE,total,2012,1855350 +NV,total,2012,2754354 +NV,under18,2012,659655 +NV,under18,2011,659236 +NV,total,2011,2717951 +NV,under18,2010,663180 +NV,total,2010,2703230 +NV,total,2013,2790136 +NV,total,2009,2684665 +NV,under18,2009,666041 +NV,under18,2013,661605 +NV,total,2007,2601072 +NV,under18,2007,654053 +NV,total,2008,2653630 +NV,under18,2008,662621 +NV,total,2005,2432143 +NV,under18,2005,611595 +NV,total,2006,2522658 +NV,under18,2006,634403 +NV,total,2003,2248850 +NV,under18,2003,568963 +NV,total,2004,2346222 +NV,under18,2004,591314 +NV,total,2002,2173791 +NV,under18,2002,552816 +NV,total,2001,2098399 +NV,under18,2001,534708 +NV,total,1999,1934718 +NV,under18,1999,493701 +NV,total,2000,2018741 +NV,under18,2000,516018 +NV,total,1997,1764104 +NV,under18,1997,443626 +NV,under18,1998,469424 +NV,total,1998,1853192 +NV,total,1995,1581578 +NV,under18,1995,396223 +NV,under18,1996,419133 +NV,total,1996,1666320 +NV,under18,1992,337396 +NV,total,1992,1351367 +NV,total,1993,1411215 +NV,under18,1993,354990 +NV,under18,1994,376745 +NV,total,1994,1499298 +NV,total,1991,1296172 +NV,under18,1991,325033 +NV,under18,1990,316406 +NV,total,1990,1220695 +NH,under18,1990,277454 +NH,total,1990,1112384 +NH,total,1991,1109929 +NH,under18,1991,281127 +NH,under18,1994,295563 +NH,total,1994,1142561 +NH,total,1993,1129458 +NH,under18,1993,290409 +NH,under18,1992,286314 +NH,total,1992,1117785 +NH,under18,1996,300161 +NH,total,1996,1174719 +NH,total,1995,1157561 +NH,under18,1995,298246 +NH,under18,1998,307292 +NH,total,1998,1205941 +NH,total,1997,1189425 +NH,under18,1997,302834 +NH,total,2000,1239882 +NH,under18,2000,310352 +NH,total,1999,1222015 +NH,under18,1999,308423 +NH,total,2001,1255517 +NH,under18,2001,311877 +NH,total,2002,1269089 +NH,under18,2002,312743 +NH,total,2004,1290121 +NH,under18,2004,309243 +NH,total,2003,1279840 +NH,under18,2003,311412 +NH,total,2005,1298492 +NH,under18,2005,307403 +NH,total,2006,1308389 +NH,under18,2006,305169 +NH,total,2008,1315906 +NH,under18,2008,296029 +NH,total,2007,1312540 +NH,under18,2007,300918 +NH,under18,2013,271122 +NH,total,2009,1316102 +NH,under18,2009,290850 +NH,total,2013,1323459 +NH,total,2010,1316614 +NH,under18,2010,285702 +NH,total,2011,1318075 +NH,under18,2011,280486 +NH,under18,2012,275818 +NH,total,2012,1321617 +NJ,total,2012,8867749 +NJ,under18,2012,2035106 +NJ,under18,2011,2049453 +NJ,total,2011,8836639 +NJ,under18,2010,2062013 +NJ,total,2010,8802707 +NJ,total,2013,8899339 +NJ,total,2009,8755602 +NJ,under18,2009,2068684 +NJ,under18,2013,2022117 +NJ,total,2007,8677885 +NJ,under18,2007,2091023 +NJ,total,2008,8711090 +NJ,under18,2008,2076366 +NJ,total,2006,8661679 +NJ,under18,2006,2106403 +NJ,total,2005,8651974 +NJ,under18,2005,2121878 +NJ,total,2003,8601402 +NJ,under18,2003,2126014 +NJ,total,2004,8634561 +NJ,under18,2004,2129051 +NJ,total,2002,8552643 +NJ,under18,2002,2116591 +NJ,total,2001,8492671 +NJ,under18,2001,2102838 +NJ,total,1999,8359592 +NJ,under18,1999,2066678 +NJ,total,2000,8430621 +NJ,under18,2000,2088885 +NJ,total,1997,8218808 +NJ,under18,1997,2028349 +NJ,under18,1998,2042080 +NJ,total,1998,8287418 +NJ,total,1995,8083242 +NJ,under18,1995,1997187 +NJ,under18,1996,2016502 +NJ,total,1996,8149596 +NJ,under18,1992,1890108 +NJ,total,1992,7880508 +NJ,total,1993,7948915 +NJ,under18,1993,1928623 +NJ,under18,1994,1968232 +NJ,total,1994,8014306 +NJ,total,1991,7814676 +NJ,under18,1991,1849605 +NJ,under18,1990,1818187 +NJ,total,1990,7762963 +NM,total,1990,1521574 +NM,under18,1990,453538 +NM,under18,1991,461811 +NM,total,1991,1555305 +NM,under18,1994,497542 +NM,under18,1993,487742 +NM,total,1993,1636453 +NM,total,1992,1595442 +NM,under18,1992,473176 +NM,total,1994,1682398 +NM,under18,1996,508100 +NM,total,1995,1720394 +NM,under18,1995,504558 +NM,total,1996,1752326 +NM,under18,1998,512801 +NM,total,1998,1793484 +NM,total,1997,1774839 +NM,under18,1997,514500 +NM,under18,1999,511135 +NM,total,1999,1808082 +NM,total,2000,1821204 +NM,under18,2000,508132 +NM,total,2001,1831690 +NM,under18,2001,503404 +NM,total,2002,1855309 +NM,under18,2002,502779 +NM,total,2004,1903808 +NM,under18,2004,501184 +NM,total,2003,1877574 +NM,under18,2003,500777 +NM,total,2005,1932274 +NM,under18,2005,502612 +NM,total,2006,1962137 +NM,under18,2006,505125 +NM,total,2008,2010662 +NM,under18,2008,511214 +NM,total,2007,1990070 +NM,under18,2007,508725 +NM,under18,2013,507540 +NM,total,2013,2085287 +NM,total,2009,2036802 +NM,under18,2009,515470 +NM,total,2010,2064982 +NM,under18,2010,518763 +NM,under18,2011,516513 +NM,total,2011,2077919 +NM,under18,2012,512314 +NM,total,2012,2083540 +NY,total,2012,19576125 +NY,under18,2012,4264694 +NY,total,2011,19502728 +NY,under18,2011,4294555 +NY,under18,2010,4318033 +NY,total,2010,19398228 +NY,total,2009,19307066 +NY,under18,2009,4342926 +NY,total,2013,19651127 +NY,under18,2013,4239976 +NY,total,2007,19132335 +NY,under18,2007,4410949 +NY,total,2008,19212436 +NY,under18,2008,4372170 +NY,total,2006,19104631 +NY,under18,2006,4457777 +NY,total,2005,19132610 +NY,under18,2005,4514456 +NY,total,2003,19175939 +NY,under18,2003,4619506 +NY,total,2004,19171567 +NY,under18,2004,4574065 +NY,total,2002,19137800 +NY,under18,2002,4652232 +NY,total,2001,19082838 +NY,under18,2001,4672425 +NY,under18,1999,4672587 +NY,total,1999,18882725 +NY,total,2000,19001780 +NY,under18,2000,4687374 +NY,under18,1997,4670787 +NY,total,1997,18656546 +NY,total,1998,18755906 +NY,under18,1998,4652140 +NY,total,1996,18588460 +NY,under18,1995,4648419 +NY,total,1995,18524104 +NY,under18,1996,4667647 +NY,total,1994,18459470 +NY,under18,1992,4465539 +NY,total,1992,18246653 +NY,total,1993,18374954 +NY,under18,1993,4538171 +NY,under18,1994,4605284 +NY,total,1991,18122510 +NY,under18,1991,4372727 +NY,under18,1990,4281643 +NY,total,1990,18020784 +NC,under18,1990,1625804 +NC,total,1990,6664016 +NC,total,1991,6784280 +NC,under18,1991,1640394 +NC,total,1993,7042818 +NC,under18,1993,1710267 +NC,under18,1992,1674144 +NC,total,1992,6897214 +NC,under18,1994,1750754 +NC,total,1994,7187398 +NC,total,1995,7344674 +NC,under18,1995,1785150 +NC,under18,1996,1821506 +NC,total,1996,7500670 +NC,under18,1998,1894753 +NC,total,1998,7809122 +NC,total,1997,7656825 +NC,under18,1997,1861621 +NC,total,2000,8081614 +NC,under18,2000,1967626 +NC,total,1999,7949362 +NC,under18,1999,1932141 +NC,total,2001,8210122 +NC,under18,2001,2003782 +NC,total,2002,8326201 +NC,under18,2002,2034451 +NC,total,2004,8553152 +NC,under18,2004,2085165 +NC,total,2003,8422501 +NC,under18,2003,2060838 +NC,total,2005,8705407 +NC,under18,2005,2122485 +NC,total,2006,8917270 +NC,under18,2006,2166393 +NC,total,2008,9309449 +NC,under18,2008,2252101 +NC,total,2007,9118037 +NC,under18,2007,2219168 +NC,under18,2013,2285605 +NC,total,2013,9848060 +NC,total,2009,9449566 +NC,under18,2009,2272955 +NC,total,2010,9559533 +NC,under18,2010,2282288 +NC,under18,2011,2284238 +NC,total,2011,9651377 +NC,under18,2012,2284122 +NC,total,2012,9748364 +ND,total,2012,701345 +ND,under18,2012,156765 +ND,total,2011,684867 +ND,under18,2011,152357 +ND,under18,2010,150179 +ND,total,2010,674344 +ND,total,2009,664968 +ND,under18,2009,148674 +ND,total,2013,723393 +ND,under18,2013,162688 +ND,total,2007,652822 +ND,under18,2007,147263 +ND,total,2008,657569 +ND,under18,2008,147462 +ND,total,2006,649422 +ND,under18,2006,147331 +ND,total,2005,646089 +ND,under18,2005,148119 +ND,total,2003,638817 +ND,under18,2003,150406 +ND,total,2004,644705 +ND,under18,2004,149128 +ND,total,2002,638168 +ND,under18,2002,153097 +ND,total,2001,639062 +ND,under18,2001,156113 +ND,total,1999,644259 +ND,under18,1999,163056 +ND,total,2000,642023 +ND,under18,2000,160477 +ND,total,1997,649716 +ND,under18,1997,167475 +ND,under18,1998,165448 +ND,total,1998,647532 +ND,under18,1996,169257 +ND,total,1996,650382 +ND,total,1995,647832 +ND,under18,1995,171146 +ND,under18,1994,172160 +ND,total,1994,644806 +ND,under18,1992,172052 +ND,total,1992,638223 +ND,total,1993,641216 +ND,under18,1993,172168 +ND,total,1991,635753 +ND,under18,1991,171730 +ND,under18,1990,170920 +ND,total,1990,637685 +OH,under18,1990,2778491 +OH,total,1990,10864162 +OH,total,1991,10945762 +OH,under18,1991,2806959 +OH,total,1993,11101140 +OH,under18,1993,2855785 +OH,under18,1992,2839356 +OH,total,1992,11029431 +OH,under18,1994,2875397 +OH,total,1994,11152455 +OH,total,1995,11202751 +OH,under18,1995,2879930 +OH,under18,1996,2883443 +OH,total,1996,11242827 +OH,under18,1998,2896255 +OH,total,1998,11311536 +OH,total,1997,11277357 +OH,under18,1997,2897375 +OH,total,2000,11363543 +OH,under18,2000,2886585 +OH,total,1999,11335454 +OH,under18,1999,2893270 +OH,total,2001,11387404 +OH,under18,2001,2878123 +OH,total,2002,11407889 +OH,under18,2002,2865674 +OH,total,2004,11452251 +OH,under18,2004,2836068 +OH,total,2003,11434788 +OH,under18,2003,2849573 +OH,total,2005,11463320 +OH,under18,2005,2819794 +OH,total,2006,11481213 +OH,under18,2006,2804828 +OH,total,2008,11515391 +OH,under18,2008,2768968 +OH,total,2007,11500468 +OH,under18,2007,2790347 +OH,under18,2013,2649830 +OH,total,2013,11570808 +OH,total,2009,11528896 +OH,under18,2009,2748051 +OH,total,2010,11545435 +OH,under18,2010,2722589 +OH,under18,2011,2693469 +OH,total,2011,11549772 +OH,under18,2012,2668125 +OH,total,2012,11553031 +OK,total,2012,3815780 +OK,under18,2012,939911 +OK,total,2011,3785534 +OK,under18,2011,935714 +OK,under18,2010,931483 +OK,total,2010,3759263 +OK,total,2009,3717572 +OK,under18,2009,922711 +OK,total,2013,3850568 +OK,under18,2013,947027 +OK,total,2007,3634349 +OK,under18,2007,904328 +OK,total,2008,3668976 +OK,under18,2008,910617 +OK,total,2006,3594090 +OK,under18,2006,894761 +OK,total,2005,3548597 +OK,under18,2005,885316 +OK,total,2003,3504892 +OK,under18,2003,883959 +OK,total,2004,3525233 +OK,under18,2004,881606 +OK,total,2002,3489080 +OK,under18,2002,884961 +OK,total,2001,3467100 +OK,under18,2001,885218 +OK,total,1999,3437148 +OK,under18,1999,895678 +OK,total,2000,3454365 +OK,under18,2000,891847 +OK,total,1997,3372918 +OK,under18,1997,893835 +OK,under18,1998,898501 +OK,total,1998,3405194 +OK,under18,1996,887093 +OK,total,1996,3340129 +OK,total,1995,3308208 +OK,under18,1995,883667 +OK,under18,1994,877803 +OK,total,1994,3280940 +OK,under18,1992,862548 +OK,total,1992,3220517 +OK,total,1993,3252285 +OK,under18,1993,870137 +OK,total,1991,3175440 +OK,under18,1991,849639 +OK,under18,1990,841715 +OK,total,1990,3148825 +OR,under18,1990,742436 +OR,total,1990,2860375 +OR,total,1991,2928507 +OR,under18,1991,752442 +OR,total,1993,3060367 +OR,under18,1993,778973 +OR,under18,1992,770191 +OR,total,1992,2991755 +OR,under18,1994,793435 +OR,total,1994,3121264 +OR,total,1995,3184369 +OR,under18,1995,806512 +OR,under18,1996,816102 +OR,total,1996,3247111 +OR,under18,1998,837928 +OR,total,1998,3352449 +OR,total,1997,3304310 +OR,under18,1997,830002 +OR,total,2000,3429708 +OR,under18,2000,847511 +OR,total,1999,3393941 +OR,under18,1999,843484 +OR,total,2001,3467937 +OR,under18,2001,848663 +OR,total,2002,3513424 +OR,under18,2002,850733 +OR,total,2004,3569463 +OR,under18,2004,846786 +OR,total,2003,3547376 +OR,under18,2003,850251 +OR,total,2005,3613202 +OR,under18,2005,849323 +OR,total,2006,3670883 +OR,under18,2006,857003 +OR,total,2008,3768748 +OR,under18,2008,865664 +OR,total,2007,3722417 +OR,under18,2007,862161 +OR,under18,2013,857606 +OR,total,2013,3930065 +OR,total,2009,3808600 +OR,under18,2009,866194 +OR,total,2010,3837208 +OR,under18,2010,865129 +OR,under18,2011,862518 +OR,total,2011,3867937 +OR,under18,2012,859910 +OR,total,2012,3899801 +PA,total,2012,12764475 +PA,under18,2012,2737905 +PA,total,2011,12741310 +PA,under18,2011,2761343 +PA,under18,2010,2785316 +PA,total,2010,12710472 +PA,total,2009,12666858 +PA,under18,2009,2804929 +PA,total,2013,12773801 +PA,under18,2013,2715645 +PA,total,2007,12563937 +PA,under18,2007,2839574 +PA,total,2008,12612285 +PA,under18,2008,2821004 +PA,total,2006,12510809 +PA,under18,2006,2850778 +PA,total,2005,12449990 +PA,under18,2005,2859793 +PA,total,2003,12374658 +PA,under18,2003,2883270 +PA,total,2004,12410722 +PA,under18,2004,2873125 +PA,total,2002,12331031 +PA,under18,2002,2894935 +PA,total,2001,12298970 +PA,under18,2001,2905836 +PA,total,1999,12263805 +PA,under18,1999,2930193 +PA,total,2000,12284173 +PA,under18,2000,2918850 +PA,total,1997,12227814 +PA,under18,1997,2942240 +PA,under18,1998,2940285 +PA,total,1998,12245672 +PA,under18,1996,2937411 +PA,total,1996,12220464 +PA,total,1995,12198403 +PA,under18,1995,2941531 +PA,under18,1994,2932851 +PA,total,1994,12166050 +PA,under18,1992,2873013 +PA,total,1992,12049450 +PA,total,1993,12119724 +PA,under18,1993,2907351 +PA,total,1991,11982164 +PA,under18,1991,2830059 +PA,under18,1990,2799168 +PA,total,1990,11903299 +RI,under18,1990,225923 +RI,total,1990,1005995 +RI,total,1991,1010649 +RI,under18,1991,229448 +RI,total,1993,1015113 +RI,under18,1993,237218 +RI,under18,1992,232630 +RI,total,1992,1012581 +RI,under18,1994,239100 +RI,total,1994,1015960 +RI,total,1995,1017002 +RI,under18,1995,240553 +RI,under18,1996,240569 +RI,total,1996,1020893 +RI,under18,1998,241760 +RI,total,1998,1031155 +RI,total,1997,1025353 +RI,under18,1997,242079 +RI,total,2000,1050268 +RI,under18,2000,248065 +RI,total,1999,1040402 +RI,under18,1999,247014 +RI,total,2001,1057142 +RI,under18,2001,248296 +RI,total,2002,1065995 +RI,under18,2002,248690 +RI,total,2004,1074579 +RI,under18,2004,246228 +RI,total,2003,1071342 +RI,under18,2003,248075 +RI,total,2005,1067916 +RI,under18,2005,241932 +RI,total,2006,1063096 +RI,under18,2006,237348 +RI,total,2008,1055003 +RI,under18,2008,229798 +RI,total,2007,1057315 +RI,under18,2007,233655 +RI,under18,2013,213987 +RI,total,2013,1051511 +RI,total,2009,1053646 +RI,under18,2009,225902 +RI,total,2010,1052669 +RI,under18,2010,223088 +RI,under18,2011,219783 +RI,total,2011,1050350 +RI,under18,2012,216591 +RI,total,2012,1050304 +SC,total,2012,4723417 +SC,under18,2012,1077455 +SC,total,2011,4673509 +SC,under18,2011,1076524 +SC,under18,2010,1079978 +SC,total,2010,4636361 +SC,total,2009,4589872 +SC,under18,2009,1079729 +SC,total,2013,4774839 +SC,under18,2013,1079798 +SC,total,2007,4444110 +SC,under18,2007,1064190 +SC,total,2008,4528996 +SC,under18,2008,1074116 +SC,total,2006,4357847 +SC,under18,2006,1050042 +SC,total,2005,4270150 +SC,under18,2005,1036941 +SC,total,2003,4150297 +SC,under18,2003,1023785 +SC,total,2004,4210921 +SC,under18,2004,1029111 +SC,total,2002,4107795 +SC,under18,2002,1020531 +SC,total,2001,4064995 +SC,under18,2001,1016134 +SC,total,1999,3974682 +SC,under18,1999,1007050 +SC,total,2000,4024223 +SC,under18,2000,1010641 +SC,total,1997,3859696 +SC,under18,1997,1001681 +SC,under18,1998,1006371 +SC,total,1998,3919235 +SC,under18,1996,987576 +SC,total,1996,3796200 +SC,total,1995,3748582 +SC,under18,1995,975884 +SC,under18,1994,969766 +SC,total,1994,3705397 +SC,under18,1992,947868 +SC,total,1992,3620464 +SC,total,1993,3663314 +SC,under18,1993,956951 +SC,total,1991,3570404 +SC,under18,1991,936122 +SC,under18,1990,921041 +SC,total,1990,3501155 +SD,under18,1990,199453 +SD,total,1990,697101 +SD,total,1991,703669 +SD,under18,1991,201749 +SD,total,1993,722160 +SD,under18,1993,207975 +SD,under18,1992,206632 +SD,total,1992,712801 +SD,under18,1994,208443 +SD,total,1994,730790 +SD,total,1995,737926 +SD,under18,1995,207890 +SD,under18,1996,205780 +SD,total,1996,742214 +SD,under18,1998,204786 +SD,total,1998,746059 +SD,total,1997,744223 +SD,under18,1997,205978 +SD,total,2000,755844 +SD,under18,2000,202681 +SD,total,1999,750413 +SD,under18,1999,203737 +SD,total,2001,757972 +SD,under18,2001,200795 +SD,total,2002,760020 +SD,under18,2002,198694 +SD,total,2004,770396 +SD,under18,2004,196804 +SD,total,2003,763729 +SD,under18,2003,197326 +SD,total,2005,775493 +SD,under18,2005,196476 +SD,total,2006,783033 +SD,under18,2006,197332 +SD,total,2008,799124 +SD,under18,2008,199848 +SD,total,2007,791623 +SD,under18,2007,198847 +SD,under18,2013,207959 +SD,total,2013,844877 +SD,total,2009,807067 +SD,under18,2009,201204 +SD,total,2010,816211 +SD,under18,2010,203145 +SD,under18,2011,203948 +SD,total,2011,823772 +SD,under18,2012,205298 +SD,total,2012,834047 +TN,total,2012,6454914 +TN,under18,2012,1492689 +TN,total,2011,6398361 +TN,under18,2011,1491837 +TN,under18,2010,1495090 +TN,total,2010,6356683 +TN,total,2009,6306019 +TN,under18,2009,1494687 +TN,total,2013,6495978 +TN,under18,2013,1491577 +TN,total,2007,6175727 +TN,under18,2007,1482747 +TN,total,2008,6247411 +TN,under18,2008,1494354 +TN,total,2006,6088766 +TN,under18,2006,1470166 +TN,total,2005,5991057 +TN,under18,2005,1449326 +TN,total,2003,5847812 +TN,under18,2003,1424861 +TN,total,2004,5910809 +TN,under18,2004,1433343 +TN,total,2002,5795918 +TN,under18,2002,1414857 +TN,total,2001,5750789 +TN,under18,2001,1407578 +TN,total,1999,5638706 +TN,under18,1999,1385997 +TN,total,2000,5703719 +TN,under18,2000,1399685 +TN,total,1997,5499233 +TN,under18,1997,1359030 +TN,under18,1998,1369987 +TN,total,1998,5570045 +TN,under18,1996,1345723 +TN,total,1996,5416643 +TN,total,1995,5326936 +TN,under18,1995,1331616 +TN,under18,1994,1310988 +TN,total,1994,5231438 +TN,under18,1992,1259458 +TN,total,1992,5049742 +TN,total,1993,5137584 +TN,under18,1993,1285044 +TN,total,1991,4966587 +TN,under18,1991,1233260 +TN,under18,1990,1220200 +TN,total,1990,4894492 +TX,under18,1990,4906220 +TX,total,1990,17056755 +TX,total,1991,17398005 +TX,under18,1991,5000793 +TX,total,1993,18161612 +TX,under18,1993,5217899 +TX,under18,1992,5109805 +TX,total,1992,17759738 +TX,under18,1994,5331524 +TX,total,1994,18564062 +TX,total,1995,18958751 +TX,under18,1995,5421784 +TX,under18,1996,5551447 +TX,total,1996,19340342 +TX,under18,1998,5759054 +TX,total,1998,20157531 +TX,total,1997,19740317 +TX,under18,1997,5655482 +TX,total,2000,20944499 +TX,under18,2000,5906301 +TX,total,1999,20558220 +TX,under18,1999,5840211 +TX,total,2001,21319622 +TX,under18,2001,5980187 +TX,total,2002,21690325 +TX,under18,2002,6060372 +TX,total,2004,22394023 +TX,under18,2004,6208259 +TX,total,2003,22030931 +TX,under18,2003,6132980 +TX,total,2005,22778123 +TX,under18,2005,6290970 +TX,total,2006,23359580 +TX,under18,2006,6446798 +TX,total,2008,24309039 +TX,under18,2008,6675917 +TX,total,2007,23831983 +TX,under18,2007,6565872 +TX,under18,2013,7041986 +TX,total,2013,26448193 +TX,total,2009,24801761 +TX,under18,2009,6792907 +TX,total,2010,25245178 +TX,under18,2010,6879014 +TX,under18,2011,6931758 +TX,total,2011,25640909 +TX,under18,2012,6985807 +TX,total,2012,26060796 +UT,total,2012,2854871 +UT,under18,2012,888578 +UT,total,2011,2814784 +UT,under18,2011,881350 +UT,under18,2010,873019 +UT,total,2010,2774424 +UT,total,2009,2723421 +UT,under18,2009,857853 +UT,total,2013,2900872 +UT,under18,2013,896589 +UT,total,2007,2597746 +UT,under18,2007,815496 +UT,total,2008,2663029 +UT,under18,2008,837258 +UT,total,2006,2525507 +UT,under18,2006,789957 +UT,total,2005,2457719 +UT,under18,2005,767888 +UT,total,2003,2360137 +UT,under18,2003,740483 +UT,total,2004,2401580 +UT,under18,2004,751771 +UT,total,2002,2324815 +UT,under18,2002,733517 +UT,total,2001,2283715 +UT,under18,2001,726819 +UT,total,1999,2203482 +UT,under18,1999,715398 +UT,total,2000,2244502 +UT,under18,2000,721686 +UT,total,1997,2119784 +UT,under18,1997,699528 +UT,under18,1998,709386 +UT,total,1998,2165961 +UT,under18,1996,687078 +UT,total,1996,2067976 +UT,total,1995,2014179 +UT,under18,1995,679636 +UT,under18,1994,673935 +UT,total,1994,1960446 +UT,under18,1992,648725 +UT,total,1992,1836799 +UT,total,1993,1898404 +UT,under18,1993,662968 +UT,total,1991,1779780 +UT,under18,1991,637216 +UT,under18,1990,627122 +UT,total,1990,1731223 +VT,under18,1990,143296 +VT,total,1990,564798 +VT,total,1991,568606 +VT,under18,1991,145219 +VT,total,1993,577748 +VT,under18,1993,148705 +VT,under18,1992,146983 +VT,total,1992,572751 +VT,under18,1994,150794 +VT,total,1994,583836 +VT,total,1995,589003 +VT,under18,1995,151439 +VT,under18,1996,151490 +VT,total,1996,593701 +VT,under18,1998,148467 +VT,total,1998,600416 +VT,total,1997,597239 +VT,under18,1997,150040 +VT,total,2000,609618 +VT,under18,2000,147549 +VT,total,1999,604683 +VT,under18,1999,147859 +VT,total,2001,612223 +VT,under18,2001,146040 +VT,total,2002,615442 +VT,under18,2002,144441 +VT,total,2004,619920 +VT,under18,2004,141068 +VT,total,2003,617858 +VT,under18,2003,142718 +VT,total,2005,621215 +VT,under18,2005,138933 +VT,total,2006,622892 +VT,under18,2006,136731 +VT,total,2008,624151 +VT,under18,2008,132600 +VT,total,2007,623481 +VT,under18,2007,134695 +VT,under18,2013,122701 +VT,total,2013,626630 +VT,total,2009,624817 +VT,under18,2009,130450 +VT,total,2010,625793 +VT,under18,2010,128601 +VT,under18,2011,126500 +VT,total,2011,626320 +VT,under18,2012,124555 +VT,total,2012,625953 +VA,total,2012,8186628 +VA,under18,2012,1861323 +VA,total,2011,8105850 +VA,under18,2011,1857585 +VA,under18,2010,1855025 +VA,total,2010,8024417 +VA,total,2009,7925937 +VA,under18,2009,1845132 +VA,total,2013,8260405 +VA,under18,2013,1864535 +VA,total,2007,7751000 +VA,under18,2007,1834386 +VA,total,2008,7833496 +VA,under18,2008,1838361 +VA,total,2005,7577105 +VA,under18,2005,1816270 +VA,total,2006,7673725 +VA,under18,2006,1826368 +VA,total,2003,7366977 +VA,under18,2003,1782254 +VA,total,2004,7475575 +VA,under18,2004,1801958 +VA,total,2002,7286873 +VA,under18,2002,1771247 +VA,total,2001,7198362 +VA,under18,2001,1754549 +VA,total,1999,7000174 +VA,under18,1999,1723125 +VA,total,2000,7105817 +VA,under18,2000,1741420 +VA,total,1997,6829183 +VA,under18,1997,1683766 +VA,under18,1998,1706261 +VA,total,1998,6900918 +VA,under18,1996,1664147 +VA,total,1996,6750884 +VA,total,1995,6670693 +VA,under18,1995,1649005 +VA,under18,1994,1628711 +VA,total,1994,6593139 +VA,under18,1992,1581544 +VA,total,1992,6414307 +VA,total,1993,6509630 +VA,under18,1993,1604758 +VA,total,1991,6301217 +VA,under18,1991,1548258 +VA,under18,1990,1520670 +VA,total,1990,6216884 +WA,under18,1990,1301545 +WA,total,1990,4903043 +WA,total,1991,5025624 +WA,under18,1991,1326527 +WA,total,1993,5278842 +WA,under18,1993,1387716 +WA,under18,1992,1365480 +WA,total,1992,5160757 +WA,under18,1994,1409922 +WA,total,1994,5375161 +WA,total,1995,5481027 +WA,under18,1995,1429397 +WA,under18,1996,1449613 +WA,total,1996,5569753 +WA,under18,1998,1494784 +WA,total,1998,5769562 +WA,total,1997,5674747 +WA,under18,1997,1473646 +WA,total,2000,5910512 +WA,under18,2000,1516361 +WA,total,1999,5842564 +WA,under18,1999,1507824 +WA,total,2001,5985722 +WA,under18,2001,1517527 +WA,total,2002,6052349 +WA,under18,2002,1517655 +WA,total,2004,6178645 +WA,under18,2004,1520751 +WA,total,2003,6104115 +WA,under18,2003,1514877 +WA,total,2005,6257305 +WA,under18,2005,1523890 +WA,total,2006,6370753 +WA,under18,2006,1536926 +WA,total,2008,6562231 +WA,under18,2008,1560302 +WA,total,2007,6461587 +WA,under18,2007,1549582 +WA,under18,2013,1595795 +WA,total,2013,6971406 +WA,total,2009,6667426 +WA,under18,2009,1574403 +WA,total,2010,6742256 +WA,under18,2010,1581436 +WA,under18,2011,1584709 +WA,total,2011,6821481 +WA,under18,2012,1588451 +WA,total,2012,6895318 +WV,total,2012,1856680 +WV,under18,2012,384030 +WV,total,2011,1855184 +WV,under18,2011,385283 +WV,under18,2010,387224 +WV,total,2010,1854146 +WV,total,2009,1847775 +WV,under18,2009,389036 +WV,total,2013,1854304 +WV,under18,2013,381678 +WV,total,2007,1834052 +WV,under18,2007,390661 +WV,total,2008,1840310 +WV,under18,2008,390210 +WV,total,2006,1827912 +WV,under18,2006,390637 +WV,total,2005,1820492 +WV,under18,2005,390431 +WV,total,2003,1812295 +WV,under18,2003,392460 +WV,total,2004,1816438 +WV,under18,2004,391856 +WV,total,2002,1805414 +WV,under18,2002,393569 +WV,total,2001,1801481 +WV,under18,2001,395307 +WV,total,1999,1811799 +WV,under18,1999,406784 +WV,total,2000,1807021 +WV,under18,2000,401062 +WV,total,1997,1819113 +WV,under18,1997,418037 +WV,under18,1998,412793 +WV,total,1998,1815609 +WV,under18,1996,422831 +WV,total,1996,1822808 +WV,total,1995,1823700 +WV,under18,1995,428790 +WV,under18,1994,429128 +WV,total,1994,1820421 +WV,under18,1992,433116 +WV,total,1992,1806451 +WV,total,1993,1817539 +WV,under18,1993,432364 +WV,total,1991,1798735 +WV,under18,1991,433918 +WV,under18,1990,436797 +WV,total,1990,1792548 +WI,under18,1990,1302869 +WI,total,1990,4904562 +WI,total,1991,4964343 +WI,under18,1991,1314855 +WI,total,1993,5084889 +WI,under18,1993,1337334 +WI,under18,1992,1330555 +WI,total,1992,5025398 +WI,under18,1994,1348110 +WI,total,1994,5133678 +WI,total,1995,5184836 +WI,under18,1995,1351343 +WI,under18,1996,1352877 +WI,total,1996,5229986 +WI,under18,1998,1362907 +WI,total,1998,5297673 +WI,total,1997,5266213 +WI,under18,1997,1359712 +WI,total,1999,5332666 +WI,under18,1999,1367019 +WI,total,2000,5373999 +WI,under18,2000,1370440 +WI,total,2001,5406835 +WI,under18,2001,1367593 +WI,total,2002,5445162 +WI,under18,2002,1365315 +WI,total,2004,5514026 +WI,under18,2004,1354643 +WI,total,2003,5479203 +WI,under18,2003,1358505 +WI,total,2005,5546166 +WI,under18,2005,1349866 +WI,total,2006,5577655 +WI,under18,2006,1348785 +WI,total,2008,5640996 +WI,under18,2008,1345573 +WI,total,2007,5610775 +WI,under18,2007,1348901 +WI,under18,2013,1307776 +WI,total,2013,5742713 +WI,total,2009,5669264 +WI,under18,2009,1342411 +WI,total,2010,5689060 +WI,under18,2010,1336094 +WI,under18,2011,1325870 +WI,total,2011,5708785 +WI,under18,2012,1316113 +WI,total,2012,5724554 +WY,total,2012,576626 +WY,under18,2012,136526 +WY,total,2011,567329 +WY,under18,2011,135407 +WY,under18,2010,135351 +WY,total,2010,564222 +WY,total,2009,559851 +WY,under18,2009,134960 +WY,total,2013,582658 +WY,under18,2013,137679 +WY,total,2007,534876 +WY,under18,2007,128760 +WY,total,2008,546043 +WY,under18,2008,131511 +WY,total,2006,522667 +WY,under18,2006,125525 +WY,total,2005,514157 +WY,under18,2005,124022 +WY,total,2003,503453 +WY,under18,2003,124182 +WY,total,2004,509106 +WY,under18,2004,123974 +WY,total,2002,500017 +WY,under18,2002,125495 +WY,total,2001,494657 +WY,under18,2001,126212 +WY,total,2000,494300 +WY,under18,2000,128774 +WY,total,1999,491780 +WY,under18,1999,130793 +WY,total,1997,489452 +WY,under18,1997,134328 +WY,under18,1998,132602 +WY,total,1998,490787 +WY,under18,1996,135698 +WY,total,1996,488167 +WY,total,1995,485160 +WY,under18,1995,136785 +WY,under18,1994,137733 +WY,total,1994,480283 +WY,under18,1992,137308 +WY,total,1992,466251 +WY,total,1993,473081 +WY,under18,1993,137458 +WY,total,1991,459260 +WY,under18,1991,136720 +WY,under18,1990,136078 +WY,total,1990,453690 +PR,under18,1990,NaN +PR,total,1990,NaN +PR,total,1991,NaN +PR,under18,1991,NaN +PR,total,1993,NaN +PR,under18,1993,NaN +PR,under18,1992,NaN +PR,total,1992,NaN +PR,under18,1994,NaN +PR,total,1994,NaN +PR,total,1995,NaN +PR,under18,1995,NaN +PR,under18,1996,NaN +PR,total,1996,NaN +PR,under18,1998,NaN +PR,total,1998,NaN +PR,total,1997,NaN +PR,under18,1997,NaN +PR,total,1999,NaN +PR,under18,1999,NaN +PR,total,2000,3810605 +PR,under18,2000,1089063 +PR,total,2001,3818774 +PR,under18,2001,1077566 +PR,total,2002,3823701 +PR,under18,2002,1065051 +PR,total,2004,3826878 +PR,under18,2004,1035919 +PR,total,2003,3826095 +PR,under18,2003,1050615 +PR,total,2005,3821362 +PR,under18,2005,1019447 +PR,total,2006,3805214 +PR,under18,2006,998543 +PR,total,2007,3782995 +PR,under18,2007,973613 +PR,total,2008,3760866 +PR,under18,2008,945705 +PR,under18,2013,814068 +PR,total,2013,3615086 +PR,total,2009,3740410 +PR,under18,2009,920794 +PR,total,2010,3721208 +PR,under18,2010,896945 +PR,under18,2011,869327 +PR,total,2011,3686580 +PR,under18,2012,841740 +PR,total,2012,3651545 +USA,under18,1990,64218512 +USA,total,1990,249622814 +USA,total,1991,252980942 +USA,under18,1991,65313018 +USA,under18,1992,66509177 +USA,total,1992,256514231 +USA,total,1993,259918595 +USA,under18,1993,67594938 +USA,under18,1994,68640936 +USA,total,1994,263125826 +USA,under18,1995,69473140 +USA,under18,1996,70233512 +USA,total,1995,266278403 +USA,total,1996,269394291 +USA,total,1997,272646932 +USA,under18,1997,70920738 +USA,under18,1998,71431406 +USA,total,1998,275854116 +USA,under18,1999,71946051 +USA,total,2000,282162411 +USA,under18,2000,72376189 +USA,total,1999,279040181 +USA,total,2001,284968955 +USA,under18,2001,72671175 +USA,total,2002,287625193 +USA,under18,2002,72936457 +USA,total,2003,290107933 +USA,under18,2003,73100758 +USA,total,2004,292805298 +USA,under18,2004,73297735 +USA,total,2005,295516599 +USA,under18,2005,73523669 +USA,total,2006,298379912 +USA,under18,2006,73757714 +USA,total,2007,301231207 +USA,under18,2007,74019405 +USA,total,2008,304093966 +USA,under18,2008,74104602 +USA,under18,2013,73585872 +USA,total,2013,316128839 +USA,total,2009,306771529 +USA,under18,2009,74134167 +USA,under18,2010,74119556 +USA,total,2010,309326295 +USA,under18,2011,73902222 +USA,total,2011,311582564 +USA,under18,2012,73708179 +USA,total,2012,313873685 diff --git a/Day91-100/Django知识点概述.md b/Day91-100/Django知识点概述.md index 4ae84e5..e1a34e2 100644 --- a/Day91-100/Django知识点概述.md +++ b/Day91-100/Django知识点概述.md @@ -1,5 +1,7 @@ ## Django知识点概述 +> 说明:本文的部分插图来自于《Python项目开发实战》和《精通Django》,这两本书中都包含了对Django框架精彩的讲解,有兴趣的读者可以自行购买阅读。 + ### Web应用 问题1:描述一个Web应用的工作流程。 diff --git a/Day91-100/关于测试.md b/Day91-100/关于测试和自动化测试.md similarity index 100% rename from Day91-100/关于测试.md rename to Day91-100/关于测试和自动化测试.md diff --git a/Day91-100/网络API接口设计.md b/Day91-100/网络API接口设计.md index e83a568..df05a3f 100644 --- a/Day91-100/网络API接口设计.md +++ b/Day91-100/网络API接口设计.md @@ -46,7 +46,7 @@ API接口返回的数据通常都是JSON或XML格式,我们这里不讨论后 | 10003 | 评论已被删除 | 查看评论时评论因不和谐因素已被删除 | | 10004 | …… | …… | -1. **GET** `/comments/{article-id}` +1. **GET** `/articles/{article-id}/comments/` 开发者:王大锤 @@ -95,7 +95,7 @@ API接口返回的数据通常都是JSON或XML格式,我们这里不讨论后 } ``` -2. **POST** `/comments/{article-id}` +2. **POST** `/articles/{article-id}/comments` 开发者:王大锤 diff --git a/Python惯例.md b/Python惯例.md index df875fa..54b0256 100644 --- a/Python惯例.md +++ b/Python惯例.md @@ -5,7 +5,6 @@ 1. 让代码既可以被导入又可以被执行。 ```Python - if __name__ == '__main__': ``` @@ -13,7 +12,6 @@ 2. 用下面的方式判断逻辑“真”或“假”。 ```Python - if x: if not x: ``` @@ -21,7 +19,6 @@ **好**的代码: ```Python - name = 'jackfrued' fruits = ['apple', 'orange', 'grape'] owners = {'1001': '骆昊', '1002': '王大锤'} @@ -32,7 +29,6 @@ **不好**的代码: ```Python - name = 'jackfrued' fruits = ['apple', 'orange', 'grape'] owners = {'1001': '骆昊', '1002': '王大锤'} @@ -43,7 +39,6 @@ 3. 善于使用in运算符。 ```Python - if x in items: # 包含 for x in items: # 迭代 ``` @@ -51,7 +46,6 @@ **好**的代码: ```Python - name = 'Hao LUO' if 'L' in name: print('The name has an L in it.') @@ -60,7 +54,6 @@ **不好**的代码: ```Python - name = 'Hao LUO' if name.find('L') != -1: print('This name has an L in it!') @@ -69,7 +62,6 @@ 4. 不使用临时变量交换两个值。 ```Python - a, b = b, a ``` @@ -78,7 +70,6 @@ **好**的代码: ```Python - chars = ['j', 'a', 'c', 'k', 'f', 'r', 'u', 'e', 'd'] name = ''.join(chars) print(name) # jackfrued @@ -87,7 +78,6 @@ **不好**的代码: ```Python - chars = ['j', 'a', 'c', 'k', 'f', 'r', 'u', 'e', 'd'] name = '' for char in chars: @@ -104,7 +94,6 @@ **好**的代码: ```Python - d = {'x': '5'} try: value = int(d['x']) @@ -116,7 +105,6 @@ **不好**的代码: ```Python - d = {'x': '5'} if 'x' in d and isinstance(d['x'], str) \ and d['x'].isdigit(): @@ -131,7 +119,6 @@ **好**的代码: ```Python - fruits = ['orange', 'grape', 'pitaya', 'blueberry'] for index, fruit in enumerate(fruits): print(index, ':', fruit) @@ -140,7 +127,6 @@ **不好**的代码: ```Python - fruits = ['orange', 'grape', 'pitaya', 'blueberry'] index = 0 for fruit in fruits: @@ -153,7 +139,6 @@ **好**的代码: ```Python - data = [7, 20, 3, 15, 11] result = [num * 3 for num in data if num > 10] print(result) # [60, 45, 33] @@ -162,7 +147,6 @@ **不好**的代码: ```Python - data = [7, 20, 3, 15, 11] result = [] for i in data: @@ -176,7 +160,6 @@ **好**的代码: ```Python - keys = ['1001', '1002', '1003'] values = ['骆昊', '王大锤', '白元芳'] d = dict(zip(keys, values)) @@ -186,7 +169,6 @@ **不好**的代码: ```Python - keys = ['1001', '1002', '1003'] values = ['骆昊', '王大锤', '白元芳'] d = {} diff --git a/README.md b/README.md index 68be96b..4322658 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,10 @@ ## Python - 100天从新手到大师 > 作者:骆昊 +> +> 说明:最近有很多想学习Python的小伙伴申请单独加我微信和QQ,因为我自己平时也很忙,没办法一一解答大家的问题,我创建了**Python100天学习交流1群**和**Python100天学习交流2群**两个交流群,群号分别为**680701107**和**213132758**,二维码在下方。我的同事和朋友很多也在这个群里,他们都是优秀的Python开发者,有丰富的商业项目经验,我们在时间充足的时候会及时解答大家的问题,而且从Python语言入门到Web应用开发,从数据分析到机器学习,每个领域都有技术大咖为大家解惑答疑。以后我们争取每周做一次视频直播,以专题的形式分享Python开发的点点滴滴,同时还会不定期的举办线上和线下的技术交流和分享活动,小伙伴们可以加群进行交流。感谢**千锋教育Python教学部**对本群的支持。 + +![](./res/python_100_days_qq_group.png) ### Python应用领域和就业形势分析 @@ -35,7 +39,7 @@ ![](./res/python-bj-salary.png) -![](./res/python-cd-salary.png) +![](./res/python-salary-chengdu.png) 给初学者的几个建议: @@ -242,33 +246,78 @@ #### Day44 - [表单的应用](./Day41-55/04.表单的应用.md) +- 表单和表单控件 +- 跨站请求伪造和CSRF令牌 +- Form和ModelForm +- 表单验证 + #### Day45 - [Cookie和Session](./Day41-55/05.Cookie和Session.md) +- 实现用户跟踪 +- cookie和session的关系 +- Django框架对session的支持 +- 视图函数中的cookie读写操作 + #### Day46 - [中间件的应用](./Day41-55/06.中间件的应用.md) -#### Day47 - [日志和缓存](./Day41-55/07.日志和缓存.md) +- 什么是中间件 +- Django框架内置的中间件 +- 自定义中间件及其应用场景 + +#### Day47 - [日志和调试](./Day41-55/07.日志和调试.md) + +- 配置日志 +- 配置和使用Django-Debug-Toolbar #### Day48 - [文件上传和富文本编辑](./Day41-55/08.文件上传.md) +- 文件上传表单控件和图片文件预览 +- 服务器端如何处理上传的文件 +- 富文本编辑器概述 +- wangEditor的使用 + #### Day49 - [文件下载和报表](./Day41-55/09.文件下载和报表.md) +- 通过HttpResponse修改响应头 +- 使用StreamingHttpResponse处理大文件 +- 使用xlwt生成Excel报表 +- 使用reportlab生成PDF报表 +- 使用ECharts生成前端图表 + #### Day50 - [RESTful架构和DRF入门](./Day41-55/10.RESTful架构和DRF入门.md) #### Day51 - [RESTful架构和DRF进阶](./Day41-55/11.RESTful架构和DRF进阶.md) #### Day52 - [使用缓存](./Day41-55/12.使用缓存.md) +- 网站优化第一定律 + +- 在Django项目中使用Redis提供缓存服务 +- 在视图函数中读写缓存 +- 使用装饰器实现页面缓存 +- 为数据接口提供缓存服务 + #### Day53 - [短信和邮件](./Day41-55/13.短信和邮件.md) +- 常用短信网关平台介绍 +- 使用螺丝帽发送短信 +- Django框架对邮件服务的支持 + #### Day54 - [异步任务和定时任务](./Day41-55/14.异步任务和定时任务.md) +- 网站优化第二定律 +- 配置消息队列服务 +- 在项目中使用celery实现任务异步化 +- 在项目中使用celery实现定时任务 + #### Day55 - [单元测试和项目上线](./Day41-55/15.单元测试和项目上线.md) -- 项目开发流程和相关工具 -- 生成非HTML内容 -- 项目部署和测试 -- 项目性能初步调优 -- Web应用安全保护 +- Python中的单元测试 +- Django框架对单元测试的支持 +- 使用版本控制系统 +- 配置和使用uWSGI +- 动静分离和Nginx配置 +- 配置HTTPS ### Day56~60 - [实战Flask](./Day56-65) @@ -395,15 +444,15 @@ > - **客户合作** 高于 合同谈判 > - **响应变化** 高于 遵循计划 - ![](./res/the-daily-scrum-in-the-sprint-cycle.png) + ![](./res/agile-scrum-sprint-cycle.png) - > 角色:产品所有者(决定做什么,能对需求拍板的人)、团队负责人(解决各种问题,专注如何更好的工作,屏蔽外部对开发团队的影响)、开发团队(项目执行人员,具体指开发人员和测试人员)。 - > - > 准备工作:商业案例和资金、合同、憧憬、初始产品需求、初始发布计划、入股、组建团队。 - > - > 敏捷团队通常人数为8-10人。 - > - > 工作量估算:将开发任务量化,包括原型、Logo设计、UI设计、前端开发等,尽量把每个工作分解到最小任务量,最小任务量标准为工作时间不能超过两天,然后估算总体项目时间。把每个任务都贴在白板上面,白板上分三部分:to do(待完成)、in progress(进行中)和done(已完成)。 + > 角色:产品所有者(决定做什么,能对需求拍板的人)、团队负责人(解决各种问题,专注如何更好的工作,屏蔽外部对开发团队的影响)、开发团队(项目执行人员,具体指开发人员和测试人员)。 + + > 准备工作:商业案例和资金、合同、憧憬、初始产品需求、初始发布计划、入股、组建团队。 + + > 敏捷团队通常人数为8-10人。 + + > 工作量估算:将开发任务量化,包括原型、Logo设计、UI设计、前端开发等,尽量把每个工作分解到最小任务量,最小任务量标准为工作时间不能超过两天,然后估算总体项目时间。把每个任务都贴在白板上面,白板上分三部分:to do(待完成)、in progress(进行中)和done(已完成)。 2. 项目团队组建 @@ -587,6 +636,4 @@ - 云存储 - CDN - - > 致谢:感谢的我的同事古晔、张旭、肖世荣、王海飞、荣佳伟、路丰坤等在技术上给予的指导和帮助。 \ No newline at end of file diff --git a/res/01.django_single_server.png b/res/01.django_single_server.png deleted file mode 100644 index 70d3bf3..0000000 Binary files a/res/01.django_single_server.png and /dev/null differ diff --git a/res/02.django_dedicated_db_server.png b/res/02.django_dedicated_db_server.png deleted file mode 100644 index 143eb6e..0000000 Binary files a/res/02.django_dedicated_db_server.png and /dev/null differ diff --git a/res/03.django_dedicated_static_server.png b/res/03.django_dedicated_static_server.png deleted file mode 100644 index f13a247..0000000 Binary files a/res/03.django_dedicated_static_server.png and /dev/null differ diff --git a/res/04.django_load_balance.png b/res/04.django_load_balance.png deleted file mode 100644 index 16e7515..0000000 Binary files a/res/04.django_load_balance.png and /dev/null differ diff --git a/res/05.django_massive_cluster.png b/res/05.django_massive_cluster.png deleted file mode 100644 index 9163fb2..0000000 Binary files a/res/05.django_massive_cluster.png and /dev/null differ diff --git a/res/Celery_RabitMQ.png b/res/Celery_RabitMQ.png deleted file mode 100644 index 4140130..0000000 Binary files a/res/Celery_RabitMQ.png and /dev/null differ diff --git a/res/Producer-Broker-Consumer-Arrangement.png b/res/Producer-Broker-Consumer-Arrangement.png deleted file mode 100644 index b073a60..0000000 Binary files a/res/Producer-Broker-Consumer-Arrangement.png and /dev/null differ diff --git a/res/abstraction-view.png b/res/abstraction-view.png deleted file mode 100644 index 39ca0a5..0000000 Binary files a/res/abstraction-view.png and /dev/null differ diff --git a/res/the-daily-scrum-in-the-sprint-cycle.png b/res/agile-scrum-sprint-cycle.png similarity index 100% rename from res/the-daily-scrum-in-the-sprint-cycle.png rename to res/agile-scrum-sprint-cycle.png diff --git a/res/algorithm_complexity_1.png b/res/algorithm_complexity_1.png deleted file mode 100644 index 952889d..0000000 Binary files a/res/algorithm_complexity_1.png and /dev/null differ diff --git a/res/algorithm_complexity_2.png b/res/algorithm_complexity_2.png deleted file mode 100644 index 4c14249..0000000 Binary files a/res/algorithm_complexity_2.png and /dev/null differ diff --git a/res/alipay_web_developer.png b/res/alipay_web_developer.png deleted file mode 100644 index 0716552..0000000 Binary files a/res/alipay_web_developer.png and /dev/null differ diff --git a/res/aliyun-certificate.png b/res/aliyun-certificate.png deleted file mode 100644 index c19a30b..0000000 Binary files a/res/aliyun-certificate.png and /dev/null differ diff --git a/res/aliyun-dnslist.png b/res/aliyun-dnslist.png deleted file mode 100644 index e6eda2f..0000000 Binary files a/res/aliyun-dnslist.png and /dev/null differ diff --git a/res/aliyun-domain.png b/res/aliyun-domain.png deleted file mode 100644 index 64a1f48..0000000 Binary files a/res/aliyun-domain.png and /dev/null differ diff --git a/res/aliyun-keeprecord.png b/res/aliyun-keeprecord.png deleted file mode 100644 index d9d39bc..0000000 Binary files a/res/aliyun-keeprecord.png and /dev/null differ diff --git a/res/aliyun-resolve-settings.png b/res/aliyun-resolve-settings.png deleted file mode 100644 index 3f9363a..0000000 Binary files a/res/aliyun-resolve-settings.png and /dev/null differ diff --git a/res/app_folder_arch.png b/res/app_folder_arch.png deleted file mode 100644 index 7d51e95..0000000 Binary files a/res/app_folder_arch.png and /dev/null differ diff --git a/res/builtin-middlewares.png b/res/builtin-middlewares.png deleted file mode 100644 index 59acb4b..0000000 Binary files a/res/builtin-middlewares.png and /dev/null differ diff --git a/res/celery.png b/res/celery.png deleted file mode 100644 index a8d5f7d..0000000 Binary files a/res/celery.png and /dev/null differ diff --git a/res/celery_architecture.png b/res/celery_architecture.png deleted file mode 100644 index d3118a0..0000000 Binary files a/res/celery_architecture.png and /dev/null differ diff --git a/res/class-and-object.png b/res/class-and-object.png deleted file mode 100644 index fa0f995..0000000 Binary files a/res/class-and-object.png and /dev/null differ diff --git a/res/click-jacking.png b/res/click-jacking.png deleted file mode 100644 index 9d92979..0000000 Binary files a/res/click-jacking.png and /dev/null differ diff --git a/res/concurrency.png b/res/concurrency.png deleted file mode 100644 index 3e47d97..0000000 Binary files a/res/concurrency.png and /dev/null differ diff --git a/res/deployment_pipelines.png b/res/deployment_pipelines.png deleted file mode 100644 index 6db6c2d..0000000 Binary files a/res/deployment_pipelines.png and /dev/null differ diff --git a/res/django-middleware.png b/res/django-middleware.png deleted file mode 100644 index 9885582..0000000 Binary files a/res/django-middleware.png and /dev/null differ diff --git a/res/django-mtv.png b/res/django-mtv.png deleted file mode 100644 index 76f330e..0000000 Binary files a/res/django-mtv.png and /dev/null differ diff --git a/res/django_request_response_cycle.png b/res/django_request_response_cycle.png deleted file mode 100644 index 3423c9a..0000000 Binary files a/res/django_request_response_cycle.png and /dev/null differ diff --git a/res/docker_logo.png b/res/docker_logo.png deleted file mode 100644 index 19ff797..0000000 Binary files a/res/docker_logo.png and /dev/null differ diff --git a/res/docker_vs_vm.png b/res/docker_vs_vm.png deleted file mode 100644 index 0eb6fea..0000000 Binary files a/res/docker_vs_vm.png and /dev/null differ diff --git a/res/encapsulation.png b/res/encapsulation.png deleted file mode 100644 index 437df0a..0000000 Binary files a/res/encapsulation.png and /dev/null differ diff --git a/res/er-graph.png b/res/er-graph.png deleted file mode 100644 index c8415be..0000000 Binary files a/res/er-graph.png and /dev/null differ diff --git a/res/git_logo.png b/res/git_logo.png deleted file mode 100644 index 04b0f00..0000000 Binary files a/res/git_logo.png and /dev/null differ diff --git a/res/git_repository.png b/res/git_repository.png deleted file mode 100644 index d85bdbd..0000000 Binary files a/res/git_repository.png and /dev/null differ diff --git a/res/gitignore_io.png b/res/gitignore_io.png deleted file mode 100644 index a305da6..0000000 Binary files a/res/gitignore_io.png and /dev/null differ diff --git a/res/greedy.png b/res/greedy.png deleted file mode 100644 index 376ceef..0000000 Binary files a/res/greedy.png and /dev/null differ diff --git a/res/http-request.png b/res/http-request.png deleted file mode 100644 index aca9287..0000000 Binary files a/res/http-request.png and /dev/null differ diff --git a/res/http-response.png b/res/http-response.png deleted file mode 100644 index f2b8ae3..0000000 Binary files a/res/http-response.png and /dev/null differ diff --git a/res/jenkins_new_project.png b/res/jenkins_new_project.png deleted file mode 100644 index 8019ada..0000000 Binary files a/res/jenkins_new_project.png and /dev/null differ diff --git a/res/modularity.png b/res/modularity.png deleted file mode 100644 index 25a6696..0000000 Binary files a/res/modularity.png and /dev/null differ diff --git a/res/multi-inheritance.png b/res/multi-inheritance.png deleted file mode 100644 index c2ae49b..0000000 Binary files a/res/multi-inheritance.png and /dev/null differ diff --git a/res/mvc.png b/res/mvc.png deleted file mode 100644 index 7ba14ba..0000000 Binary files a/res/mvc.png and /dev/null differ diff --git a/res/oauth2.png b/res/oauth2.png deleted file mode 100644 index 7a07bd3..0000000 Binary files a/res/oauth2.png and /dev/null differ diff --git a/res/object-roles.png b/res/object-roles.png deleted file mode 100644 index 41174cd..0000000 Binary files a/res/object-roles.png and /dev/null differ diff --git a/res/objects-collaborate.png b/res/objects-collaborate.png deleted file mode 100644 index bae06e8..0000000 Binary files a/res/objects-collaborate.png and /dev/null differ diff --git a/res/objects-lifetime.png b/res/objects-lifetime.png deleted file mode 100644 index 54207bb..0000000 Binary files a/res/objects-lifetime.png and /dev/null differ diff --git a/res/python-cd-salary.png b/res/python-cd-salary.png deleted file mode 100644 index f728255..0000000 Binary files a/res/python-cd-salary.png and /dev/null differ diff --git a/res/python-salary-hangzhou.png b/res/python-salary-hangzhou.png deleted file mode 100644 index fc901aa..0000000 Binary files a/res/python-salary-hangzhou.png and /dev/null differ diff --git a/res/python-salary-shanghai.png b/res/python-salary-shanghai.png deleted file mode 100644 index 9402051..0000000 Binary files a/res/python-salary-shanghai.png and /dev/null differ diff --git a/res/python-salary-shenzhen.png b/res/python-salary-shenzhen.png deleted file mode 100644 index 07b6f20..0000000 Binary files a/res/python-salary-shenzhen.png and /dev/null differ diff --git a/res/python-str-join.png b/res/python-str-join.png deleted file mode 100644 index b784ffb..0000000 Binary files a/res/python-str-join.png and /dev/null differ diff --git a/res/python_100_days_qq_group.png b/res/python_100_days_qq_group.png new file mode 100644 index 0000000..b858c8e Binary files /dev/null and b/res/python_100_days_qq_group.png differ diff --git a/res/python_salary_guangzhou.png b/res/python_salary_guangzhou.png deleted file mode 100644 index e7567e3..0000000 Binary files a/res/python_salary_guangzhou.png and /dev/null differ diff --git a/res/redmine_new_issue.png b/res/redmine_new_issue.png deleted file mode 100644 index 63971fc..0000000 Binary files a/res/redmine_new_issue.png and /dev/null differ diff --git a/res/selenium-ide.png b/res/selenium-ide.png deleted file mode 100644 index 52a4a4f..0000000 Binary files a/res/selenium-ide.png and /dev/null differ diff --git a/res/selenium_ide.png b/res/selenium_ide.png deleted file mode 100644 index 4d2f275..0000000 Binary files a/res/selenium_ide.png and /dev/null differ diff --git a/res/shopping-pdm.png b/res/shopping-pdm.png deleted file mode 100644 index 2b93a21..0000000 Binary files a/res/shopping-pdm.png and /dev/null differ diff --git a/res/uml-graph.png b/res/uml-graph.png deleted file mode 100644 index def109b..0000000 Binary files a/res/uml-graph.png and /dev/null differ diff --git a/res/uml.png b/res/uml.png deleted file mode 100644 index 98168cb..0000000 Binary files a/res/uml.png and /dev/null differ diff --git a/res/web-application.png b/res/web-application.png deleted file mode 100644 index 89d2dec..0000000 Binary files a/res/web-application.png and /dev/null differ diff --git a/res/web-queue-worker-physical.png b/res/web-queue-worker-physical.png deleted file mode 100644 index 81da48d..0000000 Binary files a/res/web-queue-worker-physical.png and /dev/null differ diff --git a/用函数还是用复杂的表达式.md b/用函数还是用复杂的表达式.md index b84d8cf..ebf10eb 100644 --- a/用函数还是用复杂的表达式.md +++ b/用函数还是用复杂的表达式.md @@ -15,7 +15,6 @@ else: if c > the_max: the_max = c print('The max is:', the_max) - ``` 但是我们刚才说了,程序员都是懒惰的,很多程序员都会使用三元条件运算符来改写上面的代码。 @@ -27,7 +26,6 @@ c = int(input('c = ')) the_max = a if a > b else b the_max = c if c > the_max else the_max print('The max is:', the_max) - ``` 需要说明的是,Python在2.5版本以前是没有上面代码第4行和第5行中使用的三元条件运算符的,究其原因是Guido van Rossum(Python之父)认为三元条件运算符并不能帮助 Python变得更加简洁,于是那些习惯了在C/C++或Java中使用三元条件运算符(在这些语言中,三元条件运算符也称为“Elvis运算符”,因为`?:`放在一起很像著名摇滚歌手猫王Elvis的大背头)的程序员试着用`and`和`or`运算符的短路特性来模拟出三元操作符,于是在那个年代,上面的代码是这样写的。 @@ -39,7 +37,6 @@ c = int(input('c = ')) the_max = a > b and a or b the_max = c > the_max and c or the_max print('The max is:', the_max) - ``` 但是这种做法在某些场景下是不能成立的,且看下面的代码。 @@ -60,7 +57,6 @@ a = int(input('a = ')) b = int(input('b = ')) c = int(input('c = ')) print('The max is:', (a if a > b else b) if (a if a > b else b) > c else c) - ``` 但是,这样做真的好吗?如此复杂的表达式是不是让代码变得晦涩了很多呢?我们发现,在实际开发中很多开发者都喜欢过度的使用某种语言的特性或语法糖,于是简单的多行代码变成了复杂的单行表达式,这样做真的好吗?这个问题我也不止一次的问过自己,现在我能给出的答案是下面的代码,使用辅助函数。 @@ -74,7 +70,6 @@ a = int(input('a = ')) b = int(input('b = ')) c = int(input('c = ')) print('The max is:', the_max(the_max(a, b), c)) - ``` 上面的代码中,我定义了一个辅助函数`the_max`用来找出参数传入的两个值中较大的那一个,于是下面的输出语句可以通过两次调用`the_max`函数来找出三个数中的最大值,现在代码的可读性是不是好了很多。用辅助函数来替代复杂的表达式真的是一个不错的选择,关键是比较大小的逻辑转移到这个辅助函数后不仅可以反复调用它,而且还可以进行级联操作。 @@ -86,6 +81,5 @@ a = int(input('a = ')) b = int(input('b = ')) c = int(input('c = ')) print('The max is:', max(a, b, c)) - ``` diff --git a/知乎问题回答.md b/知乎问题回答.md index 68bc00d..2d96658 100644 --- a/知乎问题回答.md +++ b/知乎问题回答.md @@ -94,4 +94,4 @@ - 《Scrum敏捷软件开发》(*Software Development using Scrum*) - 《高效团队开发 - 工具与方法》 -当然学习编程,最重要的通过项目实战来提升自己的综合能力,Github上有大量的优质开源项目,其中不乏优质的Python项目。有一个名为[“awesome-python-applications”](https://github.com/mahmoud/awesome-python-applications)的项目对这些优质的资源进行了归类并提供了传送门,大家可以了解下。除此之外,还要为大家推荐一个名为[“Python-100-Days”](https://github.com/jackfrued/Python-100-Days)的项目,上面有大量优质的Python学习资料(包括文档、代码和相关资源)。如果自学能力不是那么强,可以通过网络上免费或者付费的视频课程来学习对应的知识;如果自律性没有那么强,那就只能建议花钱参加培训班了,因为花钱在有人监督的环境下学习对很多人来说确实是一个捷径,但是要记得:“师傅领进门,修行靠各人”。选择自己热爱的东西并全力以赴,不要盲目的跟风学习,这一点算是过来人的忠告吧。记得我自己刚开始进入软件开发这个行业时,有人跟我说过这么一句话,现在也分享出来与诸君共勉:“浮躁的人有两种:只观望而不学习的人,只学习而不坚持的人;浮躁的人都不是高手。” \ No newline at end of file +当然学习编程,最重要的通过项目实战来提升自己的综合能力,Github上有大量的优质开源项目,其中不乏优质的Python项目。有一个名为[“awesome-python-applications”](https://github.com/mahmoud/awesome-python-applications)的项目对这些优质的资源进行了归类并提供了传送门,大家可以了解下。如果自学能力不是那么强,可以通过网络上免费或者付费的视频课程来学习对应的知识;如果自律性没有那么强,那就只能建议花钱参加培训班了,因为花钱在有人监督的环境下学习对很多人来说确实是一个捷径,但是要记得:“师傅领进门,修行靠各人”。选择自己热爱的东西并全力以赴,不要盲目的跟风学习,这一点算是过来人的忠告吧。记得我自己刚开始进入软件开发这个行业时,有人跟我说过这么一句话,现在也分享出来与诸君共勉:“浮躁的人有两种:只观望而不学习的人,只学习而不坚持的人;浮躁的人都不是高手。” \ No newline at end of file