Scala Spark:将双列转换为数据帧中的日期时间列 [英] Scala Spark : Convert Double Column to Date Time Column in dataframe
本文介绍了Scala Spark:将双列转换为数据帧中的日期时间列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试编写代码,以将实际上是unix时间的date-time列date和last_updated_date转换为double格式,以显示为 mm-dd-yyyy格式。我该怎么做?
I am trying to write code to convert date-time columns date and last_updated_date which are actually unix times cast as doubles into "mm-dd-yyyy" format for display. How do I do this ?
import org.joda.time._
import scala.tools._
import org.joda.time.format.DateTimeFormat._
import java.text.SimpleDateFormat
import org.apache.spark.sql.functions.{unix_timestamp, to_date}
root
|-- date: double (nullable = false)
|-- last_updated_date: double (nullable = false)
|-- Percent_Used: double (nullable = false)
+------------+---------------------+------------+
| date| last_updated_date|Percent_Used|
+------------+---------------------+------------+
| 1.453923E12| 1.47080394E12| 1.948327124|
|1.4539233E12| 1.47080394E12| 2.019636442|
|1.4539236E12| 1.47080394E12| 1.995299371|
+------------+---------------------+------------+
推荐答案
以时间戳为单位:
df.select(col("date").cast("timestamp"));
这篇关于Scala Spark:将双列转换为数据帧中的日期时间列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文