title: apply a function to a pandas Dataframe whose returned value is based on other rows
body: <p>I have a Dataframe looking like this:</p>
  
  <pre><code>&gt;&gt;&gt; import pandas
  &gt;&gt;&gt; df = pandas.DataFrame({'region' : ['east', 'west', 'south', 'west',
  ...  'east', 'west', 'east', 'west'],
  ...  'item' : ['one', 'one', 'two', 'three',
  ...         'two', 'two', 'one', 'three'],
  ...         'quantity' : [3,3,4,5,12,14,3,8], "price" : [50,50,12,35,10,10,12,12]})
  &gt;&gt;&gt; df
      item  price  quantity region
  0    one     50         3   east
  1    one     50         3   west
  2    two     12         4  south
  3  three     35         5   west
  4    two     10        12   east
  5    two     10        14   west
  6    one     12         3   east
  7  three     12         8   west
  </code></pre>
  
  <p>and what I want to do is modify the values in the quantity column. Each new quantity value is caculated based on the number of different regions that exist for this row's combination of item, and price. More concretly I want to take each quantity and multiply it by the weight of it's region returned by a function I wrote that takes a region and the list of other region composing the pool:</p>
  
  <p><code>region_weight(region, list_of_regions)</code>. For this imaginary situation, let's say:</p>
  
  <ul>
  <li>region east is worth 1</li>
  <li>region west is worth 2</li>
  <li>south worth is worth 3</li>
  </ul>
  
  <p>Then the returned weight of east in the pool east, west is 0.3333333333333333 (1/3). The weight of south in pool east, west, south is 0.5 (1/2).</p>
  
  <p>So for the first row, we look at what other rows there are of item one and price 50. There are 2 one with east and one with the west region. The new quantity in the first row would be: 3 * <code>region_weight("east", ["east", "west"])</code>  or 3 * 0.3333333333333333.</p>
  
  <p>I want to apply the same process to the whole quantity column. I don't know how to approach this problem with the pandas library other than looping through the Dataframe row by row.</p>