title: Pandas: GroupBy Shift And Cumulative Sum
body: <p>I want to do <code>groupby</code>, <code>shift</code> and <code>cumsum</code> which seems pretty trivial task but still banging my head over the result I'm getting. Can someone please tell what am I doing wrong. All the results I found online shows the same or the same variation of what I am doing. Below is my implementation.</p>
  
  <pre><code>temp = pd.DataFrame(data=[['a',1],['a',1],['a',1],['b',1],['b',1],['b',1],['c',1],['c',1]], columns=['ID','X'])
  
  temp['transformed'] = temp.groupby('ID')['X'].cumsum().shift()
  print(temp)
  
     ID   X   transformed
  0   a   1   NaN
  1   a   1   1.0
  2   a   1   2.0
  3   b   1   3.0
  4   b   1   1.0
  5   b   1   2.0
  6   c   1   3.0
  7   c   1   1.0
  </code></pre>
  
  <p>This is wrong because the actual or what I am looking for is as below:</p>
  
  <pre><code>   ID   X   transformed
  0   a   1   NaN
  1   a   1   1.0
  2   a   1   2.0
  3   b   1   NaN
  4   b   1   1.0
  5   b   1   2.0
  6   c   1   NaN
  7   c   1   1.0
  </code></pre>
  
  <p>Thanks a lot in advance.</p>