I have a function to which I need to provide a dataframe and a column. It extracts a string using regex pattern and return is a new dataframe.
However, I want the return to be just the result of regex, just the column.
def extract_strings(dataframe_selected, column_selected):
dataframe2 = dataframe_selected.withColumn("strings", F.regexp_extract(dataframe_selected[f"{column_selected}"], r"([a-zA-Z]+)", 0))
return dataframe2
I would like to create a function which I could use like
df['new_column'] = extract_strings(df, 'text')