【发布时间】:2021-10-12 00:58:19
【问题描述】:
我有以下数据框
root
|-- id: long (nullable = false)
|-- name: string (nullable = true)
|-- school: string(nullable = true)
|-- subject: string(nullable = true)
|-- created_date: long(nullable = false)
我想将数据存储在这个数据框中,根据 created_date 列按年份和月份划分。
newDataframe=originaldataframe.select(col("id"),col("name"),col("school"),col("subject"),date_format(from_unixtime(col["created_date"]/1000,"MM-dd-yyyy"),"MM-dd-yyyy")).cast('date')
dataframePationed= newDataframe.withColumn("year", year(newDataframe.created_date)).withColumn("month", month(newDataframe.created_date)).drop("created_date")
dataframePationed.write.partitionBy("year", "month").format("csv").save("path/to/partion/data")
但是在 long 数据类型转换日期格式后,如果我尝试打印 createdDate 列值显示为 null。我怎样才能正确地做到这一点?
【问题讨论】:
标签: dataframe pyspark date-format partition