Skip to Content
Spark快速大数据分析(第2版)
book

Spark快速大数据分析(第2版)

by Jules S. Damji, Brooke Wenig, Tathagata Das, Denny Lee
November 2021
Intermediate to advanced
340 pages
10h 46m
Chinese
Posts & Telecom Press
Content preview from Spark快速大数据分析(第2版)
Apache Spark
的结构化数据
API
59
DataFrame API
也提供了
collect()
方法,但对于特别大的
DataFrame
,这个
方法会非常耗费资源,而且很危险,因为有可能会导致内存不足。与
count()
同(
count()
只会将一个数值返回到驱动器),
collect()
会返回整个
DataFrame
Dataset
中所有的
Row
对象。如果你想拿几个
Row
对象来看一下,
最好使用
take(
n
)
方法,这个方法只会返回
DataFrame
的前
n
Row
对象。
其他常用的
DataFrame
操作
 与已经介绍的其他所有操作一样,
DataFrame
API
提供了描
述型的统计方法,比如
min()
max()
sum()
avg()
。我们可以通过一些例子来展示如何
针对旧金山消防部门数据集使用这些方法进行计算。
这次我们计算数据集的所有记录中警报的总数、平均响应时间、最短响应时间和最长响应
时间。引入
PySpark
的函数时修改了引用名,这是为了避免和内建的
Python
函数冲突。
# Python代码
import pyspark.sql.functions as F
(fire_ts_df
.select(F.sum("NumAlarms"), F.avg("ResponseDelayedinMins"),
F.min("ResponseDelayedinMins"), F.max("ResponseDelayedinMins"))
.show())
// Scala代码
import ...
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

数据驱动力:企业数据分析实战

数据驱动力:企业数据分析实战

Carl Anderson
数据压缩入门

数据压缩入门

Colt McAnlis, Aleks Haecky
解密金融数据

解密金融数据

Justin Pauley

Publisher Resources

ISBN: 9787115576019