2024-04-20 14:00:13 发布
网友
我有一个包含多个列和行的数据集。
目前,它是字符串类型,我想转换为日期时间格式,以便执行进一步的任务
我尝试了下面这个返回null的代码
df = df.withColumn('Date_Time',df['Date_Time'].cast(TimestampType())) df.show()
我在这里尝试了一些解决方案,但没有一个有效。最后,所有这些都返回null
Convert pyspark string to date format
由于日期格式是非标准的,因此需要使用to_timestamp并指定相应的格式:
to_timestamp
import pyspark.sql.functions as F df2 = df.withColumn('Date_Time', F.to_timestamp('Date_Time', 'dd/MM/yyyy hh:mm:ss a'))
由于日期格式是非标准的,因此需要使用
to_timestamp
并指定相应的格式:相关问题 更多 >
编程相关推荐