title: Pandas: join with outer product
body: <p>I want to multiply a lookup table (<code>demand</code>), given for multiple commodities (here: Water, Elec) and area types (Com, Ind, Res) with a DataFrame (<code>areas</code>) that is a table of areas for these area types.</p>
  
  <pre><code>import pandas as pd
  areas = pd.DataFrame({'Com':[1,2,3], 'Ind':[4,5,6]})
  demand = pd.DataFrame({'Water':[4,3], 
                         'Elec':[8,9]}, index=['Com', 'Ind'])
  </code></pre>
  
  <p>Before:</p>
  
  <pre><code>areas
     Com  Ind
  0    1    4
  1    2    5
  2    3    6
  
  demand
       Elec  Water
  Com     8      4
  Ind     9      3
  </code></pre>
  
  <p>After:</p>
  
  <pre><code>area_demands                  
       Com          Ind         
       Elec  Water  Elec  Water 
  0       8      4    36     12 
  1      16      8    45     15 
  2      24     12    54     18 
  </code></pre>
  
  <p><strong>My attempt</strong></p>
  
  <p>Verbose and incomplete; does not work for arbitrary number of commodities.</p>
  
  <pre><code>areas = pd.DataFrame({'area': areas.stack()})
  areas.index.names = ['Edge', 'Type']
  both = areas.reset_index(1).join(demand, on='Type')
  both['Elec'] = both['Elec'] * both['area']
  both['Water'] = both['Water'] * both['area']
  del both['area']
  # almost there; it must be late, I fail to make 'Type' a hierarchical column...
  </code></pre>
  
  <p>Almost there:</p>
  
  <pre><code>     Type  Elec  Water
  Edge
  0     Com     8      4
  0     Ind    36     12
  1     Com    16      8
  1     Ind    45     15
  2     Com    24     12
  2     Ind    54     18
  </code></pre>
  
  <p><strong>In short</strong></p>
  
  <p>How to join/multiply the DataFrames <code>areas</code> and <code>demand</code> together in a decent way?</p>