Classwork 9
Collecting Data with Python requests and APIs
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:
- U.S. Real GDP (
series_id="GDPC1") - 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:
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!