การทดสอบ data pipeline แบบครบวงจร
ในแบบฝึกหัดนี้ จะได้ทำงานกับ data pipeline เดิมที่ใช้ดึง แปลง และโหลดข้อมูลภาษี โดยจะฝึกทดสอบ pipeline นี้แบบครบวงจร เพื่อให้มั่นใจว่ารันซ้ำได้หลายครั้งโดยไม่ทำให้ข้อมูลที่แปลงแล้วซ้ำกันในไฟล์ parquet
โหลด pandas ไว้เป็น pd แล้ว และได้นิยามฟังก์ชัน extract(), transform(), และ load() ไว้เรียบร้อยแล้ว
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
ETL และ ELT ด้วย Python
คำแนะนำการฝึกหัด
- รัน ETL pipeline สามครั้งโดยใช้
for-loop - แสดงค่า shape ของ
clean_tax_dataในแต่ละรอบที่รัน pipeline - อ่าน DataFrame ที่จัดเก็บไว้ในไฟล์
"clean_tax_data.parquet"ลงในตัวแปรto_validate - แสดงค่า shape ของ DataFrame
to_validateเพื่อเปรียบเทียบกับ shape ของclean_tax_rateและตรวจสอบว่าข้อมูลไม่ถูกทำซ้ำในแต่ละครั้งที่รัน pipeline
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Trigger the data pipeline to run three times
____ attempt in range(0, ____):
print(f"Attempt: {attempt}")
raw_tax_data = extract("raw_tax_data.csv")
clean_tax_data = transform(raw_tax_data)
load(clean_tax_data, "clean_tax_data.parquet")
# Print the shape of the cleaned_tax_data DataFrame
print(f"Shape of clean_tax_data: {clean_tax_data.____}")
# Read in the loaded data, check the shape
to_validate = pd.____("clean_tax_data.parquet")
print(f"Final shape of cleaned data: {to_validate.____}")