Skip to content

Instantly share code, notes, and snippets.

@dgadiraju
Last active June 29, 2017 04:28
Show Gist options
  • Select an option

  • Save dgadiraju/4dbd6664de6799aa04657d5ea716cf0e to your computer and use it in GitHub Desktop.

Select an option

Save dgadiraju/4dbd6664de6799aa04657d5ea716cf0e to your computer and use it in GitHub Desktop.
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