I'm using the code below to convert an empty string to Null.
I don't get an error but it remains an empty string.
I suspect an incorrect use of the variable col_name
in expr
for col_name in ['col1', 'col2']:
df_new = df \
.withColumn(col_name, F.expr(f"nullif('{col_name}', '')"))