title: Replace certain values depending on condition in pandas
body: <p>I'm trying to translate the following R code to Python and am stuck because of the row-indexing...</p>
  
  <pre><code>df$col3[index+1] &lt;− df$col2[index] # what he want :col2 in certain index  assign its value to col3 by index increment 1.
  </code></pre>
  
  <p><strong>Fictitiuous example</strong></p>
  
  <pre><code>df = pd.DataFrame({'id' : [1, 1, 1, 2, 2, 3, 4, 4, 4, 4, 5, 5], 
  'id_old' : [1, 1, 2, 2, 3, 4, 4, 4, 4, 5, 5, 5], 
  'col1' : np.random.normal(size = 12), 
  'col2' : np.random.randint(low = 20, high = 50, size = 12), 
  'col3' : np.repeat(20, 12)})
  print(df)
  
  myindex = np.where(df.id != df.id_old) # tuple
  print(myindex)
  print(np.add(myindex, 1))
  replacement_values = df.iloc[myindex][['col2']]
  </code></pre>
  
  <p>Output</p>
  
  <pre><code>    id  id_old      col1  col2  col3
  0    1       1  0.308380    23    20
  1    1       1  1.185646    35    20
  2    1       2 -0.432066    27    20
  3    2       2  0.115055    32    20
  4    2       3  0.683291    34    20
  5    3       4 -1.916321    42    20
  6    4       4  0.888327    34    20
  7    4       4  1.312879    29    20
  8    4       4  1.260612    27    20
  9    4       5  0.062635    22    20
  10   5       5  0.081149    23    20
  11   5       5 -1.872873    32    20
  
  (array([2, 4, 5, 9]),)
  [[ 3  5  6 10]]
  </code></pre>
  
  <p>This is what I tried :</p>
  
  <pre><code>df.loc[np.add(myindex, 1), 'col3'] = replacement_values
  df.loc[df.index.isin(np.add(myindex + 1)), 'col3'] = replacement_values
  </code></pre>
  
  <p>Desired result :</p>
  
  <pre><code>    id  id_old      col1  col2  col3
  0    1       1  0.308380    23    20
  1    1       1  1.185646    35    20
  2    1       2 -0.432066    27    20
  3    2       2  0.115055    32    27
  4    2       3  0.683291    34    20
  5    3       4 -1.916321    42    34
  6    4       4  0.888327    34    42
  7    4       4  1.312879    29    20
  8    4       4  1.260612    27    20
  9    4       5  0.062635    22    20
  10   5       5  0.081149    23    22
  11   5       5 -1.872873    32    20
  </code></pre>
  
  <p>I guess I'm overlooking something basic, or am I completely on the wrong path?</p>
  
  <p>Thanks a lot for your help!</p>