使用 PySpark 进行数据清洗
Mike Metzger
Data Engineering Consultant
Spark 中的缓存:
开发 Spark 任务时:
在动作前对 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 进行数据清洗