【发布时间】:2021-03-12 22:57:02
【问题描述】:
我正在尝试创建一列,然后应用过滤器,但出现错误:
TypeError: when() 缺少 1 个必需的位置参数:'value'
这里是使用的代码:
df = (
spark.table(f'nn_squad7_{country}.fact_table')
.filter(f.col('date_key').between(start,end))
.filter(f.col('is_client_plus')==1)
.filter(f.col('source')=='tickets')
.filter(f.col('subtype')=='trx')
.filter(f.col('is_trx_ok') == 1)
.withColumn('week', f.date_format(f.date_sub(f.col('date_key'), 1), 'YYYY-ww'))
.withColumn('month', f.date_format(f.date_sub(f.col('date_key'), 1), 'M'))
.withColumn('local_time',f.from_utc_timestamp(f.col('trx_begin_date_time'),'Europe/Brussels'))
.withColumn('Hour', f.hour(f.col('local_time')))
.filter(f.when(f.col('Hour')>= 4) & (f.col('Hour')<= 8))
)
我尝试应用的过滤器与客户的营业时间有关,我只想知道每个星期五在4.00 和8.00 pm 之间发生的数据。因此,如果此过滤器有效,我可能必须在一周中的某一天添加另一个过滤器。
关于错误的任何线索?
【问题讨论】:
标签: python dataframe apache-spark pyspark apache-spark-sql