title: Pandas: how to efficiently filter data based on their frequency
body: <p>I have a data-frame  with three columns, follower, user, and ratio.</p>
  <p>For every unique element in u, I would like to know how many times, it occurred and remove the rows corresponding to elements that occur less than say 5 times. Here is my code, it is inefficient. I would like to know how to properly write it.</p>
  <pre><code>known_follower_id= np.unique(following_df.follower.values) # IDs of members of the list in the saved database
  userid, counts = np.unique(following_df.user.values, return_counts= True) # ID of people they followed in the saved database
  count_idx=np.argsort(-counts) # number of times a user was followed
  trimmed_following_df= following_df.copy(deep= True)
  
  th = 5
  idx_th = counts&lt; th
  
  userid_removed = userid[idx_th]
  idx_userid_rem= [i for i,v in enumerate(trimmed_following_df.user.values) if v in userid_removed]
  
  trimmed_following_df=trimmed_following_df.drop(idx_userid_rem)
  </code></pre>