始める無料で始める

データパイプラインをエンドツーエンドでテストする

この演習では、これまでと同じ、税務データを抽出・変換・ロードするデータパイプラインを扱います。このパイプラインを何度実行しても、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.____}")
コードを編集して実行