从时间戳列Pyspark添加月份列

时间:2019-03-08 12:58:27

标签: apache-spark pyspark apache-spark-sql

我有一个time列,时间戳的格式为2018-04-12 06:48:39。如何在此时间戳中添加Month列(在这种情况下包含4列)?

1 个答案:

答案 0 :(得分:2)

pyspark.sql.functions.month

import pyspark.sql.functions as F
df.withColumn('month', F.month('time')).show()
+-------------------+-----+
|               time|month|
+-------------------+-----+
|2018-04-12 06:48:39|    4|
+-------------------+-----+