Classwork 9

Collecting Data with Python requests and APIs

Author

Byeong-Hak Choe

Published

March 6, 2026

Modified

March 6, 2026

Question 1

Provide a Python code to get New York City air quality surveillance data using the following API endpoint:

https://data.cityofnewyork.us/resource/c3uy-2p5r.json

  • Use the following query parameter dictionary in your request, which sets the β€œ$limit” to control how many rows are returned:
# query parameters (e.g., limit rows)
param_dict = {
    "$limit": 100   # You can increase this to get more observations
}

Answer:



Question 2

Use a for-loop, requests, and the FRED API to retrieve two macroeconomic indicators:

  1. U.S. Real GDP (series_id = "GDPC1")
  2. U.S. Unemployment Rate (series_id = "UNRATE")

Store them into one single DataFrame called df_all.

The df_all DataFrame contains both FRED series ids for (1) U.S. Real GDP (series_id = "GDPC1") and (2) U.S. Unemployment Rate (series_id = "UNRATE"), and has three columns as shown below:

Note

df_all = df_all[ ['date', 'value', 'series'] ] means:

  • β€œkeep only these columns, and relocate them in this order.”

Answer:



Discussion

Welcome to our Classwork 9 Discussion Board! πŸ‘‹

This space is designed for you to engage with your classmates about the material covered in Classwork 9.

Whether you are looking to delve deeper into the content, share insights, or have questions about the content, this is the perfect place for you.

If you have any specific questions for Byeong-Hak (@bcdanl) regarding the Classwork 9 materials or need clarification on any points, don’t hesitate to ask here.

All comments will be stored here.

Let’s collaborate and learn from each other!

Back to top