I want to replace null values in one column with the values in an adjacent column ,for example if i have
A|B 0,1 2,null 3,null 4,2
I want i
Another Answer.
If the below df1 your dataframe
df1
rd1 = sc.parallelize([(0,1), (2,None), (3,None), (4,2)]) df1 = rd1.toDF(['A', 'B']) from pyspark.sql.functions import when df1.select('A', when( df1.B.isNull(), df1.A).otherwise(df1.B).alias('B') )\ .show()