diff --git a/main/analysis.ipynb b/main/analysis.ipynb index d29e256..5e333d7 100644 --- a/main/analysis.ipynb +++ b/main/analysis.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 235, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -12,7 +12,8 @@ "\n", "from great_schools import get_nearby_schools\n", "from distance import get_distance\n", - "from secret import get_key\n" + "from secret import get_key\n", + "from district_score import get_overall_rating" ] }, { @@ -32,7 +33,7 @@ }, { "cell_type": "code", - "execution_count": 236, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -50,7 +51,7 @@ }, { "cell_type": "code", - "execution_count": 237, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -108,7 +109,7 @@ }, { "cell_type": "code", - "execution_count": 238, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -134,7 +135,7 @@ }, { "cell_type": "code", - "execution_count": 239, + "execution_count": 5, "metadata": {}, "outputs": [ { @@ -163,7 +164,7 @@ }, { "cell_type": "code", - "execution_count": 240, + "execution_count": 6, "metadata": {}, "outputs": [ { @@ -191,7 +192,7 @@ }, { "cell_type": "code", - "execution_count": 241, + "execution_count": 7, "metadata": {}, "outputs": [ { @@ -239,7 +240,7 @@ }, { "cell_type": "code", - "execution_count": 242, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -276,7 +277,7 @@ }, { "cell_type": "code", - "execution_count": 243, + "execution_count": 9, "metadata": {}, "outputs": [ { @@ -341,218 +342,216 @@ " \n", " \n", " \n", - " Newton School District\n", - " Charles E Brown Middle School\n", - " 2070310\n", - " public\n", - " m\n", - " 6,7,8\n", - " Newton Centre\n", - " MA\n", - " 2459\n", - " Middlesex County\n", - " 42.308750\n", - " -71.190292\n", - " 304\n", - " 9.0\n", - " 2021.0\n", - " (42.30875, -71.190292)\n", - " 7.300583\n", - " 11.852619\n", - " \n", - " \n", - " Oak Hill Middle School\n", - " 2070320\n", - " public\n", - " m\n", - " 6,7,8\n", - " Newton\n", - " MA\n", - " 2459\n", - " Middlesex County\n", - " 42.310009\n", - " -71.191544\n", - " 304\n", - " 8.0\n", - " 2021.0\n", - " (42.310009, -71.191544)\n", - " 7.306174\n", - " 11.751548\n", - " \n", - " \n", - " Countryside Elementary School\n", - " 2070040\n", - " public\n", - " e\n", - " KG,1,2,3,4,5\n", - " Newton Highlands\n", - " MA\n", - " 2461\n", - " Middlesex County\n", - " 42.313141\n", - " -71.202377\n", - " 304\n", - " 7.0\n", - " 2021.0\n", - " (42.313141, -71.202377)\n", - " 7.667944\n", - " 11.403174\n", - " \n", - " \n", - " Memorial Spaulding Elementary School\n", - " 2070105\n", - " public\n", - " e\n", - " KG,1,2,3,4,5\n", - " Newton Centre\n", - " MA\n", - " 2459\n", - " Middlesex County\n", - " 42.302044\n", - " -71.177696\n", - " 304\n", - " 8.0\n", - " 2021.0\n", - " (42.302044, -71.177696)\n", - " 7.062535\n", - " 12.483971\n", - " \n", - " \n", - " Newton South High School\n", - " 2070510\n", - " public\n", - " h\n", - " 9,10,11,12\n", - " Newton Centre\n", - " MA\n", - " 2459\n", - " Middlesex County\n", - " 42.314308\n", - " -71.186493\n", - " 304\n", - " 7.0\n", - " 2021.0\n", - " (42.314308, -71.186493)\n", - " 6.929197\n", - " 11.540487\n", - " \n", - " \n", - " ...\n", - " ...\n", - " ...\n", - " ...\n", - " ...\n", - " ...\n", - " ...\n", - " ...\n", - " ...\n", - " ...\n", - " ...\n", - " ...\n", - " ...\n", - " ...\n", - " ...\n", - " ...\n", - " ...\n", - " ...\n", - " \n", - " \n", - " Groton-Dunstable School District\n", - " Florence Roche School\n", - " 6730010\n", - " public\n", - " e\n", - " KG,1,2,3,4\n", - " Groton\n", - " MA\n", - " 1450\n", - " Middlesex County\n", - " 42.616894\n", - " -71.577682\n", - " 198\n", - " 7.0\n", - " 2021.0\n", - " (42.616894, -71.577682)\n", - " 31.001218\n", - " 19.195452\n", - " \n", - " \n", - " Tyngsborough School District\n", - " Tyngsborough Middle School\n", - " 3010305\n", - " public\n", - " m\n", - " 6,7,8\n", - " Tyngsborough\n", - " MA\n", - " 1879\n", - " Middlesex County\n", - " 42.696640\n", - " -71.406586\n", - " 418\n", - " 6.0\n", - " 2021.0\n", - " (42.69664, -71.406586)\n", - " 28.415381\n", - " 17.226867\n", - " \n", - " \n", - " Tyngsborough High School\n", - " 3010505\n", - " public\n", - " h\n", - " 9,10,11,12\n", - " Tyngsborough\n", - " MA\n", - " 1879\n", - " Middlesex County\n", - " 42.697529\n", - " -71.408226\n", - " 418\n", - " 8.0\n", - " 2021.0\n", - " (42.697529, -71.408226)\n", - " 28.514503\n", - " 17.319230\n", - " \n", - " \n", - " Groton-Dunstable School District\n", - " Swallow/Union School\n", - " 6730005\n", - " public\n", - " e\n", - " KG,1,2,3,4\n", - " Dunstable\n", - " MA\n", - " 1827\n", - " Middlesex County\n", - " 42.673241\n", - " -71.482529\n", - " 198\n", - " 9.0\n", - " 2021.0\n", - " (42.673241, -71.482529)\n", - " 29.723989\n", - " 18.012628\n", - " \n", - " \n", - " Groton-Dunstable Regional High School\n", - " 6730505\n", + " Acton-Boxborough School District\n", + " Acton-Boxborough Regional High School\n", + " 6000505\n", " public\n", " h\n", " 9,10,11,12,UG\n", - " Groton\n", + " Acton\n", " MA\n", - " 1450\n", + " 1720\n", " Middlesex County\n", - " 42.651093\n", - " -71.540405\n", - " 198\n", - " 10.0\n", + " 42.479694\n", + " -71.458084\n", + " 59\n", + " 9.0\n", " 2021.0\n", - " (42.651093, -71.540405)\n", - " 30.877490\n", - " 19.019974\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", + " public\n", + " m\n", + " 6,7,8\n", + " Winchester\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", + " 8.0\n", + " 2021.0\n", + " (42.455719, -71.134201)\n", + " 6.883474\n", + " 6.235460\n", " \n", " \n", "\n", @@ -562,248 +561,429 @@ "text/plain": [ " state-id \\\n", "district-name name \n", - "Newton School District Charles E Brown Middle School 2070310 \n", - " Oak Hill Middle School 2070320 \n", - " Countryside Elementary School 2070040 \n", - " Memorial Spaulding Elementary School 2070105 \n", - " Newton South High School 2070510 \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", - "Groton-Dunstable School District Florence Roche School 6730010 \n", - "Tyngsborough School District Tyngsborough Middle School 3010305 \n", - " Tyngsborough High School 3010505 \n", - "Groton-Dunstable School District Swallow/Union School 6730005 \n", - " Groton-Dunstable Regional High School 6730505 \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", "\n", " type \\\n", "district-name name \n", - "Newton School District Charles E Brown Middle School public \n", - " Oak Hill Middle School public \n", - " Countryside Elementary School public \n", - " Memorial Spaulding Elementary School public \n", - " Newton South High School public \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", - "Groton-Dunstable School District Florence Roche School public \n", - "Tyngsborough School District Tyngsborough Middle School public \n", - " Tyngsborough High School public \n", - "Groton-Dunstable School District Swallow/Union School public \n", - " Groton-Dunstable Regional High School public \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", "\n", " level-codes \\\n", "district-name name \n", - "Newton School District Charles E Brown Middle School m \n", - " Oak Hill Middle School m \n", - " Countryside Elementary School e \n", - " Memorial Spaulding Elementary School e \n", - " Newton South High School h \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", - "Groton-Dunstable School District Florence Roche School e \n", - "Tyngsborough School District Tyngsborough Middle School m \n", - " Tyngsborough High School h \n", - "Groton-Dunstable School District Swallow/Union School e \n", - " Groton-Dunstable Regional High School h \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", "\n", - " level \\\n", - "district-name name \n", - "Newton School District Charles E Brown Middle School 6,7,8 \n", - " Oak Hill Middle School 6,7,8 \n", - " Countryside Elementary School KG,1,2,3,4,5 \n", - " Memorial Spaulding Elementary School KG,1,2,3,4,5 \n", - " Newton South High School 9,10,11,12 \n", - "... ... \n", - "Groton-Dunstable School District Florence Roche School KG,1,2,3,4 \n", - "Tyngsborough School District Tyngsborough Middle School 6,7,8 \n", - " Tyngsborough High School 9,10,11,12 \n", - "Groton-Dunstable School District Swallow/Union School KG,1,2,3,4 \n", - " Groton-Dunstable Regional High School 9,10,11,12,UG \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", "\n", - " city \\\n", - "district-name name \n", - "Newton School District Charles E Brown Middle School Newton Centre \n", - " Oak Hill Middle School Newton \n", - " Countryside Elementary School Newton Highlands \n", - " Memorial Spaulding Elementary School Newton Centre \n", - " Newton South High School Newton Centre \n", - "... ... \n", - "Groton-Dunstable School District Florence Roche School Groton \n", - "Tyngsborough School District Tyngsborough Middle School Tyngsborough \n", - " Tyngsborough High School Tyngsborough \n", - "Groton-Dunstable School District Swallow/Union School Dunstable \n", - " Groton-Dunstable Regional High School Groton \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", "\n", " state \\\n", "district-name name \n", - "Newton School District Charles E Brown Middle School MA \n", - " Oak Hill Middle School MA \n", - " Countryside Elementary School MA \n", - " Memorial Spaulding Elementary School MA \n", - " Newton South High School MA \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", - "Groton-Dunstable School District Florence Roche School MA \n", - "Tyngsborough School District Tyngsborough Middle School MA \n", - " Tyngsborough High School MA \n", - "Groton-Dunstable School District Swallow/Union School MA \n", - " Groton-Dunstable Regional High School MA \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", "\n", " zip \\\n", "district-name name \n", - "Newton School District Charles E Brown Middle School 2459 \n", - " Oak Hill Middle School 2459 \n", - " Countryside Elementary School 2461 \n", - " Memorial Spaulding Elementary School 2459 \n", - " Newton South High School 2459 \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", - "Groton-Dunstable School District Florence Roche School 1450 \n", - "Tyngsborough School District Tyngsborough Middle School 1879 \n", - " Tyngsborough High School 1879 \n", - "Groton-Dunstable School District Swallow/Union School 1827 \n", - " Groton-Dunstable Regional High School 1450 \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", "\n", " county \\\n", "district-name name \n", - "Newton School District Charles E Brown Middle School Middlesex County \n", - " Oak Hill Middle School Middlesex County \n", - " Countryside Elementary School Middlesex County \n", - " Memorial Spaulding Elementary School Middlesex County \n", - " Newton South High School Middlesex County \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", - "Groton-Dunstable School District Florence Roche School Middlesex County \n", - "Tyngsborough School District Tyngsborough Middle School Middlesex County \n", - " Tyngsborough High School Middlesex County \n", - "Groton-Dunstable School District Swallow/Union School Middlesex County \n", - " Groton-Dunstable Regional High School Middlesex County \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", "\n", " lat \\\n", "district-name name \n", - "Newton School District Charles E Brown Middle School 42.308750 \n", - " Oak Hill Middle School 42.310009 \n", - " Countryside Elementary School 42.313141 \n", - " Memorial Spaulding Elementary School 42.302044 \n", - " Newton South High School 42.314308 \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", - "Groton-Dunstable School District Florence Roche School 42.616894 \n", - "Tyngsborough School District Tyngsborough Middle School 42.696640 \n", - " Tyngsborough High School 42.697529 \n", - "Groton-Dunstable School District Swallow/Union School 42.673241 \n", - " Groton-Dunstable Regional High School 42.651093 \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", "\n", " lon \\\n", "district-name name \n", - "Newton School District Charles E Brown Middle School -71.190292 \n", - " Oak Hill Middle School -71.191544 \n", - " Countryside Elementary School -71.202377 \n", - " Memorial Spaulding Elementary School -71.177696 \n", - " Newton South High School -71.186493 \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", - "Groton-Dunstable School District Florence Roche School -71.577682 \n", - "Tyngsborough School District Tyngsborough Middle School -71.406586 \n", - " Tyngsborough High School -71.408226 \n", - "Groton-Dunstable School District Swallow/Union School -71.482529 \n", - " Groton-Dunstable Regional High School -71.540405 \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", "\n", " district-id \\\n", "district-name name \n", - "Newton School District Charles E Brown Middle School 304 \n", - " Oak Hill Middle School 304 \n", - " Countryside Elementary School 304 \n", - " Memorial Spaulding Elementary School 304 \n", - " Newton South High School 304 \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", - "Groton-Dunstable School District Florence Roche School 198 \n", - "Tyngsborough School District Tyngsborough Middle School 418 \n", - " Tyngsborough High School 418 \n", - "Groton-Dunstable School District Swallow/Union School 198 \n", - " Groton-Dunstable Regional High School 198 \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", "\n", " rating \\\n", "district-name name \n", - "Newton School District Charles E Brown Middle School 9.0 \n", - " Oak Hill Middle School 8.0 \n", - " Countryside Elementary School 7.0 \n", - " Memorial Spaulding Elementary School 8.0 \n", - " Newton South High School 7.0 \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", - "Groton-Dunstable School District Florence Roche School 7.0 \n", - "Tyngsborough School District Tyngsborough Middle School 6.0 \n", - " Tyngsborough High School 8.0 \n", - "Groton-Dunstable School District Swallow/Union School 9.0 \n", - " Groton-Dunstable Regional High School 10.0 \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", "\n", " year \\\n", "district-name name \n", - "Newton School District Charles E Brown Middle School 2021.0 \n", - " Oak Hill Middle School 2021.0 \n", - " Countryside Elementary School 2021.0 \n", - " Memorial Spaulding Elementary School 2021.0 \n", - " Newton South High School 2021.0 \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", - "Groton-Dunstable School District Florence Roche School 2021.0 \n", - "Tyngsborough School District Tyngsborough Middle School 2021.0 \n", - " Tyngsborough High School 2021.0 \n", - "Groton-Dunstable School District Swallow/Union School 2021.0 \n", - " Groton-Dunstable Regional High School 2021.0 \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", "\n", " coordinates \\\n", "district-name name \n", - "Newton School District Charles E Brown Middle School (42.30875, -71.190292) \n", - " Oak Hill Middle School (42.310009, -71.191544) \n", - " Countryside Elementary School (42.313141, -71.202377) \n", - " Memorial Spaulding Elementary School (42.302044, -71.177696) \n", - " Newton South High School (42.314308, -71.186493) \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", - "Groton-Dunstable School District Florence Roche School (42.616894, -71.577682) \n", - "Tyngsborough School District Tyngsborough Middle School (42.69664, -71.406586) \n", - " Tyngsborough High School (42.697529, -71.408226) \n", - "Groton-Dunstable School District Swallow/Union School (42.673241, -71.482529) \n", - " Groton-Dunstable Regional High School (42.651093, -71.540405) \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", "\n", " distance-to-downtown \\\n", "district-name name \n", - "Newton School District Charles E Brown Middle School 7.300583 \n", - " Oak Hill Middle School 7.306174 \n", - " Countryside Elementary School 7.667944 \n", - " Memorial Spaulding Elementary School 7.062535 \n", - " Newton South High School 6.929197 \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", - "Groton-Dunstable School District Florence Roche School 31.001218 \n", - "Tyngsborough School District Tyngsborough Middle School 28.415381 \n", - " Tyngsborough High School 28.514503 \n", - "Groton-Dunstable School District Swallow/Union School 29.723989 \n", - " Groton-Dunstable Regional High School 30.877490 \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", "\n", " distance-to-work \n", "district-name name \n", - "Newton School District Charles E Brown Middle School 11.852619 \n", - " Oak Hill Middle School 11.751548 \n", - " Countryside Elementary School 11.403174 \n", - " Memorial Spaulding Elementary School 12.483971 \n", - " Newton South High School 11.540487 \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", - "Groton-Dunstable School District Florence Roche School 19.195452 \n", - "Tyngsborough School District Tyngsborough Middle School 17.226867 \n", - " Tyngsborough High School 17.319230 \n", - "Groton-Dunstable School District Swallow/Union School 18.012628 \n", - " Groton-Dunstable Regional High School 19.019974 \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]" ] }, - "execution_count": 243, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "boston_df.set_index(['district-name','name'],inplace=True)\n", + "boston_df.sort_index(inplace=True)\n", "boston_df" ] + }, + { + "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" + ] + } + ], + "source": [ + "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" + } + ], + "source": [ + "boston_df.loc[\"Boxford School District\"]" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "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" + ] + } + ], + "source": [ + "get_overall_rating(boston_df)" + ] } ], "metadata": { "interpreter": { - "hash": "4fc861b332db140b7b363b167627eee6a3238262e7c99e0237067fec0875fee7" + "hash": "dae3ff348533214ca96918f3de2a71cf7a825bd7ff89c94afcc9465db0c546d9" }, "kernelspec": { - "display_name": "Python 3.8.10 ('venv': venv)", + "display_name": "Python 3.10.4 ('venv': venv)", "language": "python", "name": "python3" }, @@ -817,7 +997,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.10" + "version": "3.10.4" }, "orig_nbformat": 4 }, diff --git a/main/district_score.py b/main/district_score.py new file mode 100644 index 0000000..ddf6340 --- /dev/null +++ b/main/district_score.py @@ -0,0 +1,58 @@ +#! /usr/bin/env + +import pandas as pd +import math + +# helper to calculate an overall district rating +def get_overall_rating(df: pd.DataFrame): + ''' + Returns a DataFrame that contains the overall district scores. + Parameters: + df (DataFrame): + Returns: + overall (DataFrame): + ''' + weights = { + 'e': 0.3, + 'm': 0.2, + 'h': 0.5 + } + levels = weights.keys() + empty_stats = { + 'e_ave': 0, + 'm_ave': 0, + 'h_ave': 0, + 'weighted_ave': 0 + } + overall = pd.DataFrame() + + districts = list(df.index.unique(level=0)) + for district in districts: + scores = {} + stats = empty_stats + weighted_ave = 0 + schools = list(df.loc[district].index.unique(level=0)) + if len(schools) <= 1: + continue + for level in levels: + scores[level] = [] + for school in schools: + this_school = df.loc[[(district,school)]] + codes = this_school['level-codes'].iloc[0] + if level in codes: + rating = float(this_school['rating'].iloc[0]) + if not math.isnan(rating): + scores[level].append(this_school['rating'].iloc[0]) + #print(district, scores) + try: + stats[level+'_ave'] = round(sum(scores[level])/len(scores[level]),2) + except: + continue + for weight in weights.keys(): + weighted_ave += weights[weight]*stats[weight+'_ave'] + 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