title: Counting non zero values in each column of a DataFrame in python
body: <p>I have a python-pandas-DataFrame in which first column is <code>&quot;user_id&quot;</code> and rest of the columns are tags(<code>&quot;Tag_0&quot;</code> to <code>&quot;Tag_122&quot;</code>).</p>
  <p>I have the data in the following format:</p>
  <pre><code>UserId  Tag_0   Tag_1
  7867688 0   5
  7867688 0   3
  7867688 3   0
  7867688 3.5 3.5
  7867688 4   4
  7867688 3.5 0
  </code></pre>
  <p>My aim is to achieve <code>Sum(Tag)/Count(NonZero(Tags))</code> for each user_id</p>
  <p><code>df.groupby('user_id').sum()</code>, gives me <code>sum(tag)</code>, however I am clueless about counting non zero values</p>
  <p>Is it possible to achieve <code>Sum(Tag)/Count(NonZero(Tags))</code> in one command?</p>
  <p>In MySQL I could achieve this as follows:-</p>
  <pre><code>select user_id, sum(tag)/count(nullif(tag,0)) from table group by 1
  </code></pre>
  <p>Any help shall be appreciated.</p>