Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2022 02:19 AM
ok so you have this columns list (df.columns).
If you then do:
if "columnName" in columns: return df
else return df.withColumn("col", lit(null))
You do not need to loop.
In your loop you return col, not a df. You want to return the complete dataframe with an optional extra column,