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 版
296
|
10
10.1 GroupBy
机制
Hadley Wickham
R
语言中许多热门包的作者)创造了一个用于描述分组运算的术语“拆
分-应用-联合”(
split-apply-combine
)。首先,
pandas
对象(无论是
Series
DataFrame
还是其他)中的数据会根据你所提供的单键或多键拆分为多组。拆分操作是在对象的特
定轴上执行的。例如,
DataFrame
可以在其行(axis="index")或列(axis="columns"
上进行分组。其次,将一个函数应用到各个分组,并产生一个新值。最后,所有这些函
数的执行结果会联合为最终的结果对象。结果对象的形式一般取决于对数据所执行的操
作。图
10-1
对简单的聚合过程做了大致说明。
10-1:分组聚合图示
每个分组键可以有多种形式,并且类型不必相同:
·
值列表或值数组,其长度与待分组的轴一样。
·
DataFrame 中指明列名的值。
·
字典或 Series,给出待分组轴上的值与分组名之间的对应关系。
·
可以在轴索引或索引各标签上调用的函数。
注意,后三种都是快捷方式,用于产生一组用于拆分对象的值数组。如果觉得它们看起
来很抽象,也不用担心,本章将给出与这些方法有关的大量示例。首先来看下面这个
数据聚合与分组操作
|
297
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

徹底攻略AWS認定デベロッパー - アソシエイト教科書&問題集 第2版 [DVA-C02]対応

徹底攻略AWS認定デベロッパー - アソシエイト教科書&問題集 第2版 [DVA-C02]対応

株式会社NTTデータ 川畑光平

Publisher Resources

ISBN: 9787111726722