This file contains hidden or 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
| # ========== (c) JP Hwang 22/8/20 ========== | |
| import logging | |
| # ===== START LOGGER ===== | |
| logger = logging.getLogger(__name__) | |
| root_logger = logging.getLogger() | |
| root_logger.setLevel(logging.INFO) | |
| sh = logging.StreamHandler() | |
| formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') |
This file contains hidden or 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
| >>> per_gm_df | |
| name g mp ... pf pts link | |
| 0 Dallas Mavericks 75 242.3 ... 19.5 117.0 /teams/DAL/2020.html | |
| 1 Milwaukee Bucks 73 241.0 ... 19.6 118.7 /teams/MIL/2020.html | |
| 2 Portland Trail Blazers 74 241.0 ... 21.7 115.0 /teams/POR/2020.html | |
| 3 Houston Rockets 72 241.4 ... 21.8 117.8 /teams/HOU/2020.html | |
| 4 Los Angeles Clippers 72 241.4 ... 22.1 116.3 /teams/LAC/2020.html | |
| 5 New Orleans Pelicans 72 242.1 ... 21.2 115.8 /teams/NOP/2020.html | |
| 6 Phoenix Suns 73 241.0 ... 22.0 113.6 /teams/PHO/2020.html | |
| 7 Washington Wizards 72 241.0 ... 22.7 114.4 /teams/WAS/2020.html |
This file contains hidden or 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
| # ========== (c) JP Hwang 22/8/20 ========== | |
| import logging | |
| # ===== START LOGGER ===== | |
| logger = logging.getLogger(__name__) | |
| root_logger = logging.getLogger() | |
| root_logger.setLevel(logging.INFO) | |
| sh = logging.StreamHandler() | |
| formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') |
This file contains hidden or 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
| data_rows = table.find_all("tr") # Includes the header row! | |
| parsed_data = list() | |
| team_attr = {"data-stat" : "team_name"} | |
| stat_keys = [col.attrs["data-stat"] for col in data_rows[0].find_all("th")] | |
| for row in data_rows: | |
| tmp_data = dict() | |
| if row.find(attrs=team_attr).find("a") is not None: | |
| team_link = row.find(attrs=team_attr).find("a").attrs["href"] | |
| tmp_data["name"] = row.find(attrs=team_attr).find("a").text |
This file contains hidden or 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
| # ========== (c) JP Hwang 27/7/20 ========== | |
| from shared_funcs import load_fig | |
| fig = load_fig() | |
| import streamlit as st | |
| st.header("Houston Rockets Shot Chart - 2020 Season") | |
| st.write("This chart shows the shot distribution of the NBA team Houston Rockets, based on particular areas of the court, and their expected points per shot (i.e. efficiency) from each area.") | |
| st.write("Use the dropdown menu to change the color scale for the shot chart.") | |
| choice = st.selectbox( |
This file contains hidden or 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
| # ========== (c) JP Hwang 27/7/20 ========== | |
| from shared_funcs import load_fig | |
| fig = load_fig() | |
| import dash | |
| import dash_html_components as html | |
| import dash_core_components as dcc | |
| from dash.dependencies import Input, Output | |
| external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css'] |
This file contains hidden or 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
| bins = [0, 10000, 25000, 65000, np.inf] | |
| names = ['<10k', '10k-25k', '25k-65k', '65k+'] | |
| x = pd.cut(tmp_df["POP_ESTIMATE_2018"], bins=bins, labels=names) | |
| tmp_df = data_df.assign(pop_bin=x) | |
| bins = [0, 40000, 50000, 60000, 70000, 80000, np.inf] | |
| names = ['<40k', '40k-50k', '50k-60k', '60k-70k', '70k-80k', '80k+'] | |
| x = pd.cut(tmp_df["Median_Household_Income_2018"], bins=bins, labels=names) | |
| tmp_df = tmp_df.assign(income_bin=x) |
This file contains hidden or 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
| # Map showing counties with typical income < 40k | |
| tmp_df = data_df[data_df["Median_Household_Income_2018"] < 40000] | |
| tmp_df = tmp_df.assign(tmp=1) | |
| fig = go.Figure(go.Choroplethmapbox(geojson=counties, locations=tmp_df.fips, z=tmp_df.tmp, | |
| colorscale=px.colors.sequential.Teal, marker_line_width=0)) | |
| fig.update_layout(mapbox_style="carto-positron", | |
| mapbox_zoom=3, mapbox_center = {"lat": 37.0902, "lon": -95.7129}, | |
| margin={"r":0,"t":0,"l":0,"b":0}) | |
| fig.show() |
This file contains hidden or 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
| fig = go.Figure(go.Choroplethmapbox(geojson=counties, locations=data_df.fips, z=data_df["Median_Household_Income_2018"], | |
| colorscale="Greens", marker_line_width=0)) | |
| fig.update_layout(mapbox_style="carto-positron", | |
| mapbox_zoom=3, mapbox_center = {"lat": 37.0902, "lon": -95.7129}, | |
| margin={"r":0,"t":0,"l":0,"b":0}) | |
| fig.show() |
This file contains hidden or 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
| >>> data_df.info() | |
| <class 'pandas.core.frame.DataFrame'> | |
| Int64Index: 3223 entries, 0 to 3222 | |
| Data columns (total 12 columns): | |
| # Column Non-Null Count Dtype | |
| --- ------ -------------- ----- | |
| 0 fips 3223 non-null int64 |