导入所需要的函数库

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()

根据提示在右侧编辑器补充代码清洗数据使用DataFrameshow打印输出。一条数据信息如下dc_iddc_0source sensor-ipad c02_level244 descriptionSensor embedded in exhaust pipes in the ceilings geo lat30283370561

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

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