# 13.1 Pandas初步

### 14.1.2 初识Pandas

Panda是一个开源的、BSD许可的库，为Python编程语言提供高性能、易于使用的数据结构和数据分析工具。Pandas内置了强大的数据结构和数据处理工具，巧妙使用这些工具，可以使得数据清洗和分析事半功倍。Pandas主要适用于处理表格或异质型数据，而NumPy更适合处理同质型得数值类数组数据。

对于数据科学研究来说，数据处理是最重要，也是最耗时的阶段。数据处理通常分为以下几个阶段：

1. 整理和清理数据
2. 分析/建模数据
3. 将分析结果组织成适合绘图或表格显示的形式。

Pandas 是完成所有这些任务的理想工具。表14.1描述了Pandas库擅长处理的数据与易于解决的问题。

表14.1 Pandas库擅长处理的数据与易于解决的问题

| 处理数据                                                                                                                                 | 解决问题                                                                                                                              |
| ------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------- |
| 列数据类型不尽相同的表格数据，如在SQL表或Excel电子表格中。 有序和无序(不一定是固定频率)时间序列数据。 具有行和列标签的任意矩阵数据(均匀类型或异构类型) 。 任何其他形式的观察/统计数据集。实际上这些数据根本不需要标记就可以存储到Pandas数据结构中 | 处理缺失数据(NaN)。 可以从DataFrame和更高维度的对象中**插入和删除**。 Pandas数据对象可以指定与一组标签对齐，也可以不加以指定由数据对象再计算中自动对齐。 对数据集进行拆分组合。 将不规则、不同索引的数据转换为DataFrame对象。 |

除了上表列举的功能之外，Pandas还支持智能标签的切片，花式索引，时间序列处理等功能，除此之外，Pandas提供了强大的I/O工具，可以对CSV、Excel等数据进行方便而又快速的读写操作。我们将在本章对Pandas库进行详细探究。

### 14.1.2 安装Pandas

我们可以使用Conda命令或者pip命令对Pandas进行安装：

conda install pandas

pip instal pandas

安装完成后就可以导入pandas库进行使用了，通常我们使用pd来作为 pandas库的别名：

Import pandas as pd

我们通常需要导入NumPy库来和Pandas配合使用：

Import numpy as np


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://johannesliu.gitbook.io/data-science-python-implemented/13.0-foundation_data_analysis/13.1-prelimary.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
