Block 53: Parsing JSON into pandas
Convert API JSON responses into DataFrames for analysis.
Concepts
- response.json() to Python dict/list
- pd.DataFrame() from list of dicts
- Normalizing nested JSON: pd.json_normalize()
- Selecting relevant fields
Code Examples
See exercise below.
Exercise
Fetch 50 random user records from randomuser.me. Convert to a DataFrame with name, email, country. Normalize a nested JSON field (e.g., coordinates) into separate columns.
Homework
What challenges arise with deeply nested JSON? How does json_normalize help?