Apache spark Pyspark中从字符串到日期时间(yyyy-mm-dd hh:mm:ss)的转换

Apache spark Pyspark中从字符串到日期时间(yyyy-mm-dd hh:mm:ss)的转换,apache-spark,pyspark,Apache Spark,Pyspark,dataframe中的列如下所示:- Input--> 20191106 ---Output---> 2019-11-06 00:00:00 Input--> 20180815--Output---> 2018-08-15 00:00:00 代码: 错误: File "C:/Users/nance.py", line 14, in <module> df.withColumn("newcol", from_unixtime(unix_timestam

dataframe中的列如下所示:-

Input--> 20191106 ---Output---> 2019-11-06 00:00:00
Input--> 20180815--Output---> 2018-08-15 00:00:00
代码:

错误:

File "C:/Users/nance.py", line 14, in <module>
    df.withColumn("newcol", from_unixtime(unix_timestamp(df("coldt"), "YYYY--MM-DD HH:MM:SS")))
TypeError: 'DataFrame' object is not callable
文件“C:/Users/nance.py”,第14行,在
df.withColumn(“newcol”,from_unixtime(unix_时间戳(df(“coldt”),“YYYY--MM-DD HH:MM:SS”))
TypeError:“DataFrame”对象不可调用
请帮助。

只需使用函数即可

工作示例:

导入pyspark.sql.F函数
df=spark.createDataFrame(['20191106'],['20180815']]
df=df.withColumn('dates',F.to_timestamp('u 1','yyyyMMdd'))
显示(df)

可能输入了
df(“coldt”)
。它不应该是
df[“coldt”]
?非常感谢,但它给出的错误是:pyspark.sql.utils.AnalysisException:u“由于数据类型不匹配,无法解析'unix_时间戳(
VDTL
,'yyyyymmdd'):参数1需要(字符串或日期或时间戳)但是,“
VDTL
”类型是bigint类型。请使用column('dates',F.to_timestamp('col','yyyyymmdd')帮助我.df=df.withColumn('code>colA,'yyyyMMdd'),但不幸的是,由于数据类型不匹配,它引发了错误,因为“无法解析'unix_timestamp(
colA
,'yyyyyymmdd'):参数1需要(字符串或日期或时间戳)类型,“
colA
”是bigint类型,将
colA
转换为
string
,然后使用to_timestamp()
File "C:/Users/nance.py", line 14, in <module>
    df.withColumn("newcol", from_unixtime(unix_timestamp(df("coldt"), "YYYY--MM-DD HH:MM:SS")))
TypeError: 'DataFrame' object is not callable