Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .translate/state/pandas.md.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
source-sha: 02e57a5befc2a9a081019edc748aba15e4b2f02a
synced-at: "2026-04-09"
source-sha: 811accdd4ed8803df3a7123ada3b560bc3110712
synced-at: "2026-06-19"
model: claude-sonnet-4-6
mode: UPDATE
section-count: 5
tool-version: 0.14.0
tool-version: 0.15.0
8 changes: 4 additions & 4 deletions .translate/state/pandas_panel.md.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
source-sha: 126eb49056ad1b685638c1820ebb7b4c89cabf89
synced-at: "2026-03-20"
source-sha: 811accdd4ed8803df3a7123ada3b560bc3110712
synced-at: "2026-06-19"
model: claude-sonnet-4-6
mode: NEW
mode: UPDATE
section-count: 6
tool-version: 0.13.0
tool-version: 0.15.0
8 changes: 4 additions & 4 deletions lectures/pandas.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ df.loc[(df.cc + df.cg >= 80) & (df.POP <= 20000), ['country', 'year', 'POP']]

**应用:对数据框进行子集化**

现实世界的数据集可能[非常庞大](https://developers.google.com/machine-learning/crash-course/overfitting)。
现实世界的数据集可能 [非常庞大](https://developers.google.com/machine-learning/crash-course/overfitting)。

有时需要使用数据的子集来提高计算效率并减少冗余。

Expand Down Expand Up @@ -360,10 +360,10 @@ df.loc[complexCondition]

修改数据框的能力对于生成用于未来分析的干净数据集非常重要。

**1.** 我们可以方便地使用 `df.where()` 来"保留"我们已选择的行,并用任何其他值替换其余行
**1.** 我们可以方便地使用 `df.where()` 来"保留"我们已选择的行,并将其余行替换为 `NaN`

```{code-cell} ipython3
df.where(df.POP >= 20000, False)
df.where(df.POP >= 20000)
```

**2.** 我们可以简单地使用 `.loc[]` 来指定我们想要修改的列,并赋值:
Expand Down Expand Up @@ -433,7 +433,7 @@ df

缺失值插补是数据科学中的一个大领域,涉及各种机器学习技术。

Python 中还有更多[高级工具](https://scikit-learn.org/stable/modules/impute.html)可用于插补缺失值。
Python 中还有更多 [高级工具](https://scikit-learn.org/stable/modules/impute.html) 可用于插补缺失值。

### 标准化与可视化

Expand Down
12 changes: 6 additions & 6 deletions lectures/pandas_panel.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,21 +152,21 @@ realwage['United States'].head()
`.stack()` 将列 `MultiIndex` 的最低层级旋转到行索引(`.unstack()` 方向相反——可以尝试一下)

```{code-cell} ipython3
realwage.stack(future_stack=True).head()
realwage.stack().head()
```

我们也可以传入参数来选择要堆叠的层级

```{code-cell} ipython3
realwage.stack(level='Country', future_stack=True).head() # pandas>3.0 之前需要 future_stack=True
realwage.stack(level='Country').head()
```

使用 `DatetimeIndex` 可以方便地选择特定时间段。

选择某一年并堆叠 `MultiIndex` 的两个较低层级,可以创建面板数据的横截面

```{code-cell} ipython3
realwage.loc['2015'].stack(level=(1, 2), future_stack=True).transpose().head() # pandas>3.0 之前需要 future_stack=True
realwage.loc['2015'].stack(level=(1, 2)).transpose().head()
```

在本讲座的其余部分,我们将使用一个包含各国和各时间段每小时实际最低工资的数据框,以 2015 年美元计价。
Expand Down Expand Up @@ -363,7 +363,7 @@ plt.show()

我们还可以指定 `MultiIndex` 的某个层级(在列轴上)进行聚合。

对于 `groupby`,由于 pandas 已弃用在 `groupby` 方法中使用 `axis=1`,我们需要使用 `.T` 将列转置为行。
对于 `groupby`,由于 `pandas` 已移除在 `groupby` 方法中使用 `axis=1` 的支持,我们需要使用 `.T` 将列转置为行。

```{code-cell} ipython3
merged.T.groupby(level='Continent').mean().head()
Expand Down Expand Up @@ -393,7 +393,7 @@ plt.show()
`.describe()` 可用于快速检索多个常用汇总统计量

```{code-cell} ipython3
merged.stack(future_stack=True).describe()
merged.stack().describe()
```

这是使用 `groupby` 的一种简化方式。
Expand Down Expand Up @@ -563,4 +563,4 @@ plt.show()
```

```{solution-end}
```
```
Loading