title: Vectorized way of using the previous row value based on the condition
body: <p>I have a pandas dataframe as below. I want to perform the below condition:
  if Column 'A' is 1 then update the value of column 'F' with the previous value of 'F'. This can be done row by row iteration but it is not efficient way of doing that. I want a vectorized method of doing that.</p>
  
  <pre><code>df = pd.DataFrame({'A':[1,1,1, 0, 0, 0, 1, 0, 0], 'C':[1,1,1, 0, 0, 0, 1, 1, 1], 'D':[1,1,1, 0, 0, 0, 1, 1, 1],
  'F':[2,0,0, 0, 0, 1, 1, 1, 1]})
  df
  
      A   C   D   F
  0   1   1   1   2
  1   1   1   1   0
  2   1   1   1   0
  3   0   0   0   0
  4   0   0   0   0
  5   0   0   0   1
  6   1   1   1   1
  7   0   1   1   1
  8   0   1   1   1
  </code></pre>
  
  <p>My desired output:</p>
  
  <pre><code>    A   C   D   F
  0   1   1   1   2
  1   1   1   1   2
  2   1   1   1   2
  3   0   0   0   0
  4   0   0   0   0
  5   0   0   0   1
  6   1   1   1   1
  7   0   1   1   1
  8   0   1   1   1
  </code></pre>
  
  <p>I tried the below code, but it doesnot work because when I use shift, it doesnot take the updated previous row.</p>
  
  <pre><code>df['F'] = df.groupby(['A'])['F'].shift(1)
  df
  
      A   C   D   F
  0   1   1   1   NaN
  1   1   1   1   2.0
  2   1   1   1   0.0
  3   0   0   0   NaN
  4   0   0   0   0.0
  5   0   0   0   0.0
  6   1   1   1   0.0
  7   0   1   1   1.0
  8   0   1   1   1.0
  </code></pre>