admin 管理员组

文章数量: 1184232


2024年12月29日发(作者:matlab画方程组的图)

pythonpandas的基本操作

【中英文实用版】

Title: Basic Operations with Python Pandas

Title: Python Pandas 基本操作

Introduction:

Python"s Pandas library is a powerful tool for data manipulation and

, we will discuss some of the basic operations that can be

performed using Pandas.

介绍:

Python 的 Pandas 库是数据操作和分析的强大工具。在这里,我们将讨论

一些使用 Pandas 可以执行的基本操作。

Data Loading:

To begin with, we need to load some provides various

options to load data such as reading from a CSV file, Excel file, or a SQL

database.

数据加载:

首先,我们需要加载一些数据。Pandas 提供了各种加载数据的方法,例如

从 CSV 文件、Excel 文件或 SQL 数据库中读取。

```python

import pandas as pd

# 读取 CSV 文件

df = _csv("")

# 读取 Excel 文件

df = _excel("")

# 读取 SQL 数据库

df = _sql("SELECT * FROM table_name", conn)

```

```python

# 读取 CSV 文件

df = _csv("数据.csv")

# 读取 Excel 文件

df = _excel("数据.xlsx")

# 读取 SQL 数据库

df = _sql("SELECT * FROM 表名", 连接对象)

```

Data Selection:

Once the data is loaded, we can select specific columns or rows using

various methods like `loc`, `iloc`, and `at`/`iat`.

数据选择:

一旦加载了数据,我们可以使用 `loc`、`iloc`、`at` 和 `iat` 等方法选择特

定的列或行。

```python

# 选择特定列

selected_columns = df[["column1", "column2"]]

# 选择满足条件的行

selected_rows = df[df["column1"] > 10]

# 使用 loc 和 iloc 选择行和列

selected_cell = [0, "column1"]

```

```python

# 选择特定列

选定列 = df[["列1", "列2"]]

# 选择满足条件的行

选定行 = df[df["列1"] > 10]

# 使用 loc 和 iloc 选择行和列

选定单元格 = [0, "列1"]

```

Data Manipulation:

Pandas provides powerful data manipulation capabilities like adding

new columns, dropping columns, and renaming columns.

数据操作:

Pandas 提供了强大的数据操作功能,如添加新列、删除列和重命名列。

```python

# 添加新列

df["new_column"] = df["column1"] * 2

# 删除列

df = ("column2", axis=1)

# 重命名列

(columns={"column1":

inplace=True)

```

```python

# 添加新列

df["新列"] = df["列1"] * 2

# 删除列

df = ("列2", axis=1)

# 重命名列

(columns={"列1": "新列名"}, inplace=True)

```

Data Aggregation:

Pandas allows us to perform aggregation operations like sum, mean,

median, etc., on the data.

数据聚合:

Pandas 允许我们对数据执行求和、平均值、中位数等聚合操作。

"new_column_name"},


本文标签: 数据 操作 连接 加载 读取