首页 > 解决方案 > 当 isNotNull Pyspark 时有列

问题描述

我从控制台收到以下错误:

TypeError: _() 接受 1 个位置参数,但给出了 2 个

这是使用的代码:

import pyspark.sql.functions as f

start = '2020-10-20'
end = '2021-01-20'

country = 'es'
spark.conf.set('spark.sql.legacy.timeParserPolicy', 'LEGACY')

dim_customers = (spark.table(f'nn_team_{country}.dim_customers')
           .select(f.col('customer_id').alias('customers'),
                   f.col('hello_pay_date').alias('hello_pay_date'),                    
                      )
                 .withColumn('HelloPay_user',
                             f.when((f.col('lidl_pay_date').isNotNull(1)).otherwise(0))
           ))

我尝试了几种 () 组合但没有结果。关于我为什么会收到此错误的任何想法?

标签: pythonapache-sparkpysparkapache-spark-sql

解决方案


你的语法不正确。您应该将 1 放在when子句中,而不是 inside isnotnull

dim_customers = (spark.table(f'nn_team_{country}.dim_customers')
           .select(f.col('customer_id').alias('customers'),
                   f.col('hello_pay_date').alias('hello_pay_date'),                    
                      )
                 .withColumn('HelloPay_user',
                             f.when(f.col('lidl_pay_date').isNotNull(), 1).otherwise(0))
           ))

推荐阅读