title: How to subtract values in one column based on values in another column
body: <p>I am trying to manipulate a pandas DataFrame that has 2 columns, <code>Type</code> and <code>Value</code>:</p>
  
  <pre><code>type    value
  -------------
    1     100
    2       1
    3       1
    4       1
    1     300
    2       1
    3       1  
    4       1
    1     500
    2       1
    3       1
    4     700
  </code></pre>
  
  <p>I want to create a new column, difference, which would be the product of subtracting the value from the the previous value, only for type == 1. (so 300-100, 500-300, 700-500)</p>
  
  <p>One option is by coping the selected celes to a new df </p>
  
  <pre><code>new = df[df['type'].isin(['1'])]
  </code></pre>
  
  <p>do the subtraction and join the dfs again. but is there a better way of doing with out having to move to a new df?</p>