從已儲存的文字建立 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(____)