title: Shift rows in a pandas df
body: <p>I am trying to <code>shift</code> values in a <code>pandas df</code>. Specifically, <code>rows</code> that follow a specific <code>value</code>. For the <code>df</code> below I want to <code>shift</code> the <code>row</code> to the left when the above value is <code>== 'X'</code>.</p>
  
  <pre><code>d = ({
      'A' : ['Foo','','Foo',''],           
      'B' : ['X','Bar','X','Bar'],
      'C' : ['','Y','','Y'],
      })
  
  df = pd.DataFrame(data=d)
  </code></pre>
  
  <p>Out:</p>
  
  <pre><code>     A    B  C
  0  Foo    X   
  1       Bar  Y
  2  Foo    X   
  3       Bar  Y
  </code></pre>
  
  <p>I have tried this:</p>
  
  <pre><code>b = ['X']
  x = df.B=='X'
  df.loc[x, b] = df.loc[x, b].apply(lambda x: x.shift(-1), axis=1)
  </code></pre>
  
  <p>Intended Output:</p>
  
  <pre><code>     A  B C
  0  Foo  X  
  1  Bar  Y  
  2  Foo  X  
  3  Bar  Y
  </code></pre>
  
  <p>Whilst these <code>strings</code> are identical my dataset varies. <code>Foo</code> will be the same but the <code>string</code> that follows <code>X</code> will vary. So I can't just select <code>Bar</code> and <code>shift</code> <code>row</code> left. I need something that finds the <code>row</code> below <code>X</code> and shifts left</p>