ComeçarComece de graça

Nested movies

You are curious about a movies dataset you've had on your computer for some time now that contains data about different movies. You would like to analyze that data, but you realize it's in a nested JSON format.

To read it into a DataFrame, you will need to use the function you have just learned. After that, you will reshape the resulting DataFrame to make it easier to work with.

The semi-structured JSON named movies is available for you. Make sure to examine it in the console!

Este exercício faz parte do curso

Reshaping Data with pandas

Ver curso

Instruções do exercício

  • Import the json_normalize() function from pandas.
  • Normalize the JSON contained in movies. Separate the names generated from nested records with an underscore.
  • Reshape the resulting movies_norm DataFrame from wide to long format, using the director and producer columns as unique indexes. Name the new variable created from the columns movies, starting with features, separated by an underscore with a suffix containing words.

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

# Import the json_normalize function
____

# Normalize movies and separate the new columns with an underscore 
movies_norm = ____(____, sep=____)

# Reshape using director and producer as index, create movies from column starting from features
movies_long = pd.____(____, stubnames=____, 
                      i=____, j=____, 
                      sep=____, suffix=____)

# Print movies_long
print(movies_long)
Editar e executar o código