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 版
138
|
5
虽然可以用这种方式用标签选取数据,但是更可取的方式是使用特殊的 loc 运算符选取
索引值:
loc 的方式更为可取,因为用 [] 进行索引时,针对整数的处理有所不同。如果索引包含
整数,常规的基于 [] 的索引会将整数用作标签,因此索引的选取取决于数据类型。例如:
pandas
入门
|
139
使用 loc 时,如果索引中不含整数,则表达式 obj.loc[[0, 1, 2]] 会失效:
loc 运算符只使用标签,iloc 运算符只使用整数。无论索引是否包含整数,都能使用
iloc
还可以使用标签进行切片,但区别于普通
Python
的切片方式,loc 的切片是
包含末端的:
140
|
5
使用以上切片方法可以对
Series
的相应部分进行赋值:
像函数那样调用 loc iloc 是新手常犯的错误,正确的方式是用方括号
进行索引。方括号不仅用于切片索引,还用于对
DataFrame
的多个轴进行
索引。
用单个值或序列对
DataFrame
进行索引,以获取单列或多列:
pandas
入门
|
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