我有一個帶有 Julian Dates 的 pySpark DataFrame 列。我試圖將日期轉換為日歷日期。
| 數字 | 朱利安日期 |
|---|---|
| 1 | 17196 |
| 2 | 17199 |
| 3 | 17281 |
我嘗試使用以下代碼:
spdf = spdf.withColumn('date_new',functions.to_date(functions.from_unixtime("julian_date")))
但是,我得到的輸出為:
| 數字 | 朱利安日期 | date_new |
|---|---|---|
| 1 | 17196 | 1970-01-01 |
| 2 | 17199 | 1970-01-01 |
| 3 | 17281 | 1970-01-01 |
請幫忙。提前致謝
uj5u.com熱心網友回復:
儒略日期由 2 年數字和 3 位日期組成。
例如:17196 是 2017 年的第 196 天,即 2017-07-15。
因此,您可以使用to_date年份 (y) 和年份 (D) 格式。(參考:日期模式)
df.withColumn('date_new', functions.to_date(df.julian_date, 'yyDDD'))
# If julian_date is not String type.
# df.julian_date.cast(StringType())
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/477856.html
