This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Nearest Neighbor | |
import numpy as np | |
from sklearn.neighbors import NearestNeighbors | |
from sklearn.preprocessing import StandardScaler | |
from sklearn.pipeline import make_pipeline | |
# Select columns that will be used to calculate nearest neighbors | |
# Added data points | |
# new = [Transit Score, Bike Score, Total_Schools, Private, Public district, Public Charter, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def run_prophet(series): | |
model = Prophet(daily_seasonality=False, | |
weekly_seasonality=False, | |
yearly_seasonality=False) | |
model.fit(series) | |
forecast = model.make_future_dataframe(periods=10, freq='Y') | |
forecast = model.predict(forecast) | |
forecast = forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']] | |
forecast['City,State'] = series['City,State'].iloc[0] | |
forecast = forecast[['City,State','ds', 'yhat', 'yhat_lower', 'yhat_upper']] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create list of cities | |
cities_list = list(population['City,State']) | |
# group cities from the population_melt.csv | |
def rnd_series(city): | |
subset = population_melt[population_melt['City,State']== city] | |
dates = (pd.DataFrame({'ds': pd.to_datetime(population_melt['ds'])})) | |
return subset | |
# create dictionary of city name and grouped population_melt.csv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
population_melt = (population.melt(id_vars=['City,State'], | |
var_name = 'ds', | |
value_name = 'y' | |
).reset_index(drop=True) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SchoolData(BaseModel): | |
total_schools: int | |
percent_high_performing_schools: float | |
percent_private: float | |
percent_public: float | |
percent_charter: float | |
async def get_school_summary(city: City): | |
"""Retrieve recommended cities for target city |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Schools Listing Endpoint | |
async def schools_listings(current_city:City, school_category): | |
""" | |
Listing of school information for the city | |
(locates specific pickled dictionary based on school category for the city) | |
- Ratings -> sorted, listed from highest to lowest | |
- Type -> public, private, charter | |
- Grades -> pre-k, elementary, middle, high school | |
- District -> district in city |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
table = soup.find("table", { "class" : "" }) | |
for row in table.find_all("tr"): | |
cell = row.find_all("td") | |
if len(cell) == 7: | |
school = row.find('a', {'class':'name'}).text.strip() | |
try: | |
score = row.find('div', {'class': 'circle-rating--small'}).text.strip() | |
except AttributeError: | |
score = '0/10' | |
rating = row.find('div', {'class': 'scale'}).text.strip() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for i in cities['city']: | |
fetching = True | |
page = 0 | |
while fetching: | |
page += 1 | |
url = url_pre + urllib.parse.quote(i) + '/schools/?page={}&tableView=Overview&view=table'.format(page) | |
print("Fetching ", url) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Looping through each city in the file | |
cities = pd.read_csv('csv/cities.csv') | |
records = [] | |
# selenium driver | |
driver = webdriver.Chrome() | |
# url for greatschools pre_url and post_url (with state/city inbetween) | |
url_pre = 'http://www.greatschools.org/' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from state_abbr import us_state_abbrev as abbr | |
# create city state list | |
cities = pd.read_excel('notebooks/datasets/data/schools/csv/List of Cities.xlsx') | |
# just get the second and third colun | |
cities = cities[['Unnamed: 1','Unnamed: 2']] | |
# create new dictionary with reversed key, value pairs | |
full = dict(map(reversed, abbr.items())) |
NewerOlder