Skip to Content
利用 Python 进行数据分析:原书第 3 版
book

利用 Python 进行数据分析:原书第 3 版

by Wes McKinney
November 2023
Intermediate to advanced
512 pages
11h 53m
Chinese
China Machine Press
Content preview from 利用 Python 进行数据分析:原书第 3 版
496
|
附录
B
义在 main 中的变量了。这等价于在
Jupyter notebook
的代码框中定义一个顶级变量。
扁平优于嵌套
深层嵌套的代码总让我联想到洋葱皮。当测试或调试函数时,你需要剥多少层洋葱皮才
能到达目标代码呢?“扁平优于嵌套”是
Python
之禅的一部分,它也适用于交互式代码
开发。尽量将函数和类解耦和模块化有利于进行交互式测试(如果你在编写单元测试)、
调试和使用。
克服对长文件的恐惧
如果你之前接触过
Java
(或者其他类似的语言),可能已经知道要让文件尽量简短。在多
数语言中,这都是合理的建议,代码太长会让人觉得是坏代码,有必要对代码进行重构
和重组。但是,在用
IPython
开发时,处理
10
个相关联的小文件(比如小于
100
行)比
处理两个或三个长文件更让人头疼。更少的文件意味着重载模块更少,以及编写代码时
在各文件间跳转更少。我发现维护大模块,每个模块都是高内聚的(所有代码都用于解
决同类问题),会更实用且符合
Python
的风格。当然,经过方案迭代,有时会将大文件
分解成小文件。
不过,我不建议极端化地实践这条建议,否则就是将所有代码放到一个单独的怪异文件
中。为了组装大型代码库而寻找合理且直观的模块和包,往往需要不少工作,最好以团
队合作的方式进行。每个模块都应该是内聚的,并且应该能直观地找到负责每个功能的
函数和类。
B.7
高阶
IPython
特性
要充分利用
IPython
系统,需要用另一种稍微不同的方式来编写代码或者深入研究
IPython
配置。
文件和配置
通过扩展配置系统,
IPython
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

Effective Python 第3版 ―Pythonプログラムを改良する125項目

Effective Python 第3版 ―Pythonプログラムを改良する125項目

Brett Slatkin, 鈴木 駿

Publisher Resources

ISBN: 9787111726722