截断Scala中的数据帧列值
df是数据帧,并且 df.选择$createdon.show 输出为:截断Scala中的数据帧列值,scala,dataframe,spark-dataframe,Scala,Dataframe,Spark Dataframe,df是数据帧,并且 df.选择$createdon.show 输出为: | 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值只是日期,而不是整个时间戳。如何使包含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值只是日期,而不是整个时间戳。如何使包含createdon值的新数据框仅为日期而不是整个时间戳?您可以使用映射转换,假设所选值为字符串类型 df.选择$createdon.map\u.getAs[String]createdon.substring0,11.show 截止日期函数应执行以下操作:
df.withColumn("createdon", to_date($"createdon")).show
+----------+
| createdon|
+----------+
|2017-05-11|
+----------+