Skip to content

Baby Names Solution


babynames.value_counts().loc[['Chad', 'Ruger', 'Zeltron']]
# Chad       4
# Ruger      7
# Zeltron    3
# dtype: Int64

Explanation

The trick here is to use the Series value_counts() method to get the count of each unique element in the Series.

babynames.value_counts()
# Ruger          7
# Phreddy        4
# Chad           4
# Jathonathon    3
# Zeltron        3
# Ryan           3
# Mister         1
# dtype: Int64

This results in another Series, so we can chain it with .loc passing in a list of the indices we want to retrieve.

babynames.value_counts().loc[['Chad', 'Ruger', 'Zeltron']]
# Chad       4
# Ruger      7
# Zeltron    3
# dtype: Int64