python - 当 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
子句中,而不是 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))
))
推荐阅读
- php - 在 Slim 框架中管理跨多个路由共享的数据的最佳方法是什么?
- php - 部署到 Heroku 后 MySQL INSERT 错误
- swift - 使用 SwiftUI 和 WebSockets 将代码添加到新行
- reactjs - 从 api 渲染数据
- android - 在从 Intent.ACTION_CREATE_DOCUMENT 从 ParcelFileDescriptor 创建 FileOutputStream 之前确定可用空间
- c# - 如何在 Linux 上的 asp.net 核心中捕获退出信号?
- javascript - 绘制一条总是与其父 BoxElement 一样宽的线?
- powershell - 获取总磁盘使用量的总和
- python - 有没有办法将协议“添加”到已经创建的 python 类?
- sql - 根据条件将行转换为列