title: Pandas reduce number of categorical variables in value_counts() tabulation
body: <p>New to pandas I want to perform something similar to <a href="https://stackoverflow.com/questions/39066382/reduce-number-of-levels-for-large-categorical-variables?noredirect=1#comment65482577_39066382">Reduce number of levels for large categorical variables</a> (binning of categorical variables in order to reduce their levels)
  The following code works fine in R</p>
  
  <pre><code>DTsetlvls &lt;- function(x, newl)  
     setattr(x, "levels", c(setdiff(levels(x), newl), rep("other", length(newl))))
  </code></pre>
  
  <p>My dataframe:</p>
  
  <pre><code>df = pd.DataFrame({'Color': 'Red Red Blue'.split(),
                     'Value': [100, 150, 50]})
  
  df['Counts'] = df.groupby('Color')['Value'].transform('count')
  print (df)
  
    Color  Value  Counts
  0   Red    100       2
  1   Red    150       2
  2  Blue     50       1
  </code></pre>
  
  <p>I manually would create an aggregate column and then based on that, label the less frequent groups e.g. "blue" as a single "other" group.
  But compared to the concise R code this seems clumsy. What would be the right approach here?</p>