Python Pyspark:使用 F.current_date() 过滤当前日期之前的 1 天

Pin*_*ts0 9 python datediff date subtraction pyspark

我想过滤数据集以查找特定日期之前的所有日期。具体来说是当前日期前 1 天。

我尝试了下面的代码:

df = df.filter(F.col('date') <= F.current_date() - 1)
Run Code Online (Sandbox Code Playgroud)

但我收到以下错误:

u"cannot resolve '(current_date() - 1)' due to data type mismatch: differing types in '(current_date() - 1)' (date and int)
Run Code Online (Sandbox Code Playgroud)

Psi*_*dom 8

F.date_sub方法应该有效:

df.filter(F.col('date') <= F.date_sub(F.current_date(), 1))
Run Code Online (Sandbox Code Playgroud)