【发布时间】:2020-01-30 19:24:04
【问题描述】:
我的输入数据采用以下格式,即 dataframe df_date:
col1, col2, extraction_date, col3
010, DSL, 20191201235900, VDRAC
010, DSL, 20191203235900, VDRAC
010, DSL, 20191205235900, VDRAC
010, DSL, 20200120235900, VDRAC
010, DSL, 20200128235900, VDRAC
010, DSL, 20200129235900, VDRAC
010, DSL, 20200129235900, VDRAC
(string, string, bitint(longtype), string) # I have added the data type of each column for reference)
当我想处理旧日期时,只考虑 29 日之前的记录。我需要过滤它并需要应用业务条件。
import datetime
var = '28-01-2020'
ref_date = datetime.datetime.strptime(var, '%d-%m-%Y').date() #converting input ref date arg to date format
df_fil_date = df_data.filter(df_date.extraction_date.leq(ref_date))
显示错误,因为来自源的提取日期是 long_type (bitint),而 ref_date 变量是日期格式。
能否请您检查并告诉我如何根据传递的日期变量过滤数据?
【问题讨论】:
标签: pyspark pyspark-dataframes