Skip to content

Instantly share code, notes, and snippets.

View jiobu1's full-sized avatar
💻
dreaming, learning, thinking

Jisha Obukwelu jiobu1

💻
dreaming, learning, thinking
View GitHub Profile
@jiobu1
jiobu1 / updated_nn.py
Created April 28, 2021 19:10
updated nn model
# 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,
@jiobu1
jiobu1 / prophet_model.py
Created April 28, 2021 15:30
prophet forecast model
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']]
@jiobu1
jiobu1 / series_dict.py
Created April 28, 2021 15:23
create dictionary of cities
# 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
@jiobu1
jiobu1 / prophet_melt.py
Created April 28, 2021 15:10
transform dataframe
population_melt = (population.melt(id_vars=['City,State'],
var_name = 'ds',
value_name = 'y'
).reset_index(drop=True)
)
@jiobu1
jiobu1 / school_summary.py
Last active April 27, 2021 01:24
school summary for each city
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
@jiobu1
jiobu1 / school_endpoint.py
Last active April 27, 2021 01:28
pickled schools endpoint
# 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
@jiobu1
jiobu1 / bs4.py
Created April 26, 2021 20:05
beautfiul soup -> parsing table
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()
@jiobu1
jiobu1 / finding_all_schools.py
Created April 26, 2021 19:36
looping through city amounts
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)
@jiobu1
jiobu1 / great_schools_scraper.py
Created April 26, 2021 03:03
web scraping with selenium and beautiful soup
# 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/'
@jiobu1
jiobu1 / city_dict.py
Created April 26, 2021 02:56
create cities dictionary
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()))