title: filtering dataframe in scala
body: <p>Let say I have a dataframe created from a text file using case class schema. Below is the data stored in dataframe.</p>
  
  <p>id -    Type- qt   -     P</p>
  
  <p>1,  X,  10,     100.0</p>
  
  <p>2,  Y,  20,     200.0</p>
  
  <p>1,  Y,  15,     150.0</p>
  
  <p>1,  X,  5,      120.0</p>
  
  <p>I need to filter dataframe  by "id" and Type. And for every "id" iterate through the dataframe for some calculation. 
  I tried this way but it did not work. Code snapshot.</p>
  
  <pre><code>     case class MyClass(id: Int, type: String, qt: Long, PRICE: Double)
       val df = sc.textFile("xyz.txt")
      .map(_.split(","))
      .map(p =&gt; MyClass(p(0).trim.toInt, p(1), p(2).trim.toLong, p(3).trim.toDouble)
      .toDF().cache()
  
      val productList: List[Int] = df.map{row =&gt; row.getInt(0)}.distinct.collect.toList
      val xList: List[RDD[MyClass]] = productList.map { 
              productId =&gt; df.filter({ item: MyClass =&gt; (item.id== productId) &amp;&amp; (item.type == "X" })}.toList
      val yList: List[RDD[MyClass]] = productList.map { 
              productId =&gt; df.filter({ item: MyClass =&gt; (item.id== productId) &amp;&amp; (item.type == "Y" })}.toList
  </code></pre>