【发布时间】:2020-05-15 09:59:20
【问题描述】:
我正在尝试检查 pyspark 数据框中的条件并将值添加到如下所示的列中:
DF:
cd id Location
A A A
A AA A
A AAA
A B B
A BB B
A BBB
预期输出:
cd id Location
A A A
A AA A
A AAA New_Loc
A B B
A BB B
A BBB New_Loc
我尝试使用以下 pyspark 转换进行填充
df_new = df.withColumn('Location',sf.when(df.cd == 'A' & (df.id isin(['AAA','BBB'])),'New_Loc').otherwise(df.Location))
当我尝试执行此操作时,我收到错误消息: Py4JError:调用 o129.and 时发生错误。 Trace: py4j.Py4JException: Method and ([class java.lang.string]) 不存在
知道这是什么错误吗?
【问题讨论】: