データパイプラインをエンドツーエンドでテストする
この演習では、これまでと同じ、税データを抽出・変換・ロードするデータパイプラインを扱います。パイプラインをエンドツーエンドでテストし、変換後のデータが parquet ファイル内で重複せず、解決策を複数回実行できることを確認します。
pandas は pd として読み込まれており、extract()、transform()、load() 関数はすでに定義されています。
この演習はコースの一部です
Python で学ぶ ETL と ELT
演習の手順
forループを使って ETL パイプラインを3回実行します。- 各イテレーションで
clean_tax_dataの shape を出力(print)します。 "clean_tax_data.parquet"ファイルに保存された DataFrame を読み込み、to_validate変数に代入します。- 各パイプライン実行でデータが重複していないことを確認するため、
to_validateDataFrame の 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.____}")