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

问题描述 投票:1回答:1

我想过滤特定日期之前所有日期的数据集。特别是当前日期前一天。

我试过下面的代码:

df = df.filter(F.col('date') <= F.current_date() - 1)

但是我收到以下错误:

u"cannot resolve '(current_date() - 1)' due to data type mismatch: differing types in '(current_date() - 1)' (date and int)
python date pyspark datediff subtraction
1个回答
0
投票

F.date_sub方法应该工作:

df.filter(F.col('date') <= F.date_sub(F.current_date(), 1))
© www.soinside.com 2019 - 2024. All rights reserved.