El uso litconvertiría todos los valores de la columna al valor dado.
Para hacerlo solo para valores no nulos de dataframe, tendría que filtrar los valores no nulos de cada columna y reemplazar su valor. whenpuede ayudarte a lograr esto.
from pyspark.sql.functions import when
df.withColumn('c1', when(df.c1.isNotNull(), 1))
.withColumn('c2', when(df.c2.isNotNull(), 1))
.withColumn('c3', when(df.c3.isNotNull(), 1))
Esto resultaría en:
123c111n u l lc21n u l l1c311n u l l
Además, si desea reemplazar esos valores nulos con algún otro valor también, puede usarlos otherwiseen combinación con when. Digamos que quieres imputar 0allí:
from pyspark.sql.functions import when
df.withColumn('c1', when(df.c1.isNotNull(), 1).otherwise(0))
.withColumn('c2', when(df.c2.isNotNull(), 1).otherwise(0))
.withColumn('c3', when(df.c3.isNotNull(), 1).otherwise(0))
Esto resultaría en:
123c1110 0c210 01c3110 0