导入所需要的函数库

from pyspark.sql.functions import col, from_unixtime

读取数据

df = spark.read.json('/path/to/data')

清洗掉每条数据前面的NUL

df = df.filter(col('_corrupt_record').isNull())

将time转化为日期格式yyyy/MM/dd

df = df.withColumn('time', from_unixtime(col('time')/1000, 'yyyy/MM/dd'))

打印输出

df.show()

Spark DataFrame 数据清洗 - 将时间戳转换为日期格式并展示数据

原文地址: https://www.cveoy.top/t/topic/oKOz 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录