-1

in this dataset

data = pd.DataFrame({'name':["a","c","d","b","a","b","c","a","c","d","b","n",
                         "m""b","b","c","a","c","d","b","a","b","b","b","c",
                         "a","c","d","b","a","b","b","b","c","a","c","d","b","a","b","b","b","c"]})

I want to count the number of each name and drop names that are repeated less than 2 times.

nemo92world
  • 101
  • 8

2 Answers2

2

One approach is using filters:

data.groupby('name').filter(lambda x : len(x)>1)
1

You can use map and value_counts functions as follows:

   only_duplicates = data[data['name'].map(data['name'].value_counts()) > 1]
Baruch Gans
  • 1,415
  • 1
  • 10
  • 21