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!
This exercise is part of the course
Reshaping Data with pandas
Exercise instructions
- Import the
json_normalize()
function frompandas
. - 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 thedirector
andproducer
columns as unique indexes. Name the new variable created from the columnsmovies
, starting withfeatures
, separated by an underscore with a suffix containing words.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# 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)