I have n arrays of string columns. I would like concatenate this n columns in one, using a loop.
I have this function to concat columns:
def concat(type):
def concat_(*args):
return list(chain(*args))
return udf(concat_, ArrayType(type))
concat_string_arrays = concat(StringType())
And in the following example, I have 4 columns that I will concatenate like this:
df_aux = df.select('ID_col',concat_string_arrays(col("patron_txt_1"),col("patron_txt_2"),col('patron_txt_3'),col('patron_txt_0')).alias('patron_txt')
But, if I have 200 columns, how can I use dynamically this function with a loop?