title: summarizing multiindex pandas dataframe
body: <p>With the Sample, the target is:</p>
  
  <blockquote>
    <p>Compute the funtions in each value of <code>'A'</code>, in other words, compute something in all values of the variables in all <code>B</code> values in each <code>A</code> label.:</p>
  </blockquote>
  
  <pre><code>import numpy as np
  import pandas as pd
  
  df = pd.DataFrame({'A' : ['foo', 'bar', 'foo', 'bar',
                                'foo', 'bar', 'foo', 'foo'],
                         'B' : ['one', 'one', 'two', 'three',
                                'two', 'two', 'one', 'three'],
                         'C' : np.random.randn(8),
                         'D' : np.random.randn(8)})
  
  def var1(x): return max(x)-min(x)
  def var2(x): return (max(x)-min(x))/max(x)
  def var3(x): return (max(x)-min(x))/ len(x)
  
  df = df.groupby(['A','B']).agg({'C': var1, 'D': [var2, var3]})
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/JE6BJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JE6BJ.png" alt="output"></a></p>
  
  <h1>Target</h1>
  
  <p>The Output would look like this:</p>
  
  <pre><code>A           var1        var2        var3        
  bar         0.000000    -0.000000   0.000000
  foo         1,008986    -0.8572265  0.3015905
  </code></pre>
  
  <p>functions like:</p>
  
  <pre><code>def var1(x): return max(x)-min(x)
  def var2(x): return (max(x)-min(x))/max(x)
  def var3(x): return (max(x)-min(x))/ len(x)
  def mean(numbers):
      return float(sum(numbers)) / max(len(numbers), 1)
  </code></pre>
  
  <h1> </h1>