小编Dim*_*mpu的帖子

在 PySpark 中将整数列转换为日期

birth_date我有一个以这种格式调用的整数列:20141130

我想将其转换为2014-11-30PySpark 中的内容。

这会错误地转换日期:

.withColumn("birth_date", F.to_date(F.from_unixtime(F.col("birth_date"))))
Run Code Online (Sandbox Code Playgroud)

这给出了一个错误:argument 1 requires (string or date or timestamp) type, however, 'birth_date' is of int type

.withColumn('birth_date', F.to_date(F.unix_timestamp(F.col('birth_date'), 'yyyyMMdd').cast('timestamp')))
Run Code Online (Sandbox Code Playgroud)

将其转换为我想要的日期的最佳方法是什么?

apache-spark-sql pyspark

4
推荐指数
1
解决办法
2万
查看次数

标签 统计

apache-spark-sql ×1

pyspark ×1