df.select(df.a, F.when(df.a >0, 1).otherwise(2).alias('b'))
当 df.a 值大于0时,则用 1 作为字段b的值;反之,用 2 作为字段b的值。