How do I truncate a PySpark dataframe of timestamp type to the day?

后端 未结 3 889
悲&欢浪女
悲&欢浪女 2021-01-12 13:01

I have a PySpark dataframe that includes timestamps in a column (call the column \'dt\'), like this:

2018-04-07 16:46:00
2018-03-06 22:18:00
<
3条回答
  •  春和景丽
    2021-01-12 13:45

    One simple way to do it with string manipulation:

    from pyspark.sql.functions import lit, concat
    
    df = df.withColumn('date', concat(df.date.substr(0, 10), lit(' 00:00:00'))) 
    

提交回复
热议问题