開始使用免費開始

端到端測試資料管線

在這個練習中,你會使用之前相同的資料管線,負責擷取、轉換並載入稅務資料。你將練習對這條管線進行端到端測試,確保這個解決方案可以重複執行多次,且不會在 parquet 檔案中重複寫入轉換後的資料。

pandas 已以 pd 載入,且 extract()transform()load() 三個函式都已定義完成。

本練習屬於課程

使用 Python 的 ETL 與 ELT

檢視課程

練習說明

  • 使用 for 迴圈將 ETL 管線執行 3 次。
  • 在每次管線執行時,列印 clean_tax_data 的 shape。
  • "clean_tax_data.parquet" 檔案中的 DataFrame 讀入 to_validate 變數。
  • 輸出 to_validate DataFrame 的 shape,並與 clean_tax_rate 的 shape 比較,確認每次執行管線時資料沒有被重複寫入。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# 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.____}")
編輯並執行程式碼