Skip to Content
Python数据处理
book

Python数据处理

by Jacqueline Kazil, Katharine Jarmul
July 2017
Intermediate to advanced
398 pages
11h 54m
Chinese
Posts & Telecom Press
Content preview from Python数据处理
30
2
下面对这个列表调用
dir
函数:
dir(['cat', 'dog', 'horse'])
和字符串相比,列表可选的方法没有那么多,但我们来尝试其中几个。首先,将列表转化
为变量。你现在应该知道如何将列表赋值给变量,这是一个例子:
animals = ['cat', 'dog', 'horse']
前面用
dir
作用在列表上给出了许多新方法,现在在变量
animals
上试用其中一些方法:
animals.reverse()
animals.sort()
运行每一行代码后,打印输出
animals
的值,这样你就能看出这些方法是如何改变列表的。
你预期的输出是什么样的?它与你看到的相同吗?尝试将
dir
方法作用在整数和浮点数
上。(提示:
dir
只能传入一个对象,所以试着输入
dir(1)
dir(3.0)
)。其中有没有你没
有想到的方法?
如你所见,
dir
可以让你深入了解每一种
Python
数据类型的内置方法。在利用
Python
进行
数据处理时,这些方法是很有价值的。建议你花时间对感兴趣的上表列出的方法都尝试一
下,并用不同的数据类型测试更多的方法。
2.4.3
 
help
本章要学习的第三个有用的
Python
内置方法是
help
方法。这一方法会返回对象、方法或
模块的文档——虽然经常以技术性很强(有时很难懂)的文字书写。来看一下
split
方法
的帮助文档,这是我们在前一节用过的方法。如果你不知道需要将字符串的分隔符放在
括号内,怎么能知道如何使用
Python
字符串的
split
方法呢?假设我们不知道如何使用
split ...
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

数据科学中的实用统计学(第2版)

数据科学中的实用统计学(第2版)

Peter Bruce, Andrew Bruce, Peter Gedeck
Java持续交付

Java持续交付

Daniel Bryant, Abraham Marín-Pérez
解密金融数据

解密金融数据

Justin Pauley

Publisher Resources

ISBN: 9787115459190