使用 PySpark 清理資料
Mike Metzger
Data Engineering Consultant
Spark 的「快取」:
開發 Spark 工作時:
在執行 Action 前,先對 DataFrame 呼叫 .cache()
voter_df = spark.read.csv('voter_data.txt.gz')
voter_df.cache().count()
voter_df = voter_df.withColumn('ID', monotonically_increasing_id())
voter_df = voter_df.cache()
voter_df.show()
使用 .is_cached 檢查快取狀態
print(voter_df.is_cached)
True
完成後對 DataFrame 呼叫 .unpersist()
voter_df.unpersist()
使用 PySpark 清理資料