JSON is a readable, compact format for exchanging numbers, text, lists, and dictionaries. pandas uses read_json to turn JSON data into a DataFrame, especially when APIs or files provide an array of records. section 3.20 section 3.21
A practical city-data exercise uses the imported DataFrame to:
- Compare mean and median populations, then remove the 50 largest cities and compare them again. section 3.20 section 3.21
- Find the northernmost city by locating the maximum latitude, then select its city, state, and rank. section 3.21
- Count cities by state with value_counts and inspect the largest or smallest counts. section 3.20 section 3.21
df['population'].describe()[['mean', '50%']]
Summarizes population statistics by selecting the mean and median from describe. section 3.21
df.loc[50:, 'population'].describe()[['mean', '50%']]
Repeats the summary after slicing away the first 50 indexed rows with loc. section 3.21
df.loc[df['latitude'] == df['latitude'].max(), ['city', 'state', 'rank']]
Finds rows at the maximum latitude and returns the identifying city fields. section 3.21
