title: How to use groupby and cumcount on unique names in a Pandas column
body: <p>I have a dataframe that looks like this</p>
  
  <pre><code> ID ..... config_name    config_version  ...  
   aa           A                0         
   ab           A                7
   ad           A                7
   ad           A                27   
   bb           B                0     
   cc           C                0      
   cd           C                8 
  </code></pre>
  
  <p>I want to groupby config_name and apply cumcount on each unique config_version so that I get an additional column like </p>
  
  <pre><code> ID ..... config_name    config_version     config_version_count 
   aa           A                0                     0        
   ab           A                7                     1
   ad           A                7                     1  
   ad           A                27                    2 
   bb           B                0                     0
   cc           C                0                     0
   cd           C                8                     1
  </code></pre>
  
  <p>But I can't seem to understand how to do it.</p>
  
  <p>I tried using </p>
  
  <pre><code>      unique_count = df.groupby('config_name')['config_version'].cumcount()
        unique_count = pd.DataFrame({'config_name': [unique_count.index], 'config_version_count: [unique.count.values]})
        df = pd.merge(df,unique_count, on = 'config_name' , how = 'left')
  </code></pre>
  
  <p>Which gives the following output </p>
  
  <pre><code> ID ..... config_name    config_version     config_version_count 
   aa           A                0                     0        
   ab           A                7                     1
   ad           A                7                     2  
   ad           A                27                    3 
   bb           B                0                     0
   cc           C                0                     0
   cd           C                8                     1
  </code></pre>
  
  <p>I also tried </p>
  
  <pre><code> unique_count = df.drop_duplicates().groupby('config_name')['config_version'].cumcount()
    unique_count.reindex(df.index).ffill()
    df['config_version_count'] = unique_count
  </code></pre>
  
  <p>But this gives the same output as the first try.</p>
  
  <p>Any idea how I could do this?</p>