我正在嘗試在 Apache Spark 表上使用 concatenate 和 to_timestamp() 并使用 .withColumn 函式添加列,但它不起作用。
代碼如下:
DIM_WORK_ORDER.withColumn("LAST_MODIFICATION_DT", to_timestamp(concat(col('LAST_MOD_DATE'), lit(' '), col('LAST_MOD_TIME')), 'yyyyMMdd HHmmss'))
我希望看到的結果是
LAST_MODIFICATION_DT | 作業指示
但是,我得到以下結果:

一些需要處理的資料:
WORK_ORDER LAST_MOD_TIME 10000008 空 11358186 142254 10000007 193402 10000009 空
有什么想法嗎?
uj5u.com熱心網友回復:
據我所知,火花資料幀是不可變的。因此,一旦您創建了資料框,它就無法更改。
%python
import pyspark
from pyspark.sql.functions import *
df = spark.read.option("header","true").csv("<input file path>")
df1 = df.withColumn("LAST_MODIFICATION_DT", to_timestamp(concat(col('LAST_MOD_DATE'), lit(' '), col('LAST_MOD_TIME')), 'yyyyMMdd HHmmss'))
display(df1)
我的輸出低于預期。如果這不是您所期望的,請提供更多資訊
在此處輸入影像描述
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/442678.html
