json_normalize()
noun
say it: “JAY-sun NOR-muh-lyze” /ˈdʒeɪsən ˈnɔrməˌlaɪz/
A pandas function that flattens nested data, such as records with lists inside them, into a plain table with one row per inner item.
What does json_normalize() do in pandas?
json_normalize() (pd.json_normalize) turns nested JSON data, records with lists inside them, into a flat
table. record_path names the inner list whose items become rows, and meta names the outer fields copied onto each
of those rows. It takes Python data, so the file is read with json.load first.
import json
import pandas as pd
with open("reviews.json") as f:
data = json.load(f)
reviews = pd.json_normalize(data, record_path="reviews", meta=["vendor_id", "vendor_name"])
In a sentence
- “json_normalize() made one row for each review and copied the vendor's ID onto it.”
- “Without meta, json_normalize() gave the reviews but not whose they were.”
Level: Freelancer · More Python terms at this level
Updated