如何在DataFrame中将Timestamp转换为Date格式? [英] How to convert Timestamp to Date format in DataFrame?
本文介绍了如何在DataFrame中将Timestamp转换为Date格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个DataFrame
和Timestamp
列,我需要将其转换为Date
格式.
I have a DataFrame
with Timestamp
column, which i need to convert as Date
format.
有没有可用的Spark SQL函数?
Is there any Spark SQL functions available for this?
推荐答案
您可以cast
到目前为止的列:
You can cast
the column to date:
斯卡拉:
import org.apache.spark.sql.types.DateType
val newDF = df.withColumn("dateColumn", df("timestampColumn").cast(DateType))
Pyspark:
df = df.withColumn('dateColumn', df['timestampColumn'].cast('date'))
这篇关于如何在DataFrame中将Timestamp转换为Date格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文