第九章:Pandas入门——数据分析利器
你有没有用 Excel 处理过数据?筛选、排序、做图表——Pandas 就是 Python 世界的 Excel,但它更灵活、更强大,能轻松处理百万行数据。
9.1 什么是 Pandas?
Pandas 是 Python 数据分析的核心库。它提供两种核心数据结构:
Series:一列数据(像 Excel 的一列)
DataFrame:一张表格(像 Excel 的一个工作表)
Python
Loading editor...
9.2 创建 DataFrame
DataFrame 是 Pandas 最核心的结构。它就像一个智能表格。
Python
Loading editor...
9.3 数据探索——先看看手头有什么
Python
Loading editor...
9.4 筛选与排序——大海捞针
Python
Loading editor...
9.5 新增列与计算——让数据更丰富
Python
Loading editor...
9.6 分组聚合——从数据中发现规律
Python
Loading editor...
9.7 数据可视化——一张图胜过千言万语
Pandas 内置了 matplotlib 集成,一行代码就能画图。
Python
Loading editor...
💡 Pandas 的
plot()方法背后正是matplotlib。只需一行df.plot(...)就能快速出图。
本章小结
| 你学到了什么 | 具体内容 |
|---|---|
| ✅ Series | 带标签的一维数组,Pandas 的基础 |
| ✅ DataFrame | 核心表格结构,从字典创建 |
| ✅ 数据探索 | `head()`、`describe()`、`mean()` |
| ✅ 筛选排序 | 条件筛选 `df[条件]`、`sort_values()` |
| ✅ 新增列 | 直接赋值运算,自动向量化 |
| ✅ 分组聚合 | `groupby()` + 聚合函数 |
| ✅ 可视化 | `df.plot()` 一行出图 |
🚀 下一章预告:有了 NumPy 和 Pandas 的武器库,你已经站在了 AI 的大门口。接下来进入真正的机器学习——让程序自己从数据中找到规律!
本章内容基于 [Pandas 官方文档](https://pandas.pydata.org/docs/) 改编,遵循 BSD License 许可。