你有没有尝试过:
from pyspark.sql import functions as Fdf.withColumn('device_id', F.when(col('device')=='desktop', 1).when(col('device')=='mobile', 2).otherwise(None))请注意,在链接
when函数时,不需要将后续调用包装在
otherwise函数中。

你有没有尝试过:
from pyspark.sql import functions as Fdf.withColumn('device_id', F.when(col('device')=='desktop', 1).when(col('device')=='mobile', 2).otherwise(None))请注意,在链接
when函数时,不需要将后续调用包装在
otherwise函数中。