title: Spark - How to count number of records by key
body: <p>This is probably an easy problem but basically I have a dataset where I am to count the number of females for each country. Ultimately I want to group each count by the country but I am unsure of what to use for the value since there is not a count column in the dataset that I can use as the value in a groupByKey or reduceByKey. I thought of using a reduceByKey() but that requires a key-value pair and I only want to count the key and make a counter as the value. How do I go about this? </p>
  
  <pre><code>val lines = sc.textFile("/home/cloudera/desktop/file.txt")
  val split_lines = lines.map(_.split(","))
  val femaleOnly = split_lines.filter(x =&gt; x._10 == "Female")
  </code></pre>
  
  <p>Here is where I am stuck. The country is index 13 in the dataset also. 
  The output should something look like this:
  (Australia, 201000)
  (America, 420000)
  etc
  Any help would be great.
  Thanks</p>