rebeccajohnson88 / PPOL564_slides_activities

Repo for Georgetown McCourt's School of Public Policy's Data Science I (PPOL 564)
Creative Commons Zero v1.0 Universal
9 stars 13 forks source link

1.1 #67

Closed sonali-sr closed 1 year ago

sonali-sr commented 1 year ago

1. Write a wrapper function to pull data from the NAEP API (12 points)

In the class activity here: https://github.com/rebeccajohnson88/PPOL564_slides_activities/blob/main/activities/fall_22/solutions/10_apis_naep_yelp_solutions.ipynb

We practiced pulling from the API for the National Assessment of Educational Progress (NAEP), "America's report card" of test scores. We pulled a small amount of data at the national level (writing scores by gender) using a query where the parameters were hardcoded. In this problem, we'll practice pulling a larger set of data at the state level and writing a wrapper function. As a reminder, the documentation for the NAEP API is here: https://www.nationsreportcard.gov/api_documentation.aspx The base link for writing queries is: https://www.nationsreportcard.gov/Dataservice/GetAdhocData.aspx

1.1 Write a query to pull 8th-grade mathematics scores in 2015 from the state of California (CA) by gender (1 point)

Print the output in dataframe format and briefly interpret; what do scores look like between the genders?

1 1
sonali-sr commented 1 year ago

Hi @jianing-gong , This can be solved by saving the 'result' part of naep_resp.json() into a variable, and then using that variable in the pd.DataFrame code.

rebeccajohnson88 commented 1 year ago
Screen Shot 2022-11-21 at 12 13 12 PM

I was wondering why my output form is so different...

The issue is that you're creating a dataframe from the full json rather than the results key of the json. See here for some example code from our class activity! https://github.com/rebeccajohnson88/PPOL564_slides_activities/blob/main/activities/fall_22/solutions/10_apis_naep_yelp_solutions.ipynb

See here:

resp_j = resp.json()
resp_df = pd.DataFrame(resp_j['result'])
return(resp_df)
jianing-gong commented 1 year ago

Yes I just realized… thank you Sonali!

On Mon, Nov 21, 2022 at 12:25 PM Rebecca Johnson @.***> wrote:

[image: Screen Shot 2022-11-21 at 12 13 12 PM] https://user-images.githubusercontent.com/115057160/203118439-0a1359ea-e195-4b4d-8ea0-2c2d25e7161c.png

I was wondering why my output form is so different...

The issue is that you're creating a dataframe from the full json rather than the results key of the json. See here for some example code from our class activity! https://github.com/rebeccajohnson88/PPOL564_slides_activities/blob/main/activities/fall_22/solutions/10_apis_naep_yelp_solutions.ipynb

See here:

resp_j = resp.json() resp_df = pd.DataFrame(resp_j['result']) return(resp_df)

— Reply to this email directly, view it on GitHub https://github.com/rebeccajohnson88/PPOL564_slides_activities/issues/67#issuecomment-1322409900, or unsubscribe https://github.com/notifications/unsubscribe-auth/A3N2ECDFKMFB6UCWO2TRWELWJOWBNANCNFSM6AAAAAARZ4W7VA . You are receiving this because you were mentioned.Message ID: @.*** com>