ComenzarEmpieza gratis

Converting to DataFrame

You want to make a DataFrame out of the politician JSON data. Now that you have de-nested the data, all you need to do is select the keys to keep as columns in the DataFrame.

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

Este ejercicio forma parte del curso

Parallel Programming with Dask in Python

Ver curso

Instrucciones del ejercicio

  • Complete the select_keys() function so that the keys in the keys_to_keep list are added to the new filtered dictionary and returned.
  • Use the select_keys() function to select the keys ['gender','name', 'birth_date', 'url'] from dict_bag.
  • Convert the filtered bag to a Dask DataFrame.
  • Print the first few rows of the DataFrame.

Ejercicio interactivo práctico

Prueba este ejercicio y completa el código de muestra.

def select_keys(dictionary, keys_to_keep):
  new_dict = {}
  # Loop through kept keys and add them to new dictionary
  for k in ____:
    ____
  return new_dict

# Use the select_keys to reduce to the 4 required keys
filtered_bag = dict_bag.map(____, ____=____)

# Convert the restructured bag to a DataFrame
df = filtered_bag.____

# Print the first few rows of the DataFrame
print(____)
Editar y ejecutar código