Python Withcolumn何时为非空Pyspark
我从控制台收到以下错误: TypeError:uz()接受1个位置参数,但给出了2个 以下是使用的代码:Python Withcolumn何时为非空Pyspark,python,apache-spark,pyspark,apache-spark-sql,Python,Apache Spark,Pyspark,Apache Spark Sql,我从控制台收到以下错误: TypeError:uz()接受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_{cou
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))
))
我尝试了()的几种组合,但没有结果。你知道我为什么会出现这个错误吗?你的语法不正确。您应该在
when
子句中输入1,而不是在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))
))
你能发布完整的堆栈跟踪吗?你好@mck,谢谢你的回答,我尝试了你的解决方案,效果很好。但我有一个问题要问你:为什么当你把.isNotNull()放在()之外时,1必须是“在()之外”?否则它就在()之内.ThanksIt是spark的语法。您可以在中了解它。isnotnull不接受参数。
1
应该是when
的参数,而不是isnotnull
。类似地,0
是的参数,否则
。