title: Pandas: apply a function with 2 array as input and return a single value
body: <p>I have a pandas DataFrame with hierarchical column names like this</p>
  
  <pre><code>import pandas as pd
  import numpy as np
  
  np.random.seed(1542)
  
  dates = pd.date_range('29/01/17', periods = 6)
  
  pd.DataFrame(np.random.randn(6,6), index = dates,\
               columns = [['g1', 'g1', 'g1', 'g2', 'g2', 'g2'],\
                          ['c1', 'c2', 'c3', 'c1', 'c2', 'c3']])
  </code></pre>
  
  <p>And I want to apply a function that, for each group in the first level of columns, takes the columns 'c2' and 'c3' and returns a single value.</p>
  
  <p>An example of the function (that in the real case is more complex) can be</p>
  
  <pre><code>def function(first_column, second_column):
      return(max(first_column) - max(second_column))
  </code></pre>
  
  <p>When I apply it to my DataFrame I want to have back a DataFrame that tells me the output of 'function' for each group, so, in this case, just 2 numbers for 'g1' and 'g2'.</p>
  
  <p><strong>Note that I want it to works also in case of gorupby()</strong> so that, in this case, I get the result of the function for each group ('g1' and 'g2') and for each groupby subset.</p>
  
  <p>For the case above, if I want to aggregate by month, the result should be:</p>
  
  <pre><code>         g1      g2                    
  1  0.909464     1.638375
  2  0.698515     0.33819
  </code></pre>