Converted analysis format to jupyter notebook.
This commit is contained in:
118
main/analysis.ipynb
Normal file
118
main/analysis.ipynb
Normal file
@@ -0,0 +1,118 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 22,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# imports\n",
|
||||
"import pandas as pd\n",
|
||||
"import numpy as np\n",
|
||||
"\n",
|
||||
"from great_schools import get_nearby_schools\n",
|
||||
"from secret import get_key"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Shaun and Daniela's Boston Public School Analysis\n",
|
||||
"#### 2021.04.10"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Fetch the API key from the local filesystem."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 23,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# get the API key\n",
|
||||
"api_key_file = '../keys/api.key'\n",
|
||||
"api_key = get_key(api_key_file)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Use the `nearby_schools` API endpoint to grab raw data of all schools within the maximum radius"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 24,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Some columns will dropped immediately as pre-processing.\n",
|
||||
"drops = [\n",
|
||||
" 'nces-id',\n",
|
||||
" 'school-summary',\n",
|
||||
" 'street',\n",
|
||||
" 'fipscounty',\n",
|
||||
" 'phone',\n",
|
||||
" 'fax',\n",
|
||||
" 'web-site',\n",
|
||||
" 'overview-url',\n",
|
||||
" 'rating-description',\n",
|
||||
"]\n",
|
||||
"\n",
|
||||
"# Grab data for Boston.\n",
|
||||
"refresh = False\n",
|
||||
"boston_nearby_schools_file = '../data/nearby_schools/boston.csv'\n",
|
||||
"if refresh:\n",
|
||||
" boston_schools = get_nearby_schools(api_key,\"42.3\",\"-71.2\",\"50\")\n",
|
||||
" boston_df = pd.DataFrame.from_dict(boston_schools)\n",
|
||||
" boston_df.drop(columns=drops,inplace=True)\n",
|
||||
" boston_df.to_csv(boston_nearby_schools_file)\n",
|
||||
"else:\n",
|
||||
" boston_df = pd.read_csv(boston_nearby_schools_file)\n",
|
||||
"\n",
|
||||
"# Grab data for Buffalo.\n",
|
||||
"refresh = False\n",
|
||||
"buffalo_nearby_schools_file = '../data/nearby_schools/buffalo.csv'\n",
|
||||
"if refresh:\n",
|
||||
" buffalo_schools = get_nearby_schools(api_key,\"42.9625\",\"-78.7425\",\"50\")\n",
|
||||
" buffalo_df = pd.DataFrame.from_dict(buffalo_schools)\n",
|
||||
" buffalo_df.drop(columns=drops,inplace=True)\n",
|
||||
" buffalo_df.to_csv(buffalo_nearby_schools_file)\n",
|
||||
"else:\n",
|
||||
" buffalo_df = pd.read_csv(buffalo_nearby_schools_file)"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"interpreter": {
|
||||
"hash": "4fc861b332db140b7b363b167627eee6a3238262e7c99e0237067fec0875fee7"
|
||||
},
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3.8.10 ('venv': venv)",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.8.10"
|
||||
},
|
||||
"orig_nbformat": 4
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
27
main/run.py
27
main/run.py
@@ -1,27 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from secret import get_key
|
||||
from great_schools import get_nearby_schools
|
||||
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
|
||||
# Get secret.
|
||||
api_key_file = '../keys/api.key'
|
||||
api_key = get_key(api_key_file)
|
||||
|
||||
# Grab data for Boston.
|
||||
refresh = False
|
||||
if refresh:
|
||||
boston_nearby_schools_file = '../data/nearby_schools/boston.csv'
|
||||
boston_schools = get_nearby_schools(api_key,"42.3","-71.2","50")
|
||||
boston_df = pd.DataFrame.from_dict(boston_schools)
|
||||
boston_df.to_csv(boston_nearby_schools_file)
|
||||
|
||||
# Grab data for Buffalo.
|
||||
refresh = True
|
||||
if refresh:
|
||||
buffalo_nearby_schools_file = '../data/nearby_schools/buffalo.csv'
|
||||
buffalo_schools = get_nearby_schools(api_key,"42.9625","-78.7425","50")
|
||||
buffalo_df = pd.DataFrame.from_dict(buffalo_schools)
|
||||
buffalo_df.to_csv(buffalo_nearby_schools_file)
|
||||
Reference in New Issue
Block a user