I have pyspark dataframe with Firstname and Middlename columns . Middlename column has null values in it.
customer_df=
FName Middlename
Avi null
Chec Bor-iin
Meg null
Zen Cha-gn
I have written UDF to strip hypens
from pyspark.sql.functions import col, udf, upper, lit, when
replacehyphens = udf(lambda string_val: string_val.replace('-',''))
customer_df=customer_df.withColumn('Middlename',
when('Middlename'.isNull,lit('')).otherwise
(replacehyphens(col('Middlename'))))
I am getting AttributeError: 'str' object has no attribute 'isNull'
What am i missing here ?