I have a dataframe df which has around 40 columns. Now I want to add a new column named as comment in the dataframe, and value of that column should be coming through a function.
I have created this function –
def new_column(df)
:
null_col = []
for c in df.columns:
if df.select(c).first()[0] == '': null_cols.append(c)
if len(null_cols) > 1: x= (' & '.join(null_cols))
else: x = (null_cols)
return x
Calling the function here –
df_updt = df.withColumn("comment", new_column(df))
But I am getting error –
Argument col
should be a Column, got str.
Is there any way this can be achieved in databricks?
I tried different version of the same function, I tried creating an udf, but udf dont take dataframe as an input parameter. I tried some other option that gemini provided, but nothing is working.
Please ignore the quotes in the function, that I had given otherwise stackoverflow was showing error.
SHWETA is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.