使用 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>
Shuffling 指為完成任務而在多個 worker 之間搬移資料。
.repartition(num_partitions).coalesce(num_partitions).join() 時要小心.broadcast()Broadcasting:
.join()使用 .broadcast(<DataFrame>) 方法
from pyspark.sql.functions import broadcast
combined_df = df_1.join(broadcast(df_2))
使用 PySpark 清理資料