SpaceX & Wine: Reshaping Nested Data

We often encounter nested data, including in json files or dataframes with nested data columns. Today, we’ll walk through a couple of examples of how to read and reshape nested data.

In the 1st example, we’ll work with a complex json file of SpaceX launches that includes a nested list of dictionaries within a list of dictionaries. We’ll set up the json_normalize function with the arguments record_path and meta, as well as set the index and data types to get a usable dataframe at the end.

In the 2nd example, we’ll work with a manually created dataframe of 10 of my favorite wines from the past few years that includes a column of dictionaries, including variety, region, country, and vintage. We’ll walk through two methods to flatten out the dictionaries to get the dataframe of all the wine info we want. The purpose of this is to demonstrate how to read and reshape common types of nested data to create usable dataframes for further analysis.

Leave a Reply

Discover more from crawstat.

Subscribe now to keep reading and get access to the full archive.

Continue reading