2017-05-11 57 views
0

df是数据帧,并截断Scala的数据帧列值

df.select($ “createdon”)显示

输出为:

|   createdon| 
+--------------------+ 
|2017-05-11 15:29:...| 
|2017-05-11 15:29:...| 
|2017-05-11 11:02:...| 
|2017-05-11 11:02:...| 
|2017-05-11 15:29:...| 

我需要的创造价值只是日期而不是整个时间戳。如何让包含createdon的值的新数据框只是日期而不是整个时间戳?

回答

0

您可以使用地图转换(假定,即选择的值是String类型的)

df.select($"createdon").map(_.getAs[String]("createdon").substring(0, 11)).show()

2

to_date功能应该这样做:

df.withColumn("createdon", to_date($"createdon")).show 
+----------+ 
| createdon| 
+----------+ 
|2017-05-11| 
+----------+