Load JSON data
Many open data portals make available JSONs datasets that are particularly easy to parse. They can be accessed directly via URL. Each object is a record, all objects have the same set of attributes, and none of the values are nested objects that themselves need to be parsed.
The New York City Department of Homeless Services Daily Report is such a dataset, containing years' worth of homeless shelter population counts. You can view it in the console before loading it to a dataframe with pandas
's read_json()
function.
This exercise is part of the course
Streamlined Data Ingestion with pandas
Exercise instructions
- Get a sense of the contents of
dhs_daily_report.json
, which are printed in the console. - Load
pandas
aspd
. - Use
read_json()
to loaddhs_daily_report.json
to a dataframe,pop_in_shelters
. - View summary statistics about
pop_in_shelters
with the dataframe'sdescribe()
method.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Load pandas as pd
____
# Load the daily report to a dataframe
pop_in_shelters = ____
# View summary stats about pop_in_shelters
print(____)