0

Say that we have the pandas table:

+-------+-------------------+
| Name  |       Dog         |
+-------+-------------------+
| Alice | husky             | 
| Bob   | husky             | 
| Chris | pom               | 
| Ferri | malamute          | 
| Bob2  | corgi             | 
| Dave2 | corgi             |
+-------+-------------------+

How do we remove the rows that only have one-entry for "Dog"? For example, this would be the rows with pom, malamute.

+-------+-------------------+
| Name  |       Dog         |
+-------+-------------------+
| Alice | husky             | 
| Bob   | husky             | 
| Bob2  | corgi             | 
| Dave2 | corgi             |
+-------+-------------------+

Thanks!

bobglu
  • 61
  • 5

1 Answers1

1
is_multi = df["Dog"].value_counts() > 1
filtered = df[df["Dog"].isin(is_multi[is_multi].index)]
Riley
  • 2,153
  • 1
  • 6
  • 16