Python Pyspark:使用 F.current_date() 在当前日期之前过滤 1 天 [英] Python Pyspark: Filter for 1 Day Before Current Date Using F.current_date()
本文介绍了Python Pyspark:使用 F.current_date() 在当前日期之前过滤 1 天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想为某个日期之前的所有日期过滤我的数据集.特别是当前日期前 1 天.
I want to filter my data set for all the dates before a certain date. Specifically 1 day before the current date.
我尝试了以下代码:
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)
推荐答案
F.date_sub
方法应该可以工作:
F.date_sub
method should work:
df.filter(F.col('date') <= F.date_sub(F.current_date(), 1))
这篇关于Python Pyspark:使用 F.current_date() 在当前日期之前过滤 1 天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文