object Ten1 {
def main(args: Array[String]): Unit = {
val source = scala.io.Source.fromFile("D:\\1Fuxi\\scala1\\scala1\\scalass\\src\\com\\fuxi\\zji\\yq.csv") getLines()
source.next()
val yq = source.toList.filter(_.length > 0).map(line => {
val fields = line.split(",")
(fields(0), (fields(2), fields(1)))
})
println(yq)
val re = yq.groupBy(ro => ro._1)
.map(kvs =>(kvs._1,kvs._2.map(_._2).sortWith(_._1 > _._1).head)
)
for ((k, v) <- re) {
println(s"日期:$k Top1:${v._2} 新增${v._1}")
}
println(re)
}
}
yq.csv
dt,province,adds,possibles
2020-5-12,beijing,1,8
2020-5-12,shanghai,3,6
2020-5-13,beijing,3,5
2020-5-13,shanghai,2,1