You need to surround the second condition in parenthesis because &
has a higher evaluation priority than !=
:
df1 = df.withColumn(
"columnName_{}".format(columnName),
psf.lit(columnName)
).withColumn(
"{}_not_null".format(columnName),
psf.when(
psf.col(columnName).isNotNull() &
(psf.trim(psf.col(columnName)) != psf.lit(''))
, 1)
)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…