title: Replace values in df col - pandas
body: <p>I'm aiming to replace values in a df column <code>Num</code>. Specifically:</p>
  <ul>
  <li>where <code>1</code> is located in <code>Num</code>, I want to replace preceding 0's with <code>1</code> until the nearest <code>Item</code> is <code>1</code> working backwards or backfilling.</li>
  <li>where <code>Num == 1</code>, the corresponding row in <code>Item</code> will always be 0.</li>
  <li>Also, <code>Num == 0</code> will always follow <code>Num == 1</code>.</li>
  </ul>
  <p>Input and code:</p>
  <pre><code>df = pd.DataFrame({
              'Item' : [0,1,2,3,4,4,0,1,2,3,1,1,2,3,4,0],
              'Num' :  [0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0]
               })
  
  df['Num'] = np.where((df['Num'] == 1) &amp; (df['Item'].shift() &gt; 1), 1, 0) 
  
      Item  Num
  0      0    0
  1      1    0
  2      2    0
  3      3    0
  4      4    0
  5      4    1
  6      0    0
  7      1    0
  8      2    0
  9      3    0
  10     1    0
  11     1    0
  12     2    0
  13     3    0
  14     4    1
  15     0    0
  </code></pre>
  <p>intended output:</p>
  <pre><code>    Item  Num
  0      0    0
  1      1    1
  2      2    1
  3      3    1
  4      4    1
  5      4    1
  6      0    0
  7      1    0
  8      2    0
  9      3    0
  10     1    0
  11     1    1
  12     2    1
  13     3    1
  14     4    1
  15     0    0
  </code></pre>