I have a dataframe nameDF as below:
scala> val nameDF = Seq(("John","A"), ("John","B"), ("John","C"), ("John","D"), ("Bravo","E"), ("Bravo","F"), ("Bravo","G")).toDF("Name","Init")
nameDF: org.apache.spark.sql.DataFrame = [Name: string, Init: string]
scala> nameDF.show
+------+----+
|Name |Init|
+------+----+
|Johnny| A|
|Johnny| B|
|Johnny| C|
|Johnny| D|
|Bravo | E|
|Bravo | F|
|Bravo | G|
+------+----+
Without using SQL, I am trying to group the names and convert the multiple rows of each "Name" into a single row as given below:
+------+-------+
|Name |Init |
+------+-------+
|Johnny|A,B,C,D|
|Bravo |E,F,G |
+------+-------+
I see the available options to pivot are not suitable for String operations.
Is Pivot the correct option in this case ? If not, could anyone let me know how can I achieve the solution ?