載入 JSON 資料
你受託要分析不同國家政治人物的資料。這些資料是以 JSON 格式儲存。你需要完成的第一步,是將它讀入,並把字串資料轉換成字典。
dask.bag 已經以 db 匯入供你使用。
本練習屬於課程
在 Python 中使用 Dask 進行平行程式設計
練習說明
- 匯入
json套件。 - 將
data/politicians目錄內所有以.json結尾的檔案,讀入為字串型別的 Dask bag。 - 將這些 JSON 字串轉換為 Python 字典。
- 列印 1 個範例字典。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Import of the json package
import json
# Read all of the JSON files inside data/politicians
text_bag = ____
# Convert the JSON strings into dictionaries
dict_bag = text_bag.____
# Show an example dictionary
print(____)