以下是我要实现的动作:
types = ["200","300"]
def Count(ID):
cnd = F.when((**F.col("type") in types**), 1).otherwise(F.lit(0))
return F.sum(cnd).alias("CountTypes")
BOLD中的语法是不正确的,任何建议如何在此处获取正确的语法?
我不确定您要实现的目标,但这是正确的语法:
types = ["200","300"]
from pyspark.sql import functions as F
cnd = F.when(F.col("type").isin(types),F.lit(1)).otherwise(F.lit(0))
sum_on_cnd = F.sum(cnd).alias("count_types")
# Column<b'sum(CASE WHEN (type IN (200, 300)) THEN 1 ELSE 0 END) AS `count_types`'>