title: Pandas Dataframe: How to create a column of incremental unique value count of another column
body: <p>Consider the sample dataframe ('value' column is of no significance here):</p>
  <pre><code>df = pd.DataFrame({'key':list('AABBBC'), 'value': [1, 2, 3, 4, 5, 6]})
  </code></pre>
  <p><a href="https://i.stack.imgur.com/UrfZ9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UrfZ9.png" alt="df" /></a></p>
  <p>What I want is a column to count the unique value of only the 'key' column, the caveat being value count will be incrementally ascending and the count will only go up if the cell value hasn't appeared in previous rows. So here &quot;A&quot; will be assigned value 1, &quot;B&quot; 2 and &quot;C&quot; 3.</p>
  <p>The desired result looks like this:</p>
  <p><a href="https://i.stack.imgur.com/MAekM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MAekM.png" alt="desired" /></a></p>
  <p>Right now I can only achieve this with a couple of steps:</p>
  <pre><code>df1 = df.drop_duplicates('key').reset_index(drop = True).drop(columns = ['value'])
  df1['count_unique'] = df1.index+1
  
  
  pd.merge(df, df1.set_index(['key']), left_on = ['key'], right_index= True, how = 'left')
  </code></pre>
  <p>It doesn't look very Pythonic and is not the most efficient. Any advice is appreciated.</p>