โหลดข้อมูล JSON
คุณได้รับมอบหมายให้วิเคราะห์ข้อมูลเกี่ยวกับนักการเมืองจากหลายประเทศ ข้อมูลนี้จัดเก็บอยู่ในรูปแบบ JSON ขั้นตอนแรกคือโหลดข้อมูลเข้ามา แล้วแปลงจาก string เป็น dictionary
ได้นำเข้า dask.bag ให้แล้วในชื่อ db
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
Parallel Programming with Dask in Python
คำแนะนำการฝึกหัด
- นำเข้าแพ็กเกจ
json - อ่านไฟล์ทั้งหมดที่มีนามสกุล
.jsonในไดเรกทอรีdata/politiciansเข้าสู่ Dask bag ในรูปแบบ string - แปลง JSON string เหล่านี้ให้เป็น Python dictionary
- แสดงตัวอย่าง dictionary 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(____)