title: Dataframe in pypark - How to apply aggregate functions to into two columns?
body: <p>I'm using Dataframe in pyspark. I have one table like Table 1 bellow. I need to obtain Table 2. Where: </p>
  
  <ul>
  <li>num_category - it is how many differents categories for each id</li>
  <li>sum(count) - it is the sum of the third column in Table 1 for each id. </li>
  </ul>
  
  <p>Example:</p>
  
  <p><strong>Table 1</strong></p>
  
  <pre><code>id   |category | count 
  
  1    |    4    |   1 
  1    |    3    |   2
  1    |    1    |   2
  2    |    2    |   1
  2    |    1    |   1
  </code></pre>
  
  <p><strong>Table 2</strong></p>
  
  <pre><code>id   |num_category| sum(count) 
  
  1    |    3       |   5 
  2    |    2       |   2
  </code></pre>
  
  <p>I try:</p>
  
  <pre><code>table1 = data.groupBy("id","category").agg(count("*"))
  cat = table1.groupBy("id").agg(count("*"))
  count = table1.groupBy("id").agg(func.sum("count"))
  table2 = cat.join(count, cat.id == count.id)
  </code></pre>
  
  <blockquote>
    <p>Error:</p>
  </blockquote>
  
  <pre><code>     1 table1 = data.groupBy("id","category").agg(count("*"))
  ---&gt; 2 cat = table1.groupBy("id").agg(count("*"))
         count = table1.groupBy("id").agg(func.sum("count"))
         table2 = cat.join(count, cat.id == count.id)
   TypeError: 'DataFrame' object is not callable
  </code></pre>