I am trying to concat all the values in a column to make a string out of it with comma seperated values. To do that in Scala, I wrote the following code:
val pushLogIds = incLogIdDf.select($"interface_log_id").collect().map(_.getInt(0).toString).mkString(",")
I am new to Python and after selecting the values in the column, I am unable to find a logic to Python to concat all the column values to a String after collecting them.
final_log_id_list = logidf.select("interface_log_id").collect()
Ex:
interface_log_id
----------------
1
2
3
4
Output: a variable of String containing '1,2,3,4'
Could anyone let me know how to concat all the column values of a dataframe into a single String of comma separated values.
import pyspark.sql.functions as Fso that the python builtins such asmin,maxetc are not overridden , hence every pyspark builtin needs anFprefix for me. You can ignore the F if you import without an alias>>> a = str(df.select('value').agg(F.concat_ws(",", F.collect_list(F.col('value'))))) >>> a 'DataFrame[concat_ws(,, collect_list(value)): string]'and it it still doesn't yild a String and instead comes a dataframe.df.agg(F.concat_ws(",",F.collect_list(F.col("A"))).alias('A')).first()[0]