Can anyone suggest how can I add multiple empty columns in a pyspark dataframe. Currently I am doing something like this but its not working :
def add_columns(dataframe, column_list):
for col in column_list:
self = dataframe.withColumn(str(col), lit(None).cast(StringType())))
return dataframe
In the output schema after the add_columns function is applied , I get new column as generator object genexpr at 0x7f41189d7e10: string (nullable = true)
lit(None)
withlit('')
? – ags29str(col)
what do you expect here? maybe it should be col.name instead. – vvg