如何使用 PYspark 在相应列中有 null 的列中用 false 替换 true?

How to replace true with false in column where ever the corresponding column has null in it using PYspark?

我是 pyspark 的新手,我对 Naan 值有疑问。所以,我有一个如下所示的数据框:

df =
 name  std output
0 er   1st False
1 rt   2nd False
2 Naan 4th True 
3 Naan 8th True
4 Naan 10th True
5 fg   Naan False
6 Naan Naan True

现在,只要列名有 naan,它就会反映 True。我想在列名称中包含空值的地方用 false 替换 True。我想知道如何在 PYSPARK

预期输出:

df =
 name  std output
0 er   1st False
1 rt   2nd False
2 Naan 4th False
3 Naan 8th False
4 Naan 10th False
5 fg   Naan False
6 Naan Naan False

尝试使用 when + otherwise 语句。

Example:

df.show()

#+----+---+------+
#|name|std|output|
#+----+---+------+
#|  er|1st| false|
#|Naan|4th|  true|
#+----+---+------+

from pyspark.sql.functions import *

df.withColumn('output',when((col('name')=='Naan') & (col('output')),False).otherwise(col('output'))).show()

#+----+---+------+
#|name|std|output|
#+----+---+------+
#|  er|1st| false|
#|Naan|4th| false|
#+----+---+------+