提交 5eb4cd2a 编写于 作者: W wizardforcel

2020-07-14 16:50:56

上级 e418751e
......@@ -32,4 +32,4 @@ Python 3.4.x 或更高版本。 在 Debian 及其衍生产品(Ubuntu)上:p
**粗体**:表示您在屏幕上看到的新术语,重要单词或顺序。 例如,菜单或对话框中的单词会出现在这样的文本中。 这是一个示例:“在此添加单元,然后单击再次运行单元”。
Warnings or important notes appear like this. Tips and tricks appear like this.
警告或重要提示如下所示。 提示和技巧如下所示。
\ No newline at end of file
......@@ -10,7 +10,7 @@
在本章中,我们将讨论如何安装和管理 Anaconda。 Anaconda 是一个软件包,我们将在本书的以下各章中使用。
# 什么是水蟒
# 什么是 Anaconda
在本节中,我们将讨论什么是 Anaconda 以及为什么使用它。 我们将提供一个链接,以显示从其赞助商 Continuum Analytics 的网站下载 Anaconda 的位置,并讨论如何安装 Anaconda。 Anaconda 是 Python 和 R 编程语言的开源发行版。
......@@ -18,7 +18,7 @@
Anaconda 的安装包括现成的数据分析所需的大部分内容。 Conda 软件包管理器还可用于下载和安装新软件包。
Why use Anaconda? Anaconda packages Python specifically for data analysis. The most important packages for your project are included with an Anaconda installation. With the addition of some performance boosts provided by Anaconda and Continuum Analytics' enterprise support of the package, one should not be surprised by its popularity.
为什么要使用 Anaconda? Anaconda 专门为数据分析打包了 Python。 Anaconda 安装中包含了您项目中最重要的软件包。 除了 Anaconda 提供的一些性能提升,和 Continuum Analytics 对该程序包的企业支持之外,对于它的流行也不应感到惊讶。
# 安装 Anaconda
......@@ -92,7 +92,7 @@ Anaconda 随附 Jupyter 笔记本。 Jupyter 笔记本允许纯文本与代码
![](img/0f3e2361-f268-4a4c-906f-a07c8abfb37e.png)
Output of "magic" command
魔术命令的输出
* 另一个有用的功能是`timeit`,我们可以使用它来分析代码。 我们首先输入`timeit`,然后输入我们希望分析的代码,如下所示:
......
......@@ -142,7 +142,7 @@
![](img/68db44e7-74f3-44b8-8712-ee9926259dcd.png)
The first number that we pass is the number of rows, and the second number is the number of columns. You could have passed a third number that will determine the number of slabs, and a fourth, a fifth, and so on to specify the number of dimensions you want, and how long you want each dimension to be.
我们传递的第一个数字是行数,第二个数字是列数。 您可以传递第三个数字来确定平板的数量,第四个,第五个等等,以指定所需的维数以及每个维的长度。
现在,我们将创建 2 x 2 个具有所选名称的矩阵,以及 2 x 2 x 2 个包含数字的数组。 因此,这是一个仅包含名称的矩阵:
......
......@@ -43,4 +43,4 @@ conda install sqlite
**粗体**:表示您在屏幕上看到的新术语,重要单词或顺序。 例如,菜单或对话框中的单词会出现在这样的文本中。 这是一个示例:“从管理面板中选择系统信息”。
Warnings or important notes appear like this. Tips and tricks appear like this.
警告或重要提示如下所示。 提示和技巧如下所示。
\ No newline at end of file
......@@ -52,7 +52,7 @@ df.head()
```
The output is as follows:
输出如下:
![](img/7bf7d1c8-8b22-4fe1-bdcf-82a45d868d85.png)
......@@ -112,7 +112,7 @@ df.head()
```
The output is as follows:
输出如下:
![](img/80076b18-0c73-4252-b86f-f088e6ed6dad.png)
......@@ -143,7 +143,7 @@ df.shape
在本节中,我们将学习如何使用 Pandas 使用 Excel 数据来处理 ork,以及如何使用 Pandas 的`read_excel`方法从 Excel 文件中读取数据。 我们将阅读并探索一个真实的 Excel 数据集,并使用 xplore 解析一些可用于解析 Excel 数据的高级选项。
pandas internally uses the Excel `rd` Python library to extract data from Excel files. We can install it by executing `conda install xlrd`.
熊猫内部使用 Python Excel 库`rd`从 Excel 文件中提取数据。 我们可以通过执行`conda install xlrd`来安装它。
首先,请确保命令行程序在安装前以 admin 模式运行,如以下屏幕截图所示:
......@@ -182,7 +182,7 @@ df = pd.read_excel('IMDB.xlsx', sheetname=0)
df.head()
```
The output is as follows:
输出如下:
![](img/821fc1c4-66e5-4d78-8833-5a18bd54d4dd.png)
......@@ -233,7 +233,7 @@ df = pd.read_excel('IMDB.xlsx', sheetname=1, header=None)
df.head()
```
The output is as follows:
输出如下:
![](img/a1b88a66-420f-4bb6-ac46-103fd63509d4.png)
......@@ -289,7 +289,7 @@ df = pd.read_excel('IMDB.xlsx', sheetname=0, index_col='Title')
df.head()
```
The output is as follows:
输出如下:
![](img/75fb95a9-93d5-4196-aff7-d4bfa3c1541e.png)
......@@ -342,7 +342,7 @@ pandas 内部使用`lxml` Python 模块读取 HTML 数据。 您可以通过执
pd.read_html('IMDB.html')
```
The output is as follows:
输出如下:
![](img/86a8b673-bec2-4b09-82aa-a733b9ab7cdc.png)
......@@ -357,7 +357,7 @@ df = pd.read_pickle('IMDB.p')
df.head()
```
The output is as follows:
输出如下:
![](img/db67347d-5356-40ff-a4ec-38485abb9f6b.png)
......
......@@ -92,7 +92,7 @@ data.State
data['Address'] = data.County + ', ' + data.Metro + ', ' + data.State
```
The following is the output:
输出如下:
![](img/80f5fbde-9419-48fe-8538-2d04b5aad7a9.png)
......@@ -108,7 +108,7 @@ zillow = pd.read_table('data-zillow.csv', sep=',')
zillow.head()
```
The following is the output:
输出如下:
![](img/8377551b-4590-4cfa-97ae-97bcfc536aff.png)
......@@ -144,7 +144,7 @@ zillow.loc[7, ['Metro', 'County']]
zillow.iloc[7, [4,5]]
```
The following is the output:
输出如下:
![](img/3f95acd9-e1ce-4fa1-b26d-f2b8903a3e31.png)
......@@ -154,7 +154,7 @@ The following is the output:
zillow.loc[11, :]
```
The following is the output:
输出如下:
![](img/1bf4d056-8840-4178-a2ab-0c907727d277.png)
......@@ -182,7 +182,7 @@ zillow.iloc[201:205, 3:6]
zillow.loc[201:205, ['RegionName', 'State']]
```
The following is the output:
输出如下:
![](img/63443760-aeaf-4f53-9190-78df352d94fc.png)
......@@ -287,7 +287,7 @@ filtered_data = data.filter(items=['State', 'Metro'])
filtered_data.head()
```
The following is the output:
输出如下:
![](img/3cee634e-99f8-4ec7-8fce-0ebb53bcb71e.png)
......@@ -340,7 +340,7 @@ data = pd.read_table('data-zillow.csv', sep=',')
data.head()
```
The following is the output:
输出如下:
![](img/71de1596-5fa5-4e63-8a88-779058338a11.png)
......@@ -364,7 +364,7 @@ data[(data['Zhvi'] > 1000000) & (data['State'] == 'NY')].head()
data[((data['State'] == 'CA') | (data['State'] == 'NY'))].head()
```
The following is the output:
输出如下:
![](img/ae3e7055-c6cc-406c-ba76-9acb4759842d.png)
......@@ -409,7 +409,7 @@ data = pd.read_table('data-zillow.csv', sep=',')
data.head()
```
The following is the output:
输出如下:
![](img/b0022cc4-7634-4a23-a712-b19d36738050.png)
......@@ -443,7 +443,7 @@ data.axes
data.mean(axis=0)
```
The following is the output:
输出如下:
![](img/a764a72c-d397-4f59-bcac-229a1a5924ef.png)
......@@ -453,7 +453,7 @@ The following is the output:
data.mean(axis=1).head()
```
The following is the output:
输出如下:
![](img/193b4742-a7e8-4868-9053-147075cb3dbf.png)
......@@ -473,7 +473,7 @@ data.mean(axis='rows')
data.mean(axis='columns').head()
```
The following is the output:
输出如下:
![](img/e1672cd1-4c1d-4905-a005-1360a6a3b98e.png)
......@@ -485,7 +485,7 @@ The following is the output:
data.drop(0, axis=0).head()
```
The following is the output:
输出如下:
![](img/1e05a2a8-4fd9-401b-8558-f958f230215e.png)
......@@ -495,7 +495,7 @@ The following is the output:
data.drop('Date', axis=1).head
```
The following is the output:
输出如下:
![](img/239d4d64-3221-49e7-b4a1-5088a9b0a273.png)
......@@ -507,7 +507,7 @@ The following is the output:
data.filter(regex='Region', axis=1).head()
```
The following is the output:
输出如下:
![](img/7898185a-1388-4957-b3b4-771b258c8acf.png)
......@@ -522,7 +522,7 @@ data = pd.read_table('data-zillow.csv', sep=',')
data.head()
```
The following is the output:
输出如下:
![](img/42d7fec2-58a2-4661-9ec6-3d81ca8f6421.png)
......@@ -536,7 +536,7 @@ The following is the output:
data.RegionName.str.contains('New').head()
```
The following is the output:
输出如下:
![](img/2979fbcc-e11b-478d-8e98-cd96d7c8403f.png)
......@@ -548,7 +548,7 @@ The following is the output:
data.RegionName.str.upper().head()
```
The following is the output:
输出如下:
![](img/1cf324f9-06f0-4490-b1f7-44a484f8710d.png)
......@@ -560,7 +560,7 @@ The following is the output:
data.County.str.lower().head()
```
The following is the output:
输出如下:
![](img/3ae082da-ca37-49c7-9df3-c4ff312fec9c.png)
......@@ -572,7 +572,7 @@ The following is the output:
data.County.str.len().head()
```
The following is the output:
输出如下:
![](img/e975c024-47c0-4323-8e31-a63adae55628.png)
......@@ -584,7 +584,7 @@ The following is the output:
data.RegionName.str.lstrip().head()
```
The following is the output:
输出如下:
![](img/4d97b815-8342-457d-8928-2da592e3b09d.png)
......@@ -596,7 +596,7 @@ The following is the output:
data.RegionName.str.replace(' ', '').head()
```
The following is the output:
输出如下:
![](img/25cab1c9-c671-4ddc-8cf5-565d672d6848.png)
......@@ -604,14 +604,14 @@ The following is the output:
在本节中,我们将学习如何更改 Pandas 系列的数据类型。 我们将看到读取其中的数据后如何更改数据类型。 我们还将学习在读取 Pandas 数据时如何更改数据类型。 我们将通过一个示例将 int 列更改为 float。 我们还将看到如何将字符串值列转换为`datetime`数据类型。
We will start by importing the pandas module and reading the dataset of house prices from [zillow.com](https://www.zillow.com/) into the Jupyter Notebook:
我们将首先导入pandas模块,然后从 [zillow.com](https://www.zillow.com/) 中读取房价数据集到 Jupyter Notebook 中:
```py
data = pd.read_table('data-zillow.csv', sep=',')
data.head()
```
The following is the output:
输出如下:
![](img/d3b3d238-14e0-4f04-9aea-b00dcf0ef16e.png)
......@@ -623,7 +623,7 @@ The following is the output:
data.dtypes
```
The following is the output:
输出如下:
![](img/a6b83857-0572-4974-a596-d039cdc55671.png)
......@@ -649,7 +649,7 @@ data2 = pd.read_csv('data-zillow.csv', sep=',', dtype={'Zhvi':float})
data2.dtypes
```
The following is the output:
输出如下:
![](img/2e110b32-4710-4f41-87e6-6801cf75d036.png)
......
......@@ -186,7 +186,7 @@ for state, grouped_data in data.groupby('State'):
import pandas as pd
```
We will then read in our CSV dataset:
我们将读取我们的 CSV 数据集:
```py
data = pd.read_csv('data-titanic.csv')
......@@ -643,7 +643,7 @@ import pandas as pd
import numpy as np
```
We will then read in our CSV dataset:
我们将读取我们的 CSV 数据集:
```py
data = pd.read_csv('data-titanic.csv')
......
......@@ -182,7 +182,7 @@ plt.figure(figsize=(8, 6))
sns.lmplot(x='beer_servings', y='wine_servings', data=df);
```
The output is as follows:
输出如下:
![](img/9d69bf21-08fc-49fd-a377-fd0d19f6afe4.png)
......@@ -217,7 +217,7 @@ df.head()
sns.palplot(sns.color_palette())
```
The output of the preceding code is as follows:
前面代码的输出如下:
![](img/9d461c2b-6706-4a46-bfa7-a115da2b89e7.png)
......@@ -308,7 +308,7 @@ sns.set_palette(my_palette)
sns.palplot(sns.color_palette())
```
The output is as follows:
输出如下:
![](img/f9d916a8-d1c6-41a2-b2b2-2fca38e86f57.png)
......@@ -372,7 +372,7 @@ sns.stripplot(x="season", y="us_viewers_in_millions", data=df);
sns.swarmplot(x="season", y="us_viewers_in_millions", data=df);
```
The output is as follows:
输出如下:
![](img/4a6c8120-148d-4896-b712-258e29deab1e.png)
......@@ -399,7 +399,7 @@ sns.boxplot(x="season", y="us_viewers_in_millions", data=df);
sns.violinplot(x="season", y="us_viewers_in_millions", data=df);
```
The output of the preceding code is as follows:
前面代码的输出如下:
![](img/5f0100a2-ea47-491d-8af6-873fef4d1e3e.png)
......@@ -411,7 +411,7 @@ The output of the preceding code is as follows:
sns.barplot(x="season", y="us_viewers_in_millions", data=df);
```
The output is as follows:
输出如下:
![](img/f790e027-d61f-435d-8ad3-7128816cd263.png)
......@@ -421,7 +421,7 @@ The output is as follows:
sns.countplot(x="season", data=df);
```
The output of the preceding code is as follows:
前面代码的输出如下:
![](img/7ea2484a-7d1d-48c2-ac21-89d0fd6deda9.png)
......@@ -436,7 +436,7 @@ df = pd.read_csv('data-alcohol.csv')
df.head()
```
The output is as follows:
输出如下:
![](img/37b39dd4-7b5e-4af1-b22c-894456c56974.png)
......@@ -446,7 +446,7 @@ The output is as follows:
sns.boxplot(data=df, orient="h");
```
The output of the preceding code is as follows:
前面代码的输出如下:
![](img/994c67a1-d2e6-4d9b-98b1-d2c098e7b34d.png)
......@@ -501,7 +501,7 @@ mlb = pd.read_csv('data-mlb-players.csv')
mlb.head()
```
The output is as follows:
输出如下:
![](img/ff10718c-542e-4f2b-9365-0441ab9e9775.png)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册