I have input dataframe as below with id, app, and customer
Input dataframe
+--------------------+-----+---------+ |
Using CONCAT_WS we can explode array and can remove the square brackets.
df.groupBy("id").pivot("app").agg(concat_ws(",",collect_list("customer")))