Last active
June 29, 2017 04:28
-
-
Save dgadiraju/4dbd6664de6799aa04657d5ea716cf0e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import scala.io.Source | |
| val fileName = "/Users/itversity/Research/data/elections/ls2014.tsv" | |
| val results = Source.fromFile(fileName).getLines | |
| val notas = results.filter(rec => rec.split("\t")(2) == "None of the Above") | |
| // val notas = results.partition(rec => rec.split("\t")(2) == "None of the Above")._1 | |
| val notaByState = notas. | |
| map(rec => (rec.split("\t")(0), rec.split("\t")(10).toInt)). | |
| toList. | |
| groupBy(rec => rec._1). | |
| map(rec => (rec._1, rec._2.map(_._2).reduce((a, b) => a + b))). | |
| toList. | |
| sortBy(rec => -rec._2) | |
| notaByState.foreach(rec => println(rec._1 + "\t" + rec._2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment