How to rank the data set having multiple columns in Scala? -
i have data set fetching csv file how store in scala processing.
+-----------+-----------+----------+ | recent | freq | monitor | +-----------+-----------+----------+ | 1 | 1234| 199090| | 4 | 2553| 198613| | 6 | 3232 | 199090| | 1 | 8823 | 498831| | 7 | 2902 | 890000| | 8 | 7991 | 081097| | 9 | 7391 | 432370| | 12 | 6138 | 864981| | 7 | 6812 | 749821| +-----------+-----------+----------+
actually need sort data , rank it. new scala programming. thanks
answering question here solution, code reads csv , order third column
object csvdemo extends app { println("recent, freq, monitor") val bufferedsource = io.source.fromfile("./data.csv") val list: array[array[string]] = (bufferedsource.getlines map { line => line.split(",").map(_.trim) }).toarray val newlist = list.sortby(_(2)) newlist map { line => println(line.mkstring(" ")) } bufferedsource.close }
you read file , parse array[array[string]]
, order third column, , print
Comments
Post a Comment