Challenge: Find the Most Frequent Values in a Column

Learn how to find the most frequent values in columns of a DataFrame.

We'll cover the following

Problem statement

We often need to find the most frequent values in a column. There are multiple ways to perform this operation with Pandas.

In the following exercise, we’ll find the three most frequent values in a column by using the functions and methods that we’ve learned so far. The find_most_frequents function below is designed to find the three most frequent values (in order) of the given column in the sales.

Solution

Write your solution in the specified place and click on “test”.

  • Make sure to uncomment the lines before execution.

  • If we give last_week_sales as input to the find_most_frequents function, the output should be a list that contains the most frequent three values in this column, which is [13, 12, 14].

Get hands-on with 1400+ tech skills courses.