如何在PySpark中将字符串列更改为DateTime格式?

2024-04-20 14:00:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个包含多个列和行的数据集。enter image description here

目前,它是字符串类型enter image description here,我想转换为日期时间格式,以便执行进一步的任务

我尝试了下面这个返回null的代码

df = df.withColumn('Date_Time',df['Date_Time'].cast(TimestampType()))
df.show()

我在这里尝试了一些解决方案,但没有一个有效。最后,所有这些都返回null

Convert pyspark string to date format


Tags: 数据字符串代码类型dfdatetime格式