2024-06-30 15:10:03 发布
网友
我正在尝试使用“链接的时间”函数。 换句话说,我希望得到两个以上的输出。
我尝试在Excel中使用concatenate IF函数的相同逻辑:
df.withColumn("device_id", when(col("device")=="desktop",1)).otherwise(when(col("device")=="mobile",2)).otherwise(null))
但这不起作用,因为我不能把元组放入“否则”函数中。
你试过了吗:
from pyspark.sql import functions as F df.withColumn('device_id', F.when(col('device')=='desktop', 1).when(col('device')=='mobile', 2).otherwise(None))
注意,链接when函数时,不需要将连续调用包装在otherwise函数中。
when
otherwise
你试过了吗:
注意,链接
when
函数时,不需要将连续调用包装在otherwise
函数中。相关问题 更多 >
编程相关推荐