Exercise

Filtering Dask bags

The politician data you are working with comes from different sources, so it isn't very clean. Many of the dictionaries are missing keys that you may need to run your analysis. You will need to filter out the elements with important missing keys.

A function named has_birth_date() is available in the environment. It checks the input dictionary to see if it contains the key 'birth_date'. It returns True if the key is in the dictionary and False if not.

def has_birth_date(dictionary):
  return 'birth_date' in dictionary

The bag you created in the last exercise is available in your environment as dict_bag.

Instructions

100 XP
  • Use dict_bag's .count() method to print out the number of elements it contains.
  • Use the has_birth_date() function to filter out the elements which do not have the 'birth_date' key.
  • Print out the number of elements filtered_bag contains.