Skip to Main Content
Python程序设计:人工智能案例实践
book

Python程序设计:人工智能案例实践

by 保罗 戴特尔, 哈维 戴特尔
August 2021
Intermediate to advanced content levelIntermediate to advanced
450 pages
13h 28m
Chinese
Pearson
Content preview from Python程序设计:人工智能案例实践

16.7.2 总结推文主题标签,介绍Spark SQL

本节将使用Spark流技术来读取脚本starttweetstream.py发送的主题标签并汇总结果,可以创建一个新的记事本并输入本文中的代码,或者加载ch16示例文件夹的SparkHashtagSummarizer子文件夹中提供的hashtagsummarizer.ipynb笔记本。

导入库

首先,导入此笔记本中使用的库。在使用pyspark类时我们再对该类进行解释。从IPython中导入display模块,其中包含可以在Jupyter中使用的类和实用程序函数。特别是,在显示新的图表之前,使用CurryOutlook函数删除现有的图表:

此Spark应用程序以10秒为时间间隔汇总主题标签数量。处理完每批数据之后,它会显示一个Seaborn柱状图。IPython魔术命令

    %matplotlib inline

表示基于Matplotlib的图形应该显示在笔记本中,而不是在它们自己的窗口中。可以回想一下Seaborn是如何使用Matplotlib的。

本书多次使用了IPython魔术命令,Jupyter笔记本中特别使用了许多魔术命令。有关魔术命令的完整列表,请参见https://ipython.readthedocs.io/en/stable/interactive/magics.html。

获取SparkSession的实用程序函数

可以使用Spark SQL查询RDD中的数据,Spark SQL使用Spark DataFrame ...

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.
Start your free trial

You might also like

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

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

Peter Bruce, Andrew Bruce, Peter Gedeck
Python算法交易实战

Python算法交易实战

Posts & Telecom Press, Sebastien Donadio
Python机器学习案例精解

Python机器学习案例精解

Posts & Telecom Press, Yuxi (Hayden) Liu

Publisher Resources

ISBN: 9787111678458