Spark dataframe date_add 功能不工作时的情况
Spark dataframe date_add function with case when not working
我有一个 spark DataFrame,其中我有一个 where
条件,可以根据某些条件在现有日期列中添加日期数。
我的代码如下所示
F.date_add(df.transDate,
F.when(F.col('txn_dt') == '2016-01-11', 9999).otherwise(10)
)
因为 date_add()
函数接受第二个参数作为 int
,但是我的代码 returns 作为 Column
,它抛出错误。
如何从 case when 条件中收集值?
pyspark.sql.functions.when()
returns a Column
,这就是您的代码生成 TypeError: 'Column' object is not callable
的原因
你可以通过将 when
移到外面来得到想要的结果,像这样:
F.when(
F.col('txn_dt') == '2016-01-11',
F.date_add(df.transDate, 9999)
).otherwise(F.date_add(df.transDate, 10))
我有一个 spark DataFrame,其中我有一个 where
条件,可以根据某些条件在现有日期列中添加日期数。
我的代码如下所示
F.date_add(df.transDate,
F.when(F.col('txn_dt') == '2016-01-11', 9999).otherwise(10)
)
因为 date_add()
函数接受第二个参数作为 int
,但是我的代码 returns 作为 Column
,它抛出错误。
如何从 case when 条件中收集值?
pyspark.sql.functions.when()
returns a Column
,这就是您的代码生成 TypeError: 'Column' object is not callable
你可以通过将 when
移到外面来得到想要的结果,像这样:
F.when(
F.col('txn_dt') == '2016-01-11',
F.date_add(df.transDate, 9999)
).otherwise(F.date_add(df.transDate, 10))