@udf(returnType=StringType()) def good_funify(s): return None if s == None else s + " is fun!" countries2.withColumn("fun_country", good_funify("country")).show() +---+---+---+ | country| id| fun_country| +---+---+---+ |Thailand| 3|Thailand is fun!| | null| ...