Fed*_*ede 9 python apache-spark pyspark pyspark-sql
我正在尝试使用"链接时"功能.换句话说,我想获得两个以上的输出.
我尝试在Excel中使用连接IF函数的相同逻辑:
df.withColumn("device_id", when(col("device")=="desktop",1)).otherwise(when(col("device")=="mobile",2)).otherwise(null))
Run Code Online (Sandbox Code Playgroud)
但这不起作用,因为我无法将元组放入"其他"功能.
Grr*_*Grr 21
你有没有尝试过:
from pyspark.sql import functions as F
df.withColumn('device_id', F.when(col('device')=='desktop', 1).when(col('device')=='mobile', 2).otherwise(None))
Run Code Online (Sandbox Code Playgroud)
请注意,在链接when
函数时,您不需要在otherwise
函数中包含连续调用.
归档时间: |
|
查看次数: |
15394 次 |
最近记录: |