Python Data Science 简明教程

Python Data Science - Pandas

What is Pandas?

熊猫是一个开源 Python 库,用于使用其强大数据结构进行高性能数据处理和数据分析。带有熊猫的 Python 在各种学术和商业领域中都在使用,包括金融、经济、统计学、广告、网络分析等。使用熊猫,我们能够完成数据处理和分析中的五个典型步骤,而不管数据的来源 - 加载、组织、处理、建模和分析数据。

Pandas is an open-source Python Library used for high-performance data manipulation and data analysis using its powerful data structures. Python with pandas is in use in a variety of academic and commercial domains, including Finance, Economics, Statistics, Advertising, Web Analytics, and more. Using Pandas, we can accomplish five typical steps in the processing and analysis of data, regardless of the origin of data — load, organize, manipulate, model, and analyse the data.

以下是熊猫的一些重要特性,专门用于数据处理和数据分析工作。

Below are the some of the important features of Pandas which is used specifically for Data processing and Data analysis work.

Key Features of Pandas

  1. Fast and efficient DataFrame object with default and customized indexing.

  2. Tools for loading data into in-memory data objects from different file formats.

  3. Data alignment and integrated handling of missing data.

  4. Reshaping and pivoting of date sets.

  5. Label-based slicing, indexing and subsetting of large data sets.

  6. Columns from a data structure can be deleted or inserted.

  7. Group by data for aggregation and transformations.

  8. High performance merging and joining of data.

  9. Time Series functionality.

熊猫处理以下三个数据结构 −

Pandas deals with the following three data structures −

  1. Series

  2. DataFrame

这些数据结构建立在 Numpy 数组之上,使其快速而高效。

These data structures are built on top of Numpy array, making them fast and efficient.

Dimension & Description

思考这些数据结构的最佳方式是,高维数据结构是其低维数据结构的一个容器。例如,数据框是序列的容器,面板是数据框的容器。

The best way to think of these data structures is that the higher dimensional data structure is a container of its lower dimensional data structure. For example, DataFrame is a container of Series, Panel is a container of DataFrame.

Data Structure

Dimensions

Description

Series

1

1D labeled homogeneous array, size-immutable.

Data Frames

2

General 2D labeled, size-mutable tabular structure with potentially heterogeneously typed columns.

DataFrame 广泛应用,是目前最重要的数据结构。

DataFrame is widely used and it is the most important data structures.

Series

Series 是具有齐次数据的一维类似数组的结构。例如,以下系列收集了整数 10、23、56、…

Series is a one-dimensional array like structure with homogeneous data. For example, the following series is a collection of integers 10, 23, 56, …

10

23

56

17

52

61

73

90

26

72

Key Points of Series

  1. Homogeneous data

  2. Size Immutable

  3. Values of Data Mutable

DataFrame

DataFrame 是一个具有异构数据的二维数组。例如,

DataFrame is a two-dimensional array with heterogeneous data. For example,

Name

Age

Gender

Rating

Steve

32

Male

3.45

Lia

28

Female

4.6

Vin

45

Male

3.9

Katie

38

Female

2.78

该表表示一个组织的销售团队及其总体绩效评级的表示,数据以行和列表示。每一列表示一个属性,每一行表示一个人。

The table represents the data of a sales team of an organization with their overall performance rating. The data is represented in rows and columns. Each column represents an attribute and each row represents a person.

Data Type of Columns

四列的数据类型如下 −

The data types of the four columns are as follows −

Column

Type

Name

String

Age

Integer

Gender

String

Rating

Float

Key Points of Data Frame

  1. Heterogeneous data

  2. Size Mutable

  3. Data Mutable

我们将在下一章中看到大量有关在数据科学工作中使用 python 的 pandas 库的示例。

We will see lots of examples on using pandas library of python in Data science work in the next chapters.