title: Calculations on a pandas DataFrame column conditional on another column
body: <p>I notice several 'set value of new column based on value of another'-type questions, but from what I gather, I have not found that they address dividing values in the <strong>same</strong> column, based on the conditions set by another column.</p>
  <p>The data I have is as the table below, minus the column (variable) 'healthpertotal'.</p>
  <ol>
  <li>It shows (in the column 'function'), the amount of government spending (aka expenditure) on<br />
  a) health (column 'value'), and<br />
  b) its total spending (same column 'value'), and</li>
  <li>the associated year of that spending (column 'year').</li>
  </ol>
  <p>I want to make a new column that shows the percent of government health spending over its total spending, for a given year, as shown below in the column 'healthpertotal'.</p>
  <p>So for instance, in 1995, the value of this variable is (42587(health spending amount)/326420(total spending amount))*100=13.05.</p>
  <p>As for the rows showing total spending, the 'healthpertotal' could be 'missing', 1, or 'not applicable' and the like. I am ok with any of these options.</p>
  <p>How would I set up this new column 'healthpertotal' using python?</p>
  <p>A proposed table or DataFrame for what I would like to achieve follows (and its code on how it might be set up - artificially 'forced' in the case of the final variable 'healthpertotal') :</p>
  <pre><code>data = {'function':['Health'] * 3 + ['Total'] * 3,
          'year':[1995,1996,1997,1995,1996,1997],
          'value':[42587, 44209,44472,326420,333637,340252],
          'healthpertotal':[13.05,13.25,13.07]+[np.nan]*3
          }
  
  df = pd.DataFrame(data)
  
  print (df)
  </code></pre>
  <p>Expected outcome:</p>
  <pre><code>  function  year   value  healthpertotal
  0   Health  1995   42587           13.05
  1   Health  1996   44209           13.25
  2   Health  1997   44472           13.07
  3    Total  1995  326420             NaN
  4    Total  1996  333637             NaN
  5    Total  1997  340252             NaN
  </code></pre>