Session Ready
Exercise

Most frequent words

In the previous exercise, we created a list of words called filtered_words.

Now we will define a count_words() function to turn the word list into a dictionary of words and word counts.

To accomplish this, we will use a dictionary comprehension.

Dictionary comprehensions create key-value pairs from an iterable.

In this case, the iterable is the word list, the dictionary keys are words, and the values are the word counts.

After we create the dictionary, we will use turn it into a pandas DataFrame, so that we can use a series of methods to

  • sort the word counts
  • obtain the top 5 most frequent words
  • create a horizontal bar plot
  • remove the y axis label

The bar plot will show the frequency of the top words in the diabetes dataset.

Instructions
100 XP
  • Complete the dictionary comprehension inside the count_words() function definition.
  • Create the dictionary of words and word counts from the filtered_words variable that we created in the previous exercise.