PySpark 1.5 How to Truncate Timestamp to Nearest Minute from seconds

后端 未结 4 1314
予麋鹿
予麋鹿 2021-02-07 21:11

I am using PySpark. I have a column (\'dt\') in a dataframe (\'canon_evt\') that this a timestamp. I am trying to remove seconds from a DateTime value. It is originally read in

4条回答
  •  自闭症患者
    2021-02-07 21:59

    This question was asked a few years ago, but if anyone else comes across it, as of Spark v2.3 this has been added as a feature. Now this is as simple as (assumes canon_evt is a dataframe with timestamp column dt that we want to remove the seconds from)

    from pyspark.sql.functions import date_trunc
    
    canon_evt = canon_evt.withColumn('dt', date_trunc('minute', canon_evt.dt))
    

提交回复
热议问题