title: performing differences between rows in pandas based on columns values
body: <p>I have this dataframe, I'm trying to create a new column where I want to store the difference of products sold based on code and date.
  for example this is the starting dataframe:</p>
  
  <pre><code>      date     code sold
  0   20150521    0   47
  1   20150521    12  39
  2   20150521    16  39
  3   20150521    20  38
  4   20150521    24  38
  5   20150521    28  37
  6   20150521    32  36
  7   20150521    4   43
  8   20150521    8   43
  9   20150522    0   47
  10  20150522    12  37
  11  20150522    16  36
  12  20150522    20  36
  13  20150522    24  36
  14  20150522    28  35
  15  20150522    32  31
  16  20150522    4   42
  17  20150522    8   41
  18  20150523    0   50
  19  20150523    12  48
  20  20150523    16  46
  21  20150523    20  46
  22  20150523    24  46
  23  20150523    28  45
  24  20150523    32  42
  25  20150523    4   49
  26  20150523    8   49
  27  20150524    0   39
  28  20150524    12  33
  29  20150524    16  30
  ... ... ... ...
  150 20150606    32  22
  151 20150606    4   34
  152 20150606    8   33
  153 20150607    0   31
  154 20150607    12  30
  155 20150607    16  30
  156 20150607    20  29
  157 20150607    24  28
  158 20150607    28  26
  159 20150607    32  24
  160 20150607    4   30
  161 20150607    8   30
  162 20150608    0   47
  </code></pre>
  
  <p>I think this could be a solution...</p>
  
  <pre><code>  full_df1=full_df[full_df.date == '20150609'].reset_index(drop=True)
      full_df1['code'] = full_df1['code'].astype(float)
      full_df1= full_df1.sort(['code'], ascending=[False])
  
      code date      sold
  8   32  20150609    33  
  7   28  20150609    36  
  6   24  20150609    37  
  5   20  20150609    39  
  4   16  20150609    42  
  3   12  20150609    46  
  2   8   20150609    49  
  1   4   20150609    49  
  0   0   20150609    50  
  
  
  
  
  
    full_df1.set_index('code')['sold'].diff().reset_index()   
  </code></pre>
  
  <p>that gives me back this output for a single date  20150609 :</p>
  
  <pre><code>    code difference
  0   32  NaN
  1   28  3
  2   24  1
  3   20  2
  4   16  3
  5   12  4
  6   8   3
  7   4   0
  8   0   1
  </code></pre>
  
  <p>is there a better solution to have the same result in a more pythonic way?
  I would like to create a new column [difference] and store the data there having as result 4 columns [date, code, sold, difference]</p>