toofrellik toofrellik - 7 months ago 55
Scala Question

Scala - Save a data frame to text file without [ ]

When i save a Dataframe to a text file it gets saved with


for example i have a data frame:


when i do
myDataFrame.rdd.saveAsTextFile("My Path")
i get


is there a way to remove those brackets.


Here's a way of doing it.

val df: DataFrame = ??? => r.getString(0)).saveAsTextFile("My Path")

The issue is your RDD contains org.apache.spark.sql.Row objects. When these are 'toStringed' they have those square braces on either side. You want to extract the data out of the Row object into a String.