数据:
col1 result
good positive
bad null
excellent null
good null
good null
所需输出:
col1 result
good positive
bad positive
excellent null
good negative
good negative
我有以下两个条件,想把它和 .fillna
,这些条件仅适用于 null
中的值 result
柱
df = df.withColumn('result', when(col('col1') == 'good', 'negative').otherwise(df["result"]))
df = df.withColumn('result', when(col('col1') == 'bad', 'positive').otherwise(df["result"]))
1条答案
按热度按时间qij5mzcb1#
你可以用
coalesce
要根据需要替换空值: