PySpark でデータをクレンジングする
Mike Metzger
Data Engineering Consultant
voter_df = df.select(df['VOTER NAME']).distinct()
voter_df.explain()
== Physical Plan ==
*(2) HashAggregate(keys=[VOTER NAME#15], functions=[])
+- Exchange hashpartitioning(VOTER NAME#15, 200)
+- *(1) HashAggregate(keys=[VOTER NAME#15], functions=[])
+- *(1) FileScan csv [VOTER NAME#15] Batched: false, Format: CSV, Location:
InMemoryFileIndex[file:/DallasCouncilVotes.csv.gz],
PartitionFilters: [], PushedFilters: [],
ReadSchema: struct<VOTER NAME:string>
「シャッフル」とは、タスク完了のためにデータを複数ワーカー間で移動することです。
.repartition(num_partitions)の多用は避ける.coalesce(num_partitions)を使用.join()の呼び出しに注意.broadcast()を使用ブロードキャスト:
.join()を大幅に高速化できる.broadcast(<DataFrame>) を使用
from pyspark.sql.functions import broadcast
combined_df = df_1.join(broadcast(df_2))
PySpark でデータをクレンジングする