title: Pandas-Update previous and next rows value based on current row value group by Id
body: <p>I have dataframe, df and want to change the value in column 'Status' for each 'Id'</p>
  
  <p>The rule is:
  If 'Status' == 'High' update rows before to 'Before' Else 'After'</p>
  
  <p>The dataframe, df:</p>
  
  <pre><code>     Id     Status    
  0    1      Low
  1    1      Low
  2    1      High
  3    1      Low
  4    2      Low
  5    2      Low
  6    2      High
  7    2      Low
  8    3      Low
  9    3      Low
  10   3      High
  11   3      Low
  12   3      High
  13   3      Low
  </code></pre>
  
  <p>My expected df:</p>
  
  <pre><code>     Id     Status
   0   1      Before
   1   1      Before
   2   1      High
   3   1      After
   4   2      Before
   5   2      Before
   6   2      High
   7   2      After
   8   3      Before
   9   3      Before
  10   3      High
  11   3      After
  12   3      High
  13   3      After 
  </code></pre>
  
  <p>This is my code so far, (I have not added the rule else change to 'After' yet)</p>
  
  <pre><code>df.loc[df.groupby(['Id'])['Status'] == "High", df['Status'].shift(1)] = 'Before'
  </code></pre>
  
  <p>I got an error:</p>
  
  <pre><code>ValueError: cannot index with vector containing NA / NaN values
  </code></pre>