简体   繁体   English

PySpark删除列中的无效日期时间格式

[英]PySpark removing Invalid Date time format in column

My date time field format is: 2016-10-15 00:00:00 after using infer schema while saving my data to a parquet file, I have a few rows that don't comply to this format. 我的日期时间字段格式为:2016-10-15 00:00:00使用推断架构,同时将我的数据保存到镶木地板文件,我有几行不符合此格式。

How can I collectively remove them in PySpark? 如何在PySpark中集体删除它们?

It is causing me problems in my UDF's. 它在我的UDF中引起了我的问题。

Assuming you're parsing the date column and rows with invalid dates are null, which is usually the case: 假设您正在解析日期列,并且具有无效日期的行为空,通常是这种情况:

df.filter(col('date').isNotNull())

Alternatively, if your date is read as a string, you can parse it using unix_timestamp : 或者,如果您的日期作为字符串读取,您可以使用unix_timestamp解析它:

(
    df
    .select(unix_timestamp('date', 'yyyy-MM-dd HH:mm:ss').cast("timestamp").alias('date'))
    .filter(col('date').isNotNull())
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM