Python PySpark:当函数具有多个输出时
我正在尝试使用“链接时间”函数。 换句话说,我希望得到两个以上的输出 我尝试在Excel中使用相同的concatenate IF函数逻辑:Python PySpark:当函数具有多个输出时,python,apache-spark,pyspark,pyspark-sql,Python,Apache Spark,Pyspark,Pyspark Sql,我正在尝试使用“链接时间”函数。 换句话说,我希望得到两个以上的输出 我尝试在Excel中使用相同的concatenate IF函数逻辑: df.withColumn("device_id", when(col("device")=="desktop",1)).otherwise(when(col("device")=="mobile",2)).otherwise(null)) 但这不起作用,因为我无法将元组放入“否则”函数中。您尝试过: from pyspark.sql import f
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))
请注意,当链接
函数时,
函数不需要将连续调用包装在函数中,否则
函数会起作用。!非常感谢你!!超级有用的链接组合!谢谢这些是链式操作-如果multiple when()为true,那么变量是被指定为true的第一个条件还是最后一个条件?@Thomas如果多个连续的when()语句为true,则只考虑计算为true的第一个when()。