LoslegenKostenlos loslegen

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!

Diese Übung ist Teil des Kurses

Reshaping Data with pandas

Kurs anzeigen

Anleitung zur Übung

  • 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.

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# 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)
Code bearbeiten und ausführen