title: Updating non-unique key in pandas
body: <p>I have a dataframe that I want to insert into a <code>mysql</code> database. Before inserting it, I need to fill in NA values in a column containing a non-unique key. The filled in values need to be shared across groups, but cannot overlap with any preexisting values in the sql table.</p>
  
  <p>Assuming that the maximum key value in the table is 5. I would need:</p>
  
  <pre><code>id    group    key
   1      A       1
   2      A       1
   3      B       NA
   4      B       NA
   5      C       2
   6      D       NA
  </code></pre>
  
  <p>To become:</p>
  
  <pre><code>id    group    key
   1      A       1
   2      A       1
   3      B       6
   4      B       6
   5      C       2
   6      D       7
  </code></pre>