diff --git a/main/analysis.ipynb b/main/analysis.ipynb index 5e333d7..a6b6b4f 100644 --- a/main/analysis.ipynb +++ b/main/analysis.ipynb @@ -10,7 +10,7 @@ "import pandas as pd\n", "import numpy as np\n", "\n", - "from great_schools import get_nearby_schools\n", + "from great_schools import get_nearby_schools, get_demographics\n", "from distance import get_distance\n", "from secret import get_key\n", "from district_score import get_overall_rating" @@ -302,6 +302,7 @@ " \n", " \n", " \n", + " universal-id\n", " state-id\n", " type\n", " level-codes\n", @@ -338,452 +339,247 @@ " \n", " \n", " \n", + " \n", " \n", " \n", " \n", " \n", - " Acton-Boxborough School District\n", - " Acton-Boxborough Regional High School\n", - " 6000505\n", - " public\n", - " h\n", - " 9,10,11,12,UG\n", - " Acton\n", - " MA\n", - " 1720\n", - " Middlesex County\n", - " 42.479694\n", - " -71.458084\n", - " 59\n", - " 9.0\n", - " 2021.0\n", - " (42.479694, -71.458084)\n", - " 21.179084\n", - " 10.393596\n", - " \n", - " \n", - " Blanchard Memorial School\n", - " 6000005\n", - " public\n", - " e\n", - " KG,1,2,3,4,5,6\n", - " Boxborough\n", - " MA\n", - " 1719\n", - " Middlesex County\n", - " 42.482014\n", - " -71.505814\n", - " 59\n", - " 8.0\n", - " 2021.0\n", - " (42.482014, -71.505814)\n", - " 23.513033\n", - " 12.828547\n", - " \n", - " \n", - " C.T. Douglas Elementary School\n", - " 6000020\n", - " public\n", - " e\n", - " KG,1,2,3,4,5,6\n", - " Acton\n", - " MA\n", - " 1720\n", - " Middlesex County\n", - " 42.481873\n", - " -71.471588\n", - " 59\n", - " 6.0\n", - " 2021.0\n", - " (42.481873, -71.471588)\n", - " 21.874635\n", - " 11.087128\n", - " \n", - " \n", - " Luther Conant School\n", - " 6000030\n", - " public\n", - " e\n", - " KG,1,2,3,4,5,6\n", - " Acton\n", - " MA\n", - " 1720\n", - " Middlesex County\n", - " 42.475239\n", - " -71.436340\n", - " 59\n", - " 8.0\n", - " 2021.0\n", - " (42.475239, -71.43634)\n", - " 20.036107\n", - " 9.279210\n", - " \n", - " \n", - " Mccarthy-Towne School\n", - " 6000015\n", - " public\n", - " e\n", - " KG,1,2,3,4,5,6\n", - " Acton\n", - " MA\n", - " 1720\n", - " Middlesex County\n", - " 42.476936\n", - " -71.453590\n", - " 59\n", - " 5.0\n", - " 2021.0\n", - " (42.476936, -71.45359)\n", - " 20.896860\n", - " 10.159317\n", - " \n", - " \n", - " ...\n", - " ...\n", - " ...\n", - " ...\n", - " ...\n", - " ...\n", - " ...\n", - " ...\n", - " ...\n", - " ...\n", - " ...\n", - " ...\n", - " ...\n", - " ...\n", - " ...\n", - " ...\n", - " ...\n", - " ...\n", - " \n", - " \n", - " Winchester School District\n", - " Lynch Elementary School\n", - " 3440020\n", - " public\n", - " p,e\n", - " PK,KG,1,2,3,4,5\n", - " Winchester\n", - " MA\n", - " 1890\n", - " Middlesex County\n", - " 42.460964\n", - " -71.150330\n", - " 464\n", - " 7.0\n", - " 2021.0\n", - " (42.460964, -71.15033)\n", - " 7.607210\n", - " 5.361206\n", - " \n", - " \n", - " Mccall Middle School\n", - " 3440305\n", + " Quincy School District\n", + " Central Middle School\n", + " 2501385\n", + " 2430315\n", " public\n", " m\n", " 6,7,8\n", - " Winchester\n", + " Quincy\n", " MA\n", - " 1890\n", - " Middlesex County\n", - " 42.449566\n", - " -71.134735\n", - " 464\n", - " 7.0\n", - " 2021.0\n", - " (42.449566, -71.134735)\n", - " 6.523996\n", - " 6.308317\n", - " \n", - " \n", - " Muraco Elementary School\n", - " 3440040\n", - " public\n", - " e\n", - " KG,1,2,3,4,5\n", - " Winchester\n", - " MA\n", - " 1890\n", - " Middlesex County\n", - " 42.463272\n", - " -71.131409\n", - " 464\n", - " 9.0\n", - " 2021.0\n", - " (42.463272, -71.131409)\n", - " 7.288029\n", - " 6.293099\n", - " \n", - " \n", - " Vinson-Owen Elementary School\n", - " 3440025\n", - " public\n", - " p,e\n", - " PK,KG,1,2,3,4,5\n", - " Winchester\n", - " MA\n", - " 1890\n", - " Middlesex County\n", - " 42.449741\n", - " -71.175018\n", - " 464\n", - " 9.0\n", - " 2021.0\n", - " (42.449741, -71.175018)\n", - " 7.758212\n", - " 4.359471\n", - " \n", - " \n", - " Winchester High School\n", - " 3440505\n", - " public\n", - " h\n", - " 9,10,11,12\n", - " Winchester\n", - " MA\n", - " 1890\n", - " Middlesex County\n", - " 42.455719\n", - " -71.134201\n", - " 464\n", + " 2170\n", + " Norfolk County\n", + " 42.261284\n", + " -71.011436\n", + " 349\n", " 8.0\n", " 2021.0\n", - " (42.455719, -71.134201)\n", - " 6.883474\n", - " 6.235460\n", + " (42.261284, -71.011436)\n", + " 7.944981\n", + " 19.199411\n", + " \n", + " \n", + " Natick School District\n", + " Brown\n", + " 2501156\n", + " 1980010\n", + " public\n", + " e\n", + " KG,1,2,3,4\n", + " Natick\n", + " MA\n", + " 1760\n", + " Middlesex County\n", + " 42.292339\n", + " -71.384941\n", + " 294\n", + " 7.0\n", + " 2021.0\n", + " (42.292339, -71.384941)\n", + " 16.826936\n", + " 14.194884\n", + " \n", + " \n", + " Wakefield School District\n", + " Dolbeare Elementary School\n", + " 2501667\n", + " 3050005\n", + " public\n", + " e\n", + " KG,1,2,3,4\n", + " Wakefield\n", + " MA\n", + " 1880\n", + " Middlesex County\n", + " 42.518574\n", + " -71.065102\n", + " 424\n", + " 8.0\n", + " 2021.0\n", + " (42.518574, -71.065102)\n", + " 10.436914\n", + " 10.107841\n", + " \n", + " \n", + " Southborough School District\n", + " Albert S. Woodward Memorial School\n", + " 2503218\n", + " 2760050\n", + " public\n", + " e\n", + " 2,3\n", + " Southborough\n", + " MA\n", + " 1772\n", + " Worcester County\n", + " 42.304043\n", + " -71.527367\n", + " 387\n", + " NaN\n", + " 2020.0\n", + " (42.304043, -71.527367)\n", + " 23.683438\n", + " 18.208098\n", + " \n", + " \n", + " Wilmington School District\n", + " Wildwood\n", + " 2501816\n", + " 3420015\n", + " public\n", + " p,e\n", + " PK,KG\n", + " Wilmington\n", + " MA\n", + " 1887\n", + " Middlesex County\n", + " 42.550678\n", + " -71.153496\n", + " 462\n", + " NaN\n", + " NaN\n", + " (42.550678, -71.153496)\n", + " 13.322938\n", + " 7.376087\n", " \n", " \n", "\n", - "

325 rows × 16 columns

\n", "" ], "text/plain": [ - " state-id \\\n", - "district-name name \n", - "Acton-Boxborough School District Acton-Boxborough Regional High School 6000505 \n", - " Blanchard Memorial School 6000005 \n", - " C.T. Douglas Elementary School 6000020 \n", - " Luther Conant School 6000030 \n", - " Mccarthy-Towne School 6000015 \n", - "... ... \n", - "Winchester School District Lynch Elementary School 3440020 \n", - " Mccall Middle School 3440305 \n", - " Muraco Elementary School 3440040 \n", - " Vinson-Owen Elementary School 3440025 \n", - " Winchester High School 3440505 \n", + " universal-id \\\n", + "district-name name \n", + "Quincy School District Central Middle School 2501385 \n", + "Natick School District Brown 2501156 \n", + "Wakefield School District Dolbeare Elementary School 2501667 \n", + "Southborough School District Albert S. Woodward Memorial School 2503218 \n", + "Wilmington School District Wildwood 2501816 \n", "\n", - " type \\\n", - "district-name name \n", - "Acton-Boxborough School District Acton-Boxborough Regional High School public \n", - " Blanchard Memorial School public \n", - " C.T. Douglas Elementary School public \n", - " Luther Conant School public \n", - " Mccarthy-Towne School public \n", - "... ... \n", - "Winchester School District Lynch Elementary School public \n", - " Mccall Middle School public \n", - " Muraco Elementary School public \n", - " Vinson-Owen Elementary School public \n", - " Winchester High School public \n", + " state-id \\\n", + "district-name name \n", + "Quincy School District Central Middle School 2430315 \n", + "Natick School District Brown 1980010 \n", + "Wakefield School District Dolbeare Elementary School 3050005 \n", + "Southborough School District Albert S. Woodward Memorial School 2760050 \n", + "Wilmington School District Wildwood 3420015 \n", "\n", - " level-codes \\\n", - "district-name name \n", - "Acton-Boxborough School District Acton-Boxborough Regional High School h \n", - " Blanchard Memorial School e \n", - " C.T. Douglas Elementary School e \n", - " Luther Conant School e \n", - " Mccarthy-Towne School e \n", - "... ... \n", - "Winchester School District Lynch Elementary School p,e \n", - " Mccall Middle School m \n", - " Muraco Elementary School e \n", - " Vinson-Owen Elementary School p,e \n", - " Winchester High School h \n", + " type \\\n", + "district-name name \n", + "Quincy School District Central Middle School public \n", + "Natick School District Brown public \n", + "Wakefield School District Dolbeare Elementary School public \n", + "Southborough School District Albert S. Woodward Memorial School public \n", + "Wilmington School District Wildwood public \n", "\n", - " level \\\n", - "district-name name \n", - "Acton-Boxborough School District Acton-Boxborough Regional High School 9,10,11,12,UG \n", - " Blanchard Memorial School KG,1,2,3,4,5,6 \n", - " C.T. Douglas Elementary School KG,1,2,3,4,5,6 \n", - " Luther Conant School KG,1,2,3,4,5,6 \n", - " Mccarthy-Towne School KG,1,2,3,4,5,6 \n", - "... ... \n", - "Winchester School District Lynch Elementary School PK,KG,1,2,3,4,5 \n", - " Mccall Middle School 6,7,8 \n", - " Muraco Elementary School KG,1,2,3,4,5 \n", - " Vinson-Owen Elementary School PK,KG,1,2,3,4,5 \n", - " Winchester High School 9,10,11,12 \n", + " level-codes \\\n", + "district-name name \n", + "Quincy School District Central Middle School m \n", + "Natick School District Brown e \n", + "Wakefield School District Dolbeare Elementary School e \n", + "Southborough School District Albert S. Woodward Memorial School e \n", + "Wilmington School District Wildwood p,e \n", "\n", - " city \\\n", - "district-name name \n", - "Acton-Boxborough School District Acton-Boxborough Regional High School Acton \n", - " Blanchard Memorial School Boxborough \n", - " C.T. Douglas Elementary School Acton \n", - " Luther Conant School Acton \n", - " Mccarthy-Towne School Acton \n", - "... ... \n", - "Winchester School District Lynch Elementary School Winchester \n", - " Mccall Middle School Winchester \n", - " Muraco Elementary School Winchester \n", - " Vinson-Owen Elementary School Winchester \n", - " Winchester High School Winchester \n", + " level \\\n", + "district-name name \n", + "Quincy School District Central Middle School 6,7,8 \n", + "Natick School District Brown KG,1,2,3,4 \n", + "Wakefield School District Dolbeare Elementary School KG,1,2,3,4 \n", + "Southborough School District Albert S. Woodward Memorial School 2,3 \n", + "Wilmington School District Wildwood PK,KG \n", "\n", - " state \\\n", - "district-name name \n", - "Acton-Boxborough School District Acton-Boxborough Regional High School MA \n", - " Blanchard Memorial School MA \n", - " C.T. Douglas Elementary School MA \n", - " Luther Conant School MA \n", - " Mccarthy-Towne School MA \n", - "... ... \n", - "Winchester School District Lynch Elementary School MA \n", - " Mccall Middle School MA \n", - " Muraco Elementary School MA \n", - " Vinson-Owen Elementary School MA \n", - " Winchester High School MA \n", + " city \\\n", + "district-name name \n", + "Quincy School District Central Middle School Quincy \n", + "Natick School District Brown Natick \n", + "Wakefield School District Dolbeare Elementary School Wakefield \n", + "Southborough School District Albert S. Woodward Memorial School Southborough \n", + "Wilmington School District Wildwood Wilmington \n", "\n", - " zip \\\n", - "district-name name \n", - "Acton-Boxborough School District Acton-Boxborough Regional High School 1720 \n", - " Blanchard Memorial School 1719 \n", - " C.T. Douglas Elementary School 1720 \n", - " Luther Conant School 1720 \n", - " Mccarthy-Towne School 1720 \n", - "... ... \n", - "Winchester School District Lynch Elementary School 1890 \n", - " Mccall Middle School 1890 \n", - " Muraco Elementary School 1890 \n", - " Vinson-Owen Elementary School 1890 \n", - " Winchester High School 1890 \n", + " state zip \\\n", + "district-name name \n", + "Quincy School District Central Middle School MA 2170 \n", + "Natick School District Brown MA 1760 \n", + "Wakefield School District Dolbeare Elementary School MA 1880 \n", + "Southborough School District Albert S. Woodward Memorial School MA 1772 \n", + "Wilmington School District Wildwood MA 1887 \n", "\n", - " county \\\n", - "district-name name \n", - "Acton-Boxborough School District Acton-Boxborough Regional High School Middlesex County \n", - " Blanchard Memorial School Middlesex County \n", - " C.T. Douglas Elementary School Middlesex County \n", - " Luther Conant School Middlesex County \n", - " Mccarthy-Towne School Middlesex County \n", - "... ... \n", - "Winchester School District Lynch Elementary School Middlesex County \n", - " Mccall Middle School Middlesex County \n", - " Muraco Elementary School Middlesex County \n", - " Vinson-Owen Elementary School Middlesex County \n", - " Winchester High School Middlesex County \n", + " county \\\n", + "district-name name \n", + "Quincy School District Central Middle School Norfolk County \n", + "Natick School District Brown Middlesex County \n", + "Wakefield School District Dolbeare Elementary School Middlesex County \n", + "Southborough School District Albert S. Woodward Memorial School Worcester County \n", + "Wilmington School District Wildwood Middlesex County \n", "\n", - " lat \\\n", - "district-name name \n", - "Acton-Boxborough School District Acton-Boxborough Regional High School 42.479694 \n", - " Blanchard Memorial School 42.482014 \n", - " C.T. Douglas Elementary School 42.481873 \n", - " Luther Conant School 42.475239 \n", - " Mccarthy-Towne School 42.476936 \n", - "... ... \n", - "Winchester School District Lynch Elementary School 42.460964 \n", - " Mccall Middle School 42.449566 \n", - " Muraco Elementary School 42.463272 \n", - " Vinson-Owen Elementary School 42.449741 \n", - " Winchester High School 42.455719 \n", + " lat \\\n", + "district-name name \n", + "Quincy School District Central Middle School 42.261284 \n", + "Natick School District Brown 42.292339 \n", + "Wakefield School District Dolbeare Elementary School 42.518574 \n", + "Southborough School District Albert S. Woodward Memorial School 42.304043 \n", + "Wilmington School District Wildwood 42.550678 \n", "\n", - " lon \\\n", - "district-name name \n", - "Acton-Boxborough School District Acton-Boxborough Regional High School -71.458084 \n", - " Blanchard Memorial School -71.505814 \n", - " C.T. Douglas Elementary School -71.471588 \n", - " Luther Conant School -71.436340 \n", - " Mccarthy-Towne School -71.453590 \n", - "... ... \n", - "Winchester School District Lynch Elementary School -71.150330 \n", - " Mccall Middle School -71.134735 \n", - " Muraco Elementary School -71.131409 \n", - " Vinson-Owen Elementary School -71.175018 \n", - " Winchester High School -71.134201 \n", + " lon \\\n", + "district-name name \n", + "Quincy School District Central Middle School -71.011436 \n", + "Natick School District Brown -71.384941 \n", + "Wakefield School District Dolbeare Elementary School -71.065102 \n", + "Southborough School District Albert S. Woodward Memorial School -71.527367 \n", + "Wilmington School District Wildwood -71.153496 \n", "\n", - " district-id \\\n", - "district-name name \n", - "Acton-Boxborough School District Acton-Boxborough Regional High School 59 \n", - " Blanchard Memorial School 59 \n", - " C.T. Douglas Elementary School 59 \n", - " Luther Conant School 59 \n", - " Mccarthy-Towne School 59 \n", - "... ... \n", - "Winchester School District Lynch Elementary School 464 \n", - " Mccall Middle School 464 \n", - " Muraco Elementary School 464 \n", - " Vinson-Owen Elementary School 464 \n", - " Winchester High School 464 \n", + " district-id \\\n", + "district-name name \n", + "Quincy School District Central Middle School 349 \n", + "Natick School District Brown 294 \n", + "Wakefield School District Dolbeare Elementary School 424 \n", + "Southborough School District Albert S. Woodward Memorial School 387 \n", + "Wilmington School District Wildwood 462 \n", "\n", - " rating \\\n", - "district-name name \n", - "Acton-Boxborough School District Acton-Boxborough Regional High School 9.0 \n", - " Blanchard Memorial School 8.0 \n", - " C.T. Douglas Elementary School 6.0 \n", - " Luther Conant School 8.0 \n", - " Mccarthy-Towne School 5.0 \n", - "... ... \n", - "Winchester School District Lynch Elementary School 7.0 \n", - " Mccall Middle School 7.0 \n", - " Muraco Elementary School 9.0 \n", - " Vinson-Owen Elementary School 9.0 \n", - " Winchester High School 8.0 \n", + " rating \\\n", + "district-name name \n", + "Quincy School District Central Middle School 8.0 \n", + "Natick School District Brown 7.0 \n", + "Wakefield School District Dolbeare Elementary School 8.0 \n", + "Southborough School District Albert S. Woodward Memorial School NaN \n", + "Wilmington School District Wildwood NaN \n", "\n", - " year \\\n", - "district-name name \n", - "Acton-Boxborough School District Acton-Boxborough Regional High School 2021.0 \n", - " Blanchard Memorial School 2021.0 \n", - " C.T. Douglas Elementary School 2021.0 \n", - " Luther Conant School 2021.0 \n", - " Mccarthy-Towne School 2021.0 \n", - "... ... \n", - "Winchester School District Lynch Elementary School 2021.0 \n", - " Mccall Middle School 2021.0 \n", - " Muraco Elementary School 2021.0 \n", - " Vinson-Owen Elementary School 2021.0 \n", - " Winchester High School 2021.0 \n", + " year \\\n", + "district-name name \n", + "Quincy School District Central Middle School 2021.0 \n", + "Natick School District Brown 2021.0 \n", + "Wakefield School District Dolbeare Elementary School 2021.0 \n", + "Southborough School District Albert S. Woodward Memorial School 2020.0 \n", + "Wilmington School District Wildwood NaN \n", "\n", - " coordinates \\\n", - "district-name name \n", - "Acton-Boxborough School District Acton-Boxborough Regional High School (42.479694, -71.458084) \n", - " Blanchard Memorial School (42.482014, -71.505814) \n", - " C.T. Douglas Elementary School (42.481873, -71.471588) \n", - " Luther Conant School (42.475239, -71.43634) \n", - " Mccarthy-Towne School (42.476936, -71.45359) \n", - "... ... \n", - "Winchester School District Lynch Elementary School (42.460964, -71.15033) \n", - " Mccall Middle School (42.449566, -71.134735) \n", - " Muraco Elementary School (42.463272, -71.131409) \n", - " Vinson-Owen Elementary School (42.449741, -71.175018) \n", - " Winchester High School (42.455719, -71.134201) \n", + " coordinates \\\n", + "district-name name \n", + "Quincy School District Central Middle School (42.261284, -71.011436) \n", + "Natick School District Brown (42.292339, -71.384941) \n", + "Wakefield School District Dolbeare Elementary School (42.518574, -71.065102) \n", + "Southborough School District Albert S. Woodward Memorial School (42.304043, -71.527367) \n", + "Wilmington School District Wildwood (42.550678, -71.153496) \n", "\n", - " distance-to-downtown \\\n", - "district-name name \n", - "Acton-Boxborough School District Acton-Boxborough Regional High School 21.179084 \n", - " Blanchard Memorial School 23.513033 \n", - " C.T. Douglas Elementary School 21.874635 \n", - " Luther Conant School 20.036107 \n", - " Mccarthy-Towne School 20.896860 \n", - "... ... \n", - "Winchester School District Lynch Elementary School 7.607210 \n", - " Mccall Middle School 6.523996 \n", - " Muraco Elementary School 7.288029 \n", - " Vinson-Owen Elementary School 7.758212 \n", - " Winchester High School 6.883474 \n", + " distance-to-downtown \\\n", + "district-name name \n", + "Quincy School District Central Middle School 7.944981 \n", + "Natick School District Brown 16.826936 \n", + "Wakefield School District Dolbeare Elementary School 10.436914 \n", + "Southborough School District Albert S. Woodward Memorial School 23.683438 \n", + "Wilmington School District Wildwood 13.322938 \n", "\n", - " distance-to-work \n", - "district-name name \n", - "Acton-Boxborough School District Acton-Boxborough Regional High School 10.393596 \n", - " Blanchard Memorial School 12.828547 \n", - " C.T. Douglas Elementary School 11.087128 \n", - " Luther Conant School 9.279210 \n", - " Mccarthy-Towne School 10.159317 \n", - "... ... \n", - "Winchester School District Lynch Elementary School 5.361206 \n", - " Mccall Middle School 6.308317 \n", - " Muraco Elementary School 6.293099 \n", - " Vinson-Owen Elementary School 4.359471 \n", - " Winchester High School 6.235460 \n", - "\n", - "[325 rows x 16 columns]" + " distance-to-work \n", + "district-name name \n", + "Quincy School District Central Middle School 19.199411 \n", + "Natick School District Brown 14.194884 \n", + "Wakefield School District Dolbeare Elementary School 10.107841 \n", + "Southborough School District Albert S. Woodward Memorial School 18.208098 \n", + "Wilmington School District Wildwood 7.376087 " ] }, "execution_count": 9, @@ -792,198 +588,70 @@ } ], "source": [ + "boston_df.reset_index(inplace=True)\n", "boston_df.set_index(['district-name','name'],inplace=True)\n", "boston_df.sort_index(inplace=True)\n", - "boston_df" + "boston_df.sample(5)" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "['h' 'e' 'm' 'e,m' 'p,h' 'p,e' 'p,e,m' 'p,e,h' 'm,h']\n" - ] - } - ], + "outputs": [], "source": [ - "print(boston_df['level-codes'].unique()) " + "#print(boston_df['level-codes'].unique()) " ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
state-idtypelevel-codeslevelcitystatezipcountylatlondistrict-idratingyearcoordinatesdistance-to-downtowndistance-to-work
name
Harry Lee Cole380005publicp,ePK,KG,1,2BoxfordMA1921Essex County42.660408-71.001770102NaNNaN(42.660408, -71.00177)20.53265918.184645
Spofford Pond380013publice3,4,5,6BoxfordMA1921Essex County42.697018-71.0173651027.02021.0(42.697018, -71.017365)22.91793319.554889
\n", - "
" - ], - "text/plain": [ - " state-id type level-codes level city state zip \\\n", - "name \n", - "Harry Lee Cole 380005 public p,e PK,KG,1,2 Boxford MA 1921 \n", - "Spofford Pond 380013 public e 3,4,5,6 Boxford MA 1921 \n", - "\n", - " county lat lon district-id rating \\\n", - "name \n", - "Harry Lee Cole Essex County 42.660408 -71.001770 102 NaN \n", - "Spofford Pond Essex County 42.697018 -71.017365 102 7.0 \n", - "\n", - " year coordinates distance-to-downtown \\\n", - "name \n", - "Harry Lee Cole NaN (42.660408, -71.00177) 20.532659 \n", - "Spofford Pond 2021.0 (42.697018, -71.017365) 22.917933 \n", - "\n", - " distance-to-work \n", - "name \n", - "Harry Lee Cole 18.184645 \n", - "Spofford Pond 19.554889 " - ] - }, - "execution_count": 11, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ - "boston_df.loc[\"Boxford School District\"]" + "#boston_df.loc[\"Quincy School District\"]" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, + "outputs": [], + "source": [ + "from district_score import get_overall_rating\n", + "\n", + "overall_df = get_overall_rating(boston_df)\n", + "overall_df = overall_df.set_index(keys='district-name', drop=True)\n", + "overall_df.sort_values(by='weighted_ave', ascending=False, inplace=True)\n", + "overall_df.reset_index(inplace=True)\n", + "overall_df.index += 1\n", + "#print(overall_df.to_markdown())" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, "outputs": [ { - "ename": "ValueError", - "evalue": "If using all scalar values, you must pass an index", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32m/home/shaun/Code/git/schools/main/analysis.ipynb Cell 20'\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0m get_overall_rating(boston_df)\n", - "File \u001b[0;32m~/Code/git/schools/main/district_score.py:56\u001b[0m, in \u001b[0;36mget_overall_rating\u001b[0;34m(df)\u001b[0m\n\u001b[1;32m 54\u001b[0m district_dict \u001b[39m=\u001b[39m {\u001b[39m'\u001b[39m\u001b[39mdistrict-name\u001b[39m\u001b[39m'\u001b[39m: district}\n\u001b[1;32m 55\u001b[0m district_dict \u001b[39m=\u001b[39m {\u001b[39m*\u001b[39m\u001b[39m*\u001b[39mdistrict_dict, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mstats}\n\u001b[0;32m---> 56\u001b[0m overall \u001b[39m=\u001b[39m pd\u001b[39m.\u001b[39;49mDataFrame(district_dict)\n\u001b[1;32m 57\u001b[0m \u001b[39mprint\u001b[39m(overall)\n\u001b[1;32m 58\u001b[0m \u001b[39mreturn\u001b[39;00m\n", - "File \u001b[0;32m~/Code/git/schools/venv/lib64/python3.10/site-packages/pandas/core/frame.py:636\u001b[0m, in \u001b[0;36mDataFrame.__init__\u001b[0;34m(self, data, index, columns, dtype, copy)\u001b[0m\n\u001b[1;32m 630\u001b[0m mgr \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_init_mgr(\n\u001b[1;32m 631\u001b[0m data, axes\u001b[39m=\u001b[39m{\u001b[39m\"\u001b[39m\u001b[39mindex\u001b[39m\u001b[39m\"\u001b[39m: index, \u001b[39m\"\u001b[39m\u001b[39mcolumns\u001b[39m\u001b[39m\"\u001b[39m: columns}, dtype\u001b[39m=\u001b[39mdtype, copy\u001b[39m=\u001b[39mcopy\n\u001b[1;32m 632\u001b[0m )\n\u001b[1;32m 634\u001b[0m \u001b[39melif\u001b[39;00m \u001b[39misinstance\u001b[39m(data, \u001b[39mdict\u001b[39m):\n\u001b[1;32m 635\u001b[0m \u001b[39m# GH#38939 de facto copy defaults to False only in non-dict cases\u001b[39;00m\n\u001b[0;32m--> 636\u001b[0m mgr \u001b[39m=\u001b[39m dict_to_mgr(data, index, columns, dtype\u001b[39m=\u001b[39;49mdtype, copy\u001b[39m=\u001b[39;49mcopy, typ\u001b[39m=\u001b[39;49mmanager)\n\u001b[1;32m 637\u001b[0m \u001b[39melif\u001b[39;00m \u001b[39misinstance\u001b[39m(data, ma\u001b[39m.\u001b[39mMaskedArray):\n\u001b[1;32m 638\u001b[0m \u001b[39mimport\u001b[39;00m \u001b[39mnumpy\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mma\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mmrecords\u001b[39;00m \u001b[39mas\u001b[39;00m \u001b[39mmrecords\u001b[39;00m\n", - "File \u001b[0;32m~/Code/git/schools/venv/lib64/python3.10/site-packages/pandas/core/internals/construction.py:502\u001b[0m, in \u001b[0;36mdict_to_mgr\u001b[0;34m(data, index, columns, dtype, typ, copy)\u001b[0m\n\u001b[1;32m 494\u001b[0m arrays \u001b[39m=\u001b[39m [\n\u001b[1;32m 495\u001b[0m x\n\u001b[1;32m 496\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mhasattr\u001b[39m(x, \u001b[39m\"\u001b[39m\u001b[39mdtype\u001b[39m\u001b[39m\"\u001b[39m) \u001b[39mor\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39misinstance\u001b[39m(x\u001b[39m.\u001b[39mdtype, ExtensionDtype)\n\u001b[1;32m 497\u001b[0m \u001b[39melse\u001b[39;00m x\u001b[39m.\u001b[39mcopy()\n\u001b[1;32m 498\u001b[0m \u001b[39mfor\u001b[39;00m x \u001b[39min\u001b[39;00m arrays\n\u001b[1;32m 499\u001b[0m ]\n\u001b[1;32m 500\u001b[0m \u001b[39m# TODO: can we get rid of the dt64tz special case above?\u001b[39;00m\n\u001b[0;32m--> 502\u001b[0m \u001b[39mreturn\u001b[39;00m arrays_to_mgr(arrays, columns, index, dtype\u001b[39m=\u001b[39;49mdtype, typ\u001b[39m=\u001b[39;49mtyp, consolidate\u001b[39m=\u001b[39;49mcopy)\n", - "File \u001b[0;32m~/Code/git/schools/venv/lib64/python3.10/site-packages/pandas/core/internals/construction.py:120\u001b[0m, in \u001b[0;36marrays_to_mgr\u001b[0;34m(arrays, columns, index, dtype, verify_integrity, typ, consolidate)\u001b[0m\n\u001b[1;32m 117\u001b[0m \u001b[39mif\u001b[39;00m verify_integrity:\n\u001b[1;32m 118\u001b[0m \u001b[39m# figure out the index, if necessary\u001b[39;00m\n\u001b[1;32m 119\u001b[0m \u001b[39mif\u001b[39;00m index \u001b[39mis\u001b[39;00m \u001b[39mNone\u001b[39;00m:\n\u001b[0;32m--> 120\u001b[0m index \u001b[39m=\u001b[39m _extract_index(arrays)\n\u001b[1;32m 121\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[1;32m 122\u001b[0m index \u001b[39m=\u001b[39m ensure_index(index)\n", - "File \u001b[0;32m~/Code/git/schools/venv/lib64/python3.10/site-packages/pandas/core/internals/construction.py:664\u001b[0m, in \u001b[0;36m_extract_index\u001b[0;34m(data)\u001b[0m\n\u001b[1;32m 661\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mValueError\u001b[39;00m(\u001b[39m\"\u001b[39m\u001b[39mPer-column arrays must each be 1-dimensional\u001b[39m\u001b[39m\"\u001b[39m)\n\u001b[1;32m 663\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mnot\u001b[39;00m indexes \u001b[39mand\u001b[39;00m \u001b[39mnot\u001b[39;00m raw_lengths:\n\u001b[0;32m--> 664\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mValueError\u001b[39;00m(\u001b[39m\"\u001b[39m\u001b[39mIf using all scalar values, you must pass an index\u001b[39m\u001b[39m\"\u001b[39m)\n\u001b[1;32m 666\u001b[0m \u001b[39melif\u001b[39;00m have_series:\n\u001b[1;32m 667\u001b[0m index \u001b[39m=\u001b[39m union_indexes(indexes)\n", - "\u001b[0;31mValueError\u001b[0m: If using all scalar values, you must pass an index" + "name": "stdout", + "output_type": "stream", + "text": [ + "{'message': 'Too Many Requests'}\n" ] } ], "source": [ - "get_overall_rating(boston_df)" + "boston_schools = get_demographics(api_key,'2500919')" ] } ], "metadata": { "interpreter": { - "hash": "dae3ff348533214ca96918f3de2a71cf7a825bd7ff89c94afcc9465db0c546d9" + "hash": "4fc861b332db140b7b363b167627eee6a3238262e7c99e0237067fec0875fee7" }, "kernelspec": { - "display_name": "Python 3.10.4 ('venv': venv)", + "display_name": "Python 3.8.10 ('venv': venv)", "language": "python", "name": "python3" }, @@ -997,7 +665,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.4" + "version": "3.8.10" }, "orig_nbformat": 4 }, diff --git a/main/district_score.py b/main/district_score.py index ddf6340..450dbe4 100644 --- a/main/district_score.py +++ b/main/district_score.py @@ -24,8 +24,7 @@ def get_overall_rating(df: pd.DataFrame): 'h_ave': 0, 'weighted_ave': 0 } - overall = pd.DataFrame() - + overall_df = pd.DataFrame() districts = list(df.index.unique(level=0)) for district in districts: scores = {} @@ -53,6 +52,6 @@ def get_overall_rating(df: pd.DataFrame): stats['weighted_ave'] = round(weighted_ave,2) district_dict = {'district-name': district} district_dict = {**district_dict, **stats} - overall = pd.DataFrame(district_dict) - print(overall) - return \ No newline at end of file + district_df = pd.DataFrame.from_dict(district_dict, orient='index') + overall_df = pd.concat([overall_df,district_df.T]) + return overall_df \ No newline at end of file diff --git a/main/great_schools.py b/main/great_schools.py index a5f6c2b..615fae4 100755 --- a/main/great_schools.py +++ b/main/great_schools.py @@ -42,4 +42,27 @@ def get_nearby_schools(key: str, lat: str, lon: str, dist: str): for school in r['schools']: schools.append(school) count = count + 1 - return schools \ No newline at end of file + return schools + +# Endpoint: demographics +def get_demographics(key: str, universal_id: str): + ''' + Returns a dictionary of schools received from the nearby schools endpoint. + Parameters: + key (str): API key + lat (str): latitude + lon (str): longitude + dist (str): radius of search + Returns: + schools (dict): Collated response from API + ''' + url = f'https://gs-api.greatschools.org/schools/' + '{universal_id}' + '/metrics' + params = { + } + headers = { + "x-api-key": key + } + + # make request + r = requests.get(url=url, params=params, headers=headers).json() + print(r) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 9c826ac..8e573fb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -63,6 +63,7 @@ Send2Trash==1.8.0 six==1.16.0 soupsieve==2.3.2 stack-data==0.2.0 +tabulate==0.8.9 terminado==0.13.3 testpath==0.6.0 tornado==6.1