liveBook · Manning

JSON

As explained in Pandas Workout: 200 exercises to make you a stronger data analyst

JSON is a text-based data-interchange format representing structured values such as arrays, objects, strings, numbers, and Boolean values.

JSON (JavaScript Object Notation) stores numbers, text, lists, and dictionaries in a readable, writable text format. It is smaller than XML, more expressive than CSV, and widely used for cross-platform internet APIs. section 3.20

A particularly useful shape is an array of objects—the Python equivalent of a list of dictionaries. With pandas, pd.read_json turns each object into a record and its keys into DataFrame columns. section 3.21

A small JSON-powered analysis can proceed as follows:

  • Load data about the 1,000 largest United States cities with pd.read_json. section 3.20
  • Compare mean and median populations with describe; the mean of 131,132 exceeds the median of 68,207 because a few large cities pull it upward. section 3.21
  • Remove the 50 largest cities with loc and recompute the values: the mean falls to 87,027, while the median falls to 65,796. section 3.21
  • Use maximum latitude to locate the northernmost city, then count state values to compare representation. section 3.21
df['population'].describe()[['mean', '50%']]

Inspect the compact pandas expression that selects mean and median population statistics. section 3.21

How Pandas Workout: 200 exercises to make you a stronger data analyst covers it

How deep it goes
Explains JSON’s main value types and array-of-object structure, then stops at pandas import and analysis rather than syntax details.
Examples
Uses a 1,000-city JSON dataset to compare population statistics, exclude large cities, find latitude extremes, and count states.
What it assumes
Assumes familiarity with pandas DataFrames and Python list-dictionary structures while explaining JSON records from that analogy.
What you can do after
Apply it via pandas to load structured JSON records and analyze the resulting DataFrame.
How it connects
Connects JSON with CSV, XML, internet APIs, Python lists and dictionaries, and pandas DataFrames.

Also explained in

Compare how 35 books explain JSON →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Pandas Workout: 200 exercises to make you a stronger data analyst. The section links point to the parts of the book it draws on.