我的值类似于4/5/2017 0:00和12/21/2016 0:00
我想要yyyy-mm-dd hh:mm:ss格式。
我正在用它来完成任务。
stf1.withColumn('approval',unix_timestamp("approval","MM/dd/yyyy h:mm ")
其中sf1是数据帧,批准是我要转换为的列名。但是我得到的答案为null。而不是预期的。
答案 0 :(得分:0)
您可以为此使用sql函数。
>>> import pyspark.sql.functions as F
>>> df.show()
+-------------+
| a|
+-------------+
|4/5/2017 0:00|
+-------------+
>>> df.withColumn('b',F.date_format(F.to_date('a','MM/dd/yyyy HH:mm'),'yyyy-MM-dd HH:mm:ss')).show()
+-------------+-------------------+
| a| b|
+-------------+-------------------+
|4/5/2017 0:00|2017-04-05 00:00:00|
+-------------+-------------------+