2 回答

TA貢獻1998條經驗 獲得超6個贊
使用to_date()功能。
df.show()
#+------+----------+
#| Name| doj|
#+------+----------+
#| Kevin|08/15/2013|
#|George|06/21/2014|
#+------+----------+
from pyspark.sql.functions import *
df.withColumn("doj",to_date(col("doj"),'MM/dd/yyyy')).show()
#+------+----------+
#| Name| doj|
#+------+----------+
#| Kevin|2013-08-15|
#|George|2014-06-21|
#+------+----------+
df.withColumn("doj",to_date(col("doj"),'MM/dd/yyyy')).printSchema()
#root
# |-- Name: string (nullable = true)
# |-- doj: date (nullable = true)

TA貢獻1788條經驗 獲得超4個贊
def dateconv(x):
if x == None:
x = 'null'
return x
else:
return x.strftime('%Y-%M-%D')
dateconv(doj)
python 中有類似的東西,我這樣做了
添加回答
舉報