toofrellik toofrellik - 1 year ago 115
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.

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download