簡體   English   中英

isNotNull 時帶列 Pyspark

[英]Withcolumn when 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))
           ))

我嘗試了幾種 () 組合但沒有結果。 關於我為什么會收到此錯誤的任何想法?

你的語法不正確。 您應該將 1 放在when子句中,而不是放在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))
           ))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM