• Пожалуйста, не используйте API / Framework высокого уровня, такие как pandas / spark- sql et c.
• Решите эту проблему, используя простые структуры данных, заданные на языке Scala.
Набор данных -
Name,Age,Location
Rajesh,21,London
Suresh,28,California
Sam,26,Delhi
Rajesh,21,Gurgaon
Manish,29,Bengaluru
Вот что я пробовал:
val list =
Source
.fromFile("/home/nikhil/Desktop/Datasets/abc.csv").drop(1)
.getLines()
.filter(line => !line.isEmpty)
.map { line =>
val value = line.split(",")
(value(0), value(1))
}.toList
val test = list.toSet //doesn't preserve the order
//#To preserve the order
// val test = list.distinct
OR use drop(1) while reading the file, that will skip the first line of the file contains (Name, Age, Location).
test.foreach(println)
output:-
(Rajesh,21)
(Suresh,28)
(Sam,26)
(Manish,29)