In my pyspark DataFrame I have two columns price1 and price2. I want to create a new column result based on the formula ((price1 - price2)/price1). However, I want also to check that neither price1 nor price2 are null, and price1 is not 0.
How can I correctly create a new column using these conditions?
Now I have this:
df = df.withColumn("result", df["price1"]-df["price2"]/df["price1"])
price1==0or if one prices isnull?price1==0or any price is equal tonull, then I expectresultto be equal to0.