Skip to Content
Python for Excel (Chinese Edition), 2nd Edition
book

Python for Excel (Chinese Edition), 2nd Edition

by Felix Zumstein
May 2026
Intermediate
418 pages
5h 50m
Chinese
O'Reilly Media, Inc.
Content preview from Python for Excel (Chinese Edition), 2nd Edition

前言

本作品已使用人工智能进行翻译。欢迎您提供反馈和意见:translation-feedback@oreilly.com

“是的,我协助 Excel 团队完成了这项工作。很高兴它终于发布了!”这是 Python 之父、当时身为微软员工的 Guido van Rossum 于 2023 年 8 月 22 日在 X 上发布的消息。他的帖子中附上了Python 登陆 Excel 的官方公告链接。那么,我们是如何走到这一步的呢?

在 Excel 的早期,对于最终用户而言,Visual Basic for Applications(VBA)是编程和扩展 Microsoft Excel 的唯一选择。VBA 堪称“一站式解决方案”,因为它允许您:

  • 编写宏以实现单击按钮即可运行,例如添加包含报告的新工作表

  • 编写可在工作表单元格中调用的自定义函数(也称为用户定义函数

  • 构建自己的加载项,在整个工作簿中提供自动化功能和自定义函数

随着互联网和移动平台的重要性日益凸显,微软必须让Excel适应这些新环境。如今,Excel运行于Windows、macOS、Android、iOS以及——最重要的是——网页端。然而,仅Windows和macOS支持VBA。微软并未将VBA支持扩展至其他平台,而是创建了新工具:

  • Power Query能够导入和转换数据,并使用 M 语言。
  • Power Pivot是一款用于数据建模的加载项,其公式语言为数据分析表达式(DAX)。
  • Office Scripts采用 Typescript 语言,是与 VBA 最为接近的解决方案。但它不支持自定义函数,且需要 Microsoft 365 订阅。
  • Lambda 函数利用Excel 自身的公式语言来创建自定义函数。

因此,曾经的一站式解决方案如今已演变为一个碎片化的生态系统,其中每种工具都使用不同的编程语言。Excel 中的 Python 为这一列表增添了又一个选项:它为分析师提供了更强大的分析和可视化引擎,但不支持 Excel 自动化或自定义函数。

然而,Python 是一种通用编程语言,若仅将其用于分析和可视化,便会浪费其大量潜力。正因如此,本书不仅止步于 Excel 中的 Python。相反,我将向您展示如何利用 Python 的完整生态系统,将其作为现代 VBA 的替代方案。

本书的结构

本书分为六个部分。前两部分将教你 Python 和 pandas 的基础知识,因此在第三部分开始将 Python 与 Excel 结合使用之前,你需要稍加耐心。这是有意为之:如果你想走捷径,市面上有大量资源可以直接跳到 Excel 中的 Python 或 pandas 内容。 然而,一旦您需要修改或调试这些教程中的代码,就很容易陷入困境。通过在第一第二部分打下坚实的基础,您将理解后续章节中将依赖的概念和工具。这种方法虽然前期花费的时间稍长,但从长远来看,它将为您节省时间并避免挫折感。

第一部分,“Python 入门”

第 1 章探讨了 Python 为何是 Excel 的绝佳搭档。第 2 章介绍了本书将使用的工具:uv 包管理器、终端、Visual Studio Code 以及 Jupyter 笔记本。第 3 章将传授足够的 Python 基础知识,以便您能够跟上本书后续内容。

第二部分,“pandas 入门”

第 4 章将简要介绍 NumPy,它是包括 pandas 在内的许多科学包的基石。pandas 是第 5 章的主题,也是最受欢迎的 Python 数据分析库之一。其核心数据结构 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

学习勒索软件响应和恢复 (Chinese Edition)

学习勒索软件响应和恢复 (Chinese Edition)

W. Curtis Preston, Michael Saylor
Prometheus:快速入门,第二版

Prometheus:快速入门,第二版

Julien Pivotto, Brian Brazil

Publisher Resources

ISBN: 0642572396008