Casting a new derived column in a DataFrame from boolean to integer Casting a new derived column in a DataFrame from boolean to integer python python

Casting a new derived column in a DataFrame from boolean to integer


Expression you use evaluates to column so you can cast directly like this:

x.withColumn('y', ((x.a-x.b) / x.c > 1).cast('integer')) # Or IntegerType()