title: Pandas groupby mean mulitple columns and count single column
body: <p>I am scraping housing ads with BS4 and analyze the data using Pandas. </p>
  
  <p>The following command,</p>
  
  <pre><code>madrid_rooms_district=df.groupby('district', as_index=False)['rent','size house, m2', 'price per m2','deposit'].agg(['mean', 'size'])
  </code></pre>
  
  <p>yields a table with one district per row, and the district's means for <code>'rent','size house, m2', 'price per m2','deposit'</code> per column. Which is what I need. </p>
  
  <p>I also need <b>one</b> column displaying the number of ads per district, hence <code>'size'</code> in the <code>.agg()</code>. However, the current set up of the command provides me with <b>four</b> columns displaying the number of ads, one column for each item in <code>['rent','size house, m2', 'price per m2','deposit']</code>.</p>
  
  <p>How can I reduce the number of "counting" columns from four to one?</p>
  
  <p>E.g. I have,</p>
  
  <pre><code>district | rent; mean | rent; size | size house, m2; mean | size house, m2; mean | ...
     -----------------------------------------------------------------------------------
     A     |    300     |     2      |        100           |       2              | ...
     B     |    400     |     6      |        200           |       6              | ...
     C     |    500     |     3      |        120           |       3              | ...
  </code></pre>
  
  <p>and I need, </p>
  
  <pre><code>district | rent; mean | size house, m2; mean | price per m2; mean | deposit; mean | count
     ---------------------------------------------------------------------------------------
     A     |    300     |        100           |        15          |       1       |   2
     B     |    400     |        200           |        14          |       2       |   6
     C     |    500     |        120           |        12          |       3       |   3
  </code></pre>
  
  <p>I've been trying to solve this differently by creating two DataFrames; one for the means and one for counting, but couldn't get them to merge into one DataFrame. Tried Series, tried joining, tried appending, tried...  </p>