Archived
1
0

Basic filter applied using ave district rating.

This commit is contained in:
Shaun Setlock
2022-04-30 13:45:38 -04:00
parent 3668c65cb9
commit 5f21580566

View File

@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 32,
"execution_count": 235,
"metadata": {},
"outputs": [],
"source": [
@@ -32,7 +32,7 @@
},
{
"cell_type": "code",
"execution_count": 33,
"execution_count": 236,
"metadata": {},
"outputs": [],
"source": [
@@ -50,7 +50,7 @@
},
{
"cell_type": "code",
"execution_count": 34,
"execution_count": 237,
"metadata": {},
"outputs": [],
"source": [
@@ -108,7 +108,7 @@
},
{
"cell_type": "code",
"execution_count": 35,
"execution_count": 238,
"metadata": {},
"outputs": [],
"source": [
@@ -134,7 +134,7 @@
},
{
"cell_type": "code",
"execution_count": 36,
"execution_count": 239,
"metadata": {},
"outputs": [
{
@@ -163,7 +163,7 @@
},
{
"cell_type": "code",
"execution_count": 37,
"execution_count": 240,
"metadata": {},
"outputs": [
{
@@ -191,19 +191,94 @@
},
{
"cell_type": "code",
"execution_count": 38,
"execution_count": 241,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"There are 116 school districts within reasonable proximity to downtown and work.\n",
"\n",
"There are 820 schools within these proximal districts.\n",
"There are 90 school districts within reasonable proximity to downtown and work.\n",
"\n",
"There are 699 schools within these proximal districts.\n",
"\n"
]
},
}
],
"source": [
"# calculate distance to PoI using geo-center of districts\n",
"distances_to_downtown = {k: np.mean(list(v)) for k, v in boston_df.groupby('district-id')['distance-to-downtown']}\n",
"distances_to_work = {k: np.mean(list(v)) for k, v in boston_df.groupby('district-id')['distance-to-work']}\n",
"\n",
"df_downtown = pd.DataFrame.from_dict(distances_to_downtown, orient='index')\n",
"df_work = pd.DataFrame.from_dict(distances_to_work, orient='index')\n",
"\n",
"# merge these new columns\n",
"both_df = pd.merge(left=df_downtown, right=df_work, how='inner', left_index=True, right_index=True)\n",
"both_df.rename(columns={'0_x': \"downtown\", '0_y': \"work\"}, inplace=True)\n",
"\n",
"both_df = both_df[both_df[\"downtown\"] < 35.0]\n",
"both_df = both_df[both_df[\"work\"] < 20.0]\n",
"\n",
"print(f'\\nThere are {len(both_df)} school districts within reasonable proximity to downtown and work.\\n')\n",
"\n",
"# filter out all schools which aren't in proximal districts\n",
"proximal_district_ids = list(both_df.index)\n",
"boston_df = boston_df[boston_df['district-id'].isin(proximal_district_ids)]\n",
"\n",
"print(f'There are {len(boston_df)} schools within these proximal districts.\\n')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's drop any districts that have an average rating below the school population mean."
]
},
{
"cell_type": "code",
"execution_count": 242,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Of the remaining 699 schools, the average rating is 5.664546899841017.\n",
"\n",
"There are 56 districts remaining after pruning districts whose collective average is below the population mean rating.\n",
"\n",
"Which are, ['Acton-Boxborough School District', 'Andover School District', 'Arlington Public Schools', 'Ashland School District', 'Assabet Valley Regional Vocational Technical School District', 'Bedford School District', 'Belmont School District', 'Billerica School District', 'Boxford School District', 'Brookline School District', 'Burlington School District', 'Cambridge School District', 'Carlisle School District', 'Chelmsford School District', 'Concord School District', 'Concord-Carlisle School District', 'Dover School District', 'Dover-Sherborn School District', 'Dracut School District', 'Essex North Shore Agricultural and Technical School District', 'Groton-Dunstable School District', 'Harvard School District', 'Lexington School District', 'Lincoln-Sudbury School District', 'Littleton School District', 'Lynnfield School District', 'Marblehead School District', 'Masconomet School District', 'Melrose School District', 'Middleton School District', 'Milton School District', 'Nahant School District', 'Nashoba School District', 'Natick School District', 'Needham School District', 'Newton School District', 'North Andover School District', 'North Reading School District', 'Norwood School District', 'Quincy School District', 'Reading School District', 'Shawsheen Valley Regional Vocational Technical School District', 'Sherborn School District', 'Southborough School District', 'Stoneham School District', 'Sudbury School District', 'Topsfield School District', 'Tyngsborough School District', 'Wakefield School District', 'Wayland School District', 'Wellesley School District', 'Westford School District', 'Weston School District', 'Westwood School District', 'Wilmington School District', 'Winchester School District']\n"
]
}
],
"source": [
"# get the mean rating from the entire population of schools\n",
"mean_rating = boston_df['rating'].mean()\n",
"std_rating = boston_df['rating'].std()\n",
"\n",
"print(f'\\nOf the remaining {len(boston_df)} schools, the average rating is {mean_rating}.')\n",
"\n",
"# compute the average rating for each district\n",
"ave_ratings = {k: np.mean(v) for k, v in boston_df.groupby(by='district-id')['rating']}\n",
"\n",
"# keep only districts that are above the population mean\n",
"not_low_performing = [k for k, v in ave_ratings.items() if v > mean_rating]\n",
"boston_df = boston_df[boston_df['district-id'].isin(not_low_performing)]\n",
"\n",
"districts = sorted(list(boston_df['district-name'].unique()))\n",
"print(f'\\nThere are {len(districts)} districts remaining after pruning districts whose collective average is below the population mean rating.\\n')\n",
"print(f'Which are, {districts}')"
]
},
{
"cell_type": "code",
"execution_count": 243,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
@@ -225,8 +300,8 @@
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th></th>\n",
" <th>state-id</th>\n",
" <th>name</th>\n",
" <th>type</th>\n",
" <th>level-codes</th>\n",
" <th>level</th>\n",
@@ -236,7 +311,6 @@
" <th>county</th>\n",
" <th>lat</th>\n",
" <th>lon</th>\n",
" <th>district-name</th>\n",
" <th>district-id</th>\n",
" <th>rating</th>\n",
" <th>year</th>\n",
@@ -245,9 +319,8 @@
" <th>distance-to-work</th>\n",
" </tr>\n",
" <tr>\n",
" <th>universal-id</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th>district-name</th>\n",
" <th>name</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
@@ -268,342 +341,460 @@
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>2500363</th>\n",
" <td>380013</td>\n",
" <td>Spofford Pond</td>\n",
" <td>public</td>\n",
" <td>e</td>\n",
" <td>3,4,5,6</td>\n",
" <td>Boxford</td>\n",
" <td>MA</td>\n",
" <td>1921</td>\n",
" <td>Essex County</td>\n",
" <td>42.697018</td>\n",
" <td>-71.017365</td>\n",
" <td>Boxford School District</td>\n",
" <td>102</td>\n",
" <td>7.0</td>\n",
" <td>2021.0</td>\n",
" <td>(42.697018, -71.017365)</td>\n",
" <td>22.917933</td>\n",
" <td>19.554889</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2506356</th>\n",
" <td>100305</td>\n",
" <td>Gibbs School</td>\n",
" <td>public</td>\n",
" <td>e,m</td>\n",
" <td>6</td>\n",
" <td>Arlington</td>\n",
" <td>MA</td>\n",
" <td>2474</td>\n",
" <td>Middlesex County</td>\n",
" <td>42.410576</td>\n",
" <td>-71.145081</td>\n",
" <td>Arlington Public Schools</td>\n",
" <td>69</td>\n",
" <td>7.0</td>\n",
" <td>2021.0</td>\n",
" <td>(42.410576, -71.145081)</td>\n",
" <td>4.794958</td>\n",
" <td>7.066929</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2501835</th>\n",
" <td>3470410</td>\n",
" <td>Daniel L Joyce Middle School</td>\n",
" <th rowspan=\"5\" valign=\"top\">Newton School District</th>\n",
" <th>Charles E Brown Middle School</th>\n",
" <td>2070310</td>\n",
" <td>public</td>\n",
" <td>m</td>\n",
" <td>6,7,8</td>\n",
" <td>Woburn</td>\n",
" <td>Newton Centre</td>\n",
" <td>MA</td>\n",
" <td>1801</td>\n",
" <td>2459</td>\n",
" <td>Middlesex County</td>\n",
" <td>42.477467</td>\n",
" <td>-71.175484</td>\n",
" <td>Woburn School District</td>\n",
" <td>467</td>\n",
" <td>4.0</td>\n",
" <td>42.308750</td>\n",
" <td>-71.190292</td>\n",
" <td>304</td>\n",
" <td>9.0</td>\n",
" <td>2021.0</td>\n",
" <td>(42.477467, -71.175484)</td>\n",
" <td>9.264922</td>\n",
" <td>4.013598</td>\n",
" <td>(42.30875, -71.190292)</td>\n",
" <td>7.300583</td>\n",
" <td>11.852619</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2501714</th>\n",
" <td>3150005</td>\n",
" <td>Claypit Hill School</td>\n",
" <th>Oak Hill Middle School</th>\n",
" <td>2070320</td>\n",
" <td>public</td>\n",
" <td>m</td>\n",
" <td>6,7,8</td>\n",
" <td>Newton</td>\n",
" <td>MA</td>\n",
" <td>2459</td>\n",
" <td>Middlesex County</td>\n",
" <td>42.310009</td>\n",
" <td>-71.191544</td>\n",
" <td>304</td>\n",
" <td>8.0</td>\n",
" <td>2021.0</td>\n",
" <td>(42.310009, -71.191544)</td>\n",
" <td>7.306174</td>\n",
" <td>11.751548</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Countryside Elementary School</th>\n",
" <td>2070040</td>\n",
" <td>public</td>\n",
" <td>e</td>\n",
" <td>KG,1,2,3,4,5</td>\n",
" <td>Wayland</td>\n",
" <td>Newton Highlands</td>\n",
" <td>MA</td>\n",
" <td>1778</td>\n",
" <td>2461</td>\n",
" <td>Middlesex County</td>\n",
" <td>42.373108</td>\n",
" <td>-71.344765</td>\n",
" <td>Wayland School District</td>\n",
" <td>434</td>\n",
" <td>42.313141</td>\n",
" <td>-71.202377</td>\n",
" <td>304</td>\n",
" <td>7.0</td>\n",
" <td>2021.0</td>\n",
" <td>(42.313141, -71.202377)</td>\n",
" <td>7.667944</td>\n",
" <td>11.403174</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Memorial Spaulding Elementary School</th>\n",
" <td>2070105</td>\n",
" <td>public</td>\n",
" <td>e</td>\n",
" <td>KG,1,2,3,4,5</td>\n",
" <td>Newton Centre</td>\n",
" <td>MA</td>\n",
" <td>2459</td>\n",
" <td>Middlesex County</td>\n",
" <td>42.302044</td>\n",
" <td>-71.177696</td>\n",
" <td>304</td>\n",
" <td>8.0</td>\n",
" <td>2021.0</td>\n",
" <td>(42.373108, -71.344765)</td>\n",
" <td>13.952791</td>\n",
" <td>8.347379</td>\n",
" <td>(42.302044, -71.177696)</td>\n",
" <td>7.062535</td>\n",
" <td>12.483971</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2502631</th>\n",
" <td>1810055</td>\n",
" <td>Tenney Grammar School</td>\n",
" <td>public</td>\n",
" <td>p,e,m</td>\n",
" <td>PK,KG,1,2,3,4,5,6,7,8</td>\n",
" <td>Methuen</td>\n",
" <td>MA</td>\n",
" <td>1844</td>\n",
" <td>Essex County</td>\n",
" <td>42.732357</td>\n",
" <td>-71.177345</td>\n",
" <td>Methuen School District</td>\n",
" <td>270</td>\n",
" <td>3.0</td>\n",
" <td>2021.0</td>\n",
" <td>(42.732357, -71.177345)</td>\n",
" <td>25.763243</td>\n",
" <td>18.273064</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2500515</th>\n",
" <td>710505</td>\n",
" <td>Danvers High School</td>\n",
" <th>Newton South High School</th>\n",
" <td>2070510</td>\n",
" <td>public</td>\n",
" <td>h</td>\n",
" <td>9,10,11,12,UG</td>\n",
" <td>Danvers</td>\n",
" <td>9,10,11,12</td>\n",
" <td>Newton Centre</td>\n",
" <td>MA</td>\n",
" <td>1923</td>\n",
" <td>Essex County</td>\n",
" <td>42.582523</td>\n",
" <td>-70.931618</td>\n",
" <td>Danvers School District</td>\n",
" <td>141</td>\n",
" <td>6.0</td>\n",
" <td>2021.0</td>\n",
" <td>(42.582523, -70.931618)</td>\n",
" <td>16.464503</td>\n",
" <td>18.045917</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2501498</th>\n",
" <td>2740410</td>\n",
" <td>Next Wave Junior High School</td>\n",
" <td>public</td>\n",
" <td>m</td>\n",
" <td>7,8</td>\n",
" <td>Somerville</td>\n",
" <td>MA</td>\n",
" <td>2145</td>\n",
" <td>2459</td>\n",
" <td>Middlesex County</td>\n",
" <td>42.387581</td>\n",
" <td>-71.087326</td>\n",
" <td>Somerville School District</td>\n",
" <td>383</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>(42.387581, -71.087326)</td>\n",
" <td>1.609308</td>\n",
" <td>10.378716</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2501384</th>\n",
" <td>2430310</td>\n",
" <td>Broad Meadows Middle School</td>\n",
" <td>public</td>\n",
" <td>m</td>\n",
" <td>6,7,8</td>\n",
" <td>Quincy</td>\n",
" <td>MA</td>\n",
" <td>2169</td>\n",
" <td>Norfolk County</td>\n",
" <td>42.259659</td>\n",
" <td>-70.985237</td>\n",
" <td>Quincy School District</td>\n",
" <td>349</td>\n",
" <td>4.0</td>\n",
" <td>42.314308</td>\n",
" <td>-71.186493</td>\n",
" <td>304</td>\n",
" <td>7.0</td>\n",
" <td>2021.0</td>\n",
" <td>(42.259659, -70.985237)</td>\n",
" <td>8.646003</td>\n",
" <td>20.169491</td>\n",
" <td>(42.314308, -71.186493)</td>\n",
" <td>6.929197</td>\n",
" <td>11.540487</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2500916</th>\n",
" <td>1570006</td>\n",
" <td>Hanscom Primary School</td>\n",
" <td>public</td>\n",
" <td>p,e</td>\n",
" <td>PK,KG,1,2,3</td>\n",
" <td>Hanscom Air Force Bs</td>\n",
" <td>MA</td>\n",
" <td>1731</td>\n",
" <td>Middlesex County</td>\n",
" <td>42.456898</td>\n",
" <td>-71.278549</td>\n",
" <td>Lincoln School District</td>\n",
" <td>242</td>\n",
" <td>3.0</td>\n",
" <td>2021.0</td>\n",
" <td>(42.456898, -71.278549)</td>\n",
" <td>12.234463</td>\n",
" <td>1.705602</td>\n",
" <th>...</th>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2501788</th>\n",
" <td>3360065</td>\n",
" <td>Lawrence W Pingree</td>\n",
" <th>Groton-Dunstable School District</th>\n",
" <th>Florence Roche School</th>\n",
" <td>6730010</td>\n",
" <td>public</td>\n",
" <td>e</td>\n",
" <td>KG,1,2,3,4</td>\n",
" <td>Weymouth</td>\n",
" <td>Groton</td>\n",
" <td>MA</td>\n",
" <td>2189</td>\n",
" <td>Norfolk County</td>\n",
" <td>42.217670</td>\n",
" <td>-70.925240</td>\n",
" <td>Weymouth School District</td>\n",
" <td>455</td>\n",
" <td>1450</td>\n",
" <td>Middlesex County</td>\n",
" <td>42.616894</td>\n",
" <td>-71.577682</td>\n",
" <td>198</td>\n",
" <td>7.0</td>\n",
" <td>2021.0</td>\n",
" <td>(42.616894, -71.577682)</td>\n",
" <td>31.001218</td>\n",
" <td>19.195452</td>\n",
" </tr>\n",
" <tr>\n",
" <th rowspan=\"2\" valign=\"top\">Tyngsborough School District</th>\n",
" <th>Tyngsborough Middle School</th>\n",
" <td>3010305</td>\n",
" <td>public</td>\n",
" <td>m</td>\n",
" <td>6,7,8</td>\n",
" <td>Tyngsborough</td>\n",
" <td>MA</td>\n",
" <td>1879</td>\n",
" <td>Middlesex County</td>\n",
" <td>42.696640</td>\n",
" <td>-71.406586</td>\n",
" <td>418</td>\n",
" <td>6.0</td>\n",
" <td>2021.0</td>\n",
" <td>(42.69664, -71.406586)</td>\n",
" <td>28.415381</td>\n",
" <td>17.226867</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Tyngsborough High School</th>\n",
" <td>3010505</td>\n",
" <td>public</td>\n",
" <td>h</td>\n",
" <td>9,10,11,12</td>\n",
" <td>Tyngsborough</td>\n",
" <td>MA</td>\n",
" <td>1879</td>\n",
" <td>Middlesex County</td>\n",
" <td>42.697529</td>\n",
" <td>-71.408226</td>\n",
" <td>418</td>\n",
" <td>8.0</td>\n",
" <td>2021.0</td>\n",
" <td>(42.21767, -70.92524)</td>\n",
" <td>12.754639</td>\n",
" <td>24.381842</td>\n",
" <td>(42.697529, -71.408226)</td>\n",
" <td>28.514503</td>\n",
" <td>17.319230</td>\n",
" </tr>\n",
" <tr>\n",
" <th rowspan=\"2\" valign=\"top\">Groton-Dunstable School District</th>\n",
" <th>Swallow/Union School</th>\n",
" <td>6730005</td>\n",
" <td>public</td>\n",
" <td>e</td>\n",
" <td>KG,1,2,3,4</td>\n",
" <td>Dunstable</td>\n",
" <td>MA</td>\n",
" <td>1827</td>\n",
" <td>Middlesex County</td>\n",
" <td>42.673241</td>\n",
" <td>-71.482529</td>\n",
" <td>198</td>\n",
" <td>9.0</td>\n",
" <td>2021.0</td>\n",
" <td>(42.673241, -71.482529)</td>\n",
" <td>29.723989</td>\n",
" <td>18.012628</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Groton-Dunstable Regional High School</th>\n",
" <td>6730505</td>\n",
" <td>public</td>\n",
" <td>h</td>\n",
" <td>9,10,11,12,UG</td>\n",
" <td>Groton</td>\n",
" <td>MA</td>\n",
" <td>1450</td>\n",
" <td>Middlesex County</td>\n",
" <td>42.651093</td>\n",
" <td>-71.540405</td>\n",
" <td>198</td>\n",
" <td>10.0</td>\n",
" <td>2021.0</td>\n",
" <td>(42.651093, -71.540405)</td>\n",
" <td>30.877490</td>\n",
" <td>19.019974</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>325 rows × 16 columns</p>\n",
"</div>"
],
"text/plain": [
" state-id name type level-codes \\\n",
"universal-id \n",
"2500363 380013 Spofford Pond public e \n",
"2506356 100305 Gibbs School public e,m \n",
"2501835 3470410 Daniel L Joyce Middle School public m \n",
"2501714 3150005 Claypit Hill School public e \n",
"2502631 1810055 Tenney Grammar School public p,e,m \n",
"2500515 710505 Danvers High School public h \n",
"2501498 2740410 Next Wave Junior High School public m \n",
"2501384 2430310 Broad Meadows Middle School public m \n",
"2500916 1570006 Hanscom Primary School public p,e \n",
"2501788 3360065 Lawrence W Pingree public e \n",
" 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",
"... ... \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",
"\n",
" level city state zip \\\n",
"universal-id \n",
"2500363 3,4,5,6 Boxford MA 1921 \n",
"2506356 6 Arlington MA 2474 \n",
"2501835 6,7,8 Woburn MA 1801 \n",
"2501714 KG,1,2,3,4,5 Wayland MA 1778 \n",
"2502631 PK,KG,1,2,3,4,5,6,7,8 Methuen MA 1844 \n",
"2500515 9,10,11,12,UG Danvers MA 1923 \n",
"2501498 7,8 Somerville MA 2145 \n",
"2501384 6,7,8 Quincy MA 2169 \n",
"2500916 PK,KG,1,2,3 Hanscom Air Force Bs MA 1731 \n",
"2501788 KG,1,2,3,4 Weymouth MA 2189 \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",
"... ... \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",
"\n",
" county lat lon \\\n",
"universal-id \n",
"2500363 Essex County 42.697018 -71.017365 \n",
"2506356 Middlesex County 42.410576 -71.145081 \n",
"2501835 Middlesex County 42.477467 -71.175484 \n",
"2501714 Middlesex County 42.373108 -71.344765 \n",
"2502631 Essex County 42.732357 -71.177345 \n",
"2500515 Essex County 42.582523 -70.931618 \n",
"2501498 Middlesex County 42.387581 -71.087326 \n",
"2501384 Norfolk County 42.259659 -70.985237 \n",
"2500916 Middlesex County 42.456898 -71.278549 \n",
"2501788 Norfolk County 42.217670 -70.925240 \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",
"... ... \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",
"\n",
" district-name district-id rating year \\\n",
"universal-id \n",
"2500363 Boxford School District 102 7.0 2021.0 \n",
"2506356 Arlington Public Schools 69 7.0 2021.0 \n",
"2501835 Woburn School District 467 4.0 2021.0 \n",
"2501714 Wayland School District 434 8.0 2021.0 \n",
"2502631 Methuen School District 270 3.0 2021.0 \n",
"2500515 Danvers School District 141 6.0 2021.0 \n",
"2501498 Somerville School District 383 NaN NaN \n",
"2501384 Quincy School District 349 4.0 2021.0 \n",
"2500916 Lincoln School District 242 3.0 2021.0 \n",
"2501788 Weymouth School District 455 8.0 2021.0 \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",
"\n",
" coordinates distance-to-downtown distance-to-work \n",
"universal-id \n",
"2500363 (42.697018, -71.017365) 22.917933 19.554889 \n",
"2506356 (42.410576, -71.145081) 4.794958 7.066929 \n",
"2501835 (42.477467, -71.175484) 9.264922 4.013598 \n",
"2501714 (42.373108, -71.344765) 13.952791 8.347379 \n",
"2502631 (42.732357, -71.177345) 25.763243 18.273064 \n",
"2500515 (42.582523, -70.931618) 16.464503 18.045917 \n",
"2501498 (42.387581, -71.087326) 1.609308 10.378716 \n",
"2501384 (42.259659, -70.985237) 8.646003 20.169491 \n",
"2500916 (42.456898, -71.278549) 12.234463 1.705602 \n",
"2501788 (42.21767, -70.92524) 12.754639 24.381842 "
" 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",
"\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",
"... ... \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",
"\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",
"... ... \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",
"\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",
"... ... \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",
"\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",
"... ... \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",
"\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",
"... ... \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",
"\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",
"... ... \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",
"\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",
"... ... \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",
"\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",
"... ... \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",
"\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",
"... ... \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",
"\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",
"... ... \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",
"\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",
"... ... \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",
"\n",
"[325 rows x 16 columns]"
]
},
"execution_count": 38,
"execution_count": 243,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# calculate distance to PoI using geo-center of districts\n",
"distances_to_downtown = {k: np.mean(list(v)) for k, v in boston_df.groupby('district-id')['distance-to-downtown']}\n",
"distances_to_work = {k: np.mean(list(v)) for k, v in boston_df.groupby('district-id')['distance-to-work']}\n",
"\n",
"df_downtown = pd.DataFrame.from_dict(distances_to_downtown, orient='index')\n",
"df_work = pd.DataFrame.from_dict(distances_to_work, orient='index')\n",
"\n",
"# merge these new columns\n",
"both_df = pd.merge(left=df_downtown, right=df_work, how='inner', left_index=True, right_index=True)\n",
"both_df.rename(columns={'0_x': \"downtown\", '0_y': \"work\"}, inplace=True)\n",
"\n",
"both_df = both_df[both_df[\"downtown\"] < 35.0]\n",
"both_df = both_df[both_df[\"work\"] < 25.0]\n",
"\n",
"print(f'There are {len(both_df)} school districts within reasonable proximity to downtown and work.\\n')\n",
"\n",
"# filter out all schools which aren't in proximal districts\n",
"proximal_district_ids = list(both_df.index)\n",
"boston_df = boston_df[boston_df['district-id'].isin(proximal_district_ids)]\n",
"\n",
"print(f'There are {len(boston_df)} schools within these proximal districts.\\n')\n",
"\n",
"boston_df.sample(10)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Some of these districts don't have enough rating data. Those should be dropped."
]
},
{
"cell_type": "code",
"execution_count": 40,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<pandas.core.groupby.generic.DataFrameGroupBy object at 0x7f54f95addf0>"
]
},
"execution_count": 40,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"boston_df.groupby(['district-id'])"
"boston_df.set_index(['district-name','name'],inplace=True)\n",
"boston_df"
]
}
],