title: Python Pandas group by function
body: <p>I have this table </p>
  
  <pre><code>    uname   sid usage
  0   Ahmad   a   5
  1   Ahmad   a   7
  2   Ahmad   a   10
  3   Ahmad   b   2
  4   Mohamad c   6
  5   Mohamad c   7
  6   Mohamad c   9
  </code></pre>
  
  <p>I want to group by uname and side, and have usage column =  <code>group.max</code> - <code>group.min</code>. But if group count is <code>1</code> return group <code>max</code> </p>
  
  <p>the out put should be </p>
  
  <pre><code>    uname   sid usage
  0   Ahmad   a   5
  1   Ahmad   b   2
  2   Mohamad c   3    
  </code></pre>