Par*_*kar 6 apache-spark pyspark
在pyspark中,有没有一种方法可以将时间戳数据类型的数据框列转换为格式为'YYYY-MM-DD'的字符串?
您可以使用date_format函数,如下所示
from pyspark.sql.functions import date_format
df.withColumn("dateColumn", date_format(col("vacationdate"), "yyyy-MM-dd"))
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助!
如果您有一个带有schema
as 的列
root
|-- date: timestamp (nullable = true)
Run Code Online (Sandbox Code Playgroud)
然后你可以使用from_unixtime
函数来转换时间戳来串转换后的时间戳来BIGINT使用unix_timestamp
功能
from pyspark.sql import functions as f
df.withColumn("date", f.from_unixtime(f.unix_timestamp(df.date), "yyyy-MM-dd"))
Run Code Online (Sandbox Code Playgroud)
你应该有
root
|-- date: string (nullable = true)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
7393 次 |
最近记录: |