我有一个火花数据框,里面有一个 where 条件,根据某个条件在现有日期列中添加日期数。
where
我的代码如下
F.date_add(df.transDate, F.when(F.col('txn_dt') == '2016-01-11', 9999).otherwise(10) )
自从 date_add() 函数接受第二个参数为 int ,但我的代码返回为 Column ,它抛出错误。
date_add()
int
Column
在条件下如何从案例中收集价值?
pyspark.sql.functions.when() 返回 Column ,这就是您的代码生成 TypeError: 'Column' object is not callable
pyspark.sql.functions.when()
TypeError: 'Column' object is not callable
您可以通过移动 when 从外面看,就像这样:
when
F.when( F.col('txn_dt') == '2016-01-11', F.date_add(df.transDate, 9999) ).otherwise(F.date_add(df.transDate, 10))