从已保存的文本创建 bag
这一次,您的同事已将评论保存到了若干文本文件中。存在多个文件,每个文件里也包含多条评论。每条评论在文本文件中占据一行。
您希望以惰性方式将这些数据加载到 Dask 中,从而利用并行处理更快地进行分析。
dask.bag 已为您导入为 db。
本练习是课程的一部分
Python 中的 Dask 并行编程
练习说明
- 使用
read_text()函数加载目录data/tripadvisor_hotel_reviews中所有的.txt文件。 - 统计 bag 中的评论数量。
- 使用 bag 的
.compute()方法打印答案。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Load in all the .txt files inside data/tripadvisor_hotel_reviews
review_bag = ____
# Count the number of reviews in the bag
review_count = review_bag.____
# Compute and print the answer
print(____)