From b38b71d2f1c04034739b09c2bb88ebfb65ba3fc1 Mon Sep 17 00:00:00 2001 From: FlyingHoward Date: Sun, 12 Sep 2021 16:59:03 +0800 Subject: [PATCH 1/2] Add files via upload --- streamlit/part5/basketball_app.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/streamlit/part5/basketball_app.py b/streamlit/part5/basketball_app.py index 9dc7283..108d1c8 100644 --- a/streamlit/part5/basketball_app.py +++ b/streamlit/part5/basketball_app.py @@ -17,6 +17,7 @@ selected_year = st.sidebar.selectbox('Year', list(reversed(range(1950,2020)))) # Web scraping of NBA player stats +# year = 2020 @st.cache def load_data(year): url = "https://www.basketball-reference.com/leagues/NBA_" + str(year) + "_per_game.html" @@ -25,6 +26,9 @@ def load_data(year): raw = df.drop(df[df.Age == 'Age'].index) # Deletes repeating headers in content raw = raw.fillna(0) playerstats = raw.drop(['Rk'], axis=1) + playerstats.columns = [i.replace('%', '_percent') for i in playerstats.columns ] + for i in playerstats.filter(regex='percent').columns: + playerstats[i] = playerstats[i].astype(float) return playerstats playerstats = load_data(selected_year) @@ -42,6 +46,8 @@ def load_data(year): st.header('Display Player Stats of Selected Team(s)') st.write('Data Dimension: ' + str(df_selected_team.shape[0]) + ' rows and ' + str(df_selected_team.shape[1]) + ' columns.') st.dataframe(df_selected_team) +# st.dataframe(df_selected_team.iloc[::,0:10]) + # Download NBA player stats data # https://discuss.streamlit.io/t/how-to-download-file-in-streamlit/1806 @@ -65,4 +71,4 @@ def filedownload(df): with sns.axes_style("white"): f, ax = plt.subplots(figsize=(7, 5)) ax = sns.heatmap(corr, mask=mask, vmax=1, square=True) - st.pyplot() + st.pyplot(f) From dc2c938c5970596581de840ad9c4a159d11804fc Mon Sep 17 00:00:00 2001 From: FlyingHoward Date: Sun, 12 Sep 2021 17:01:19 +0800 Subject: [PATCH 2/2] Add files via upload --- streamlit/part5/basketball_app.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/streamlit/part5/basketball_app.py b/streamlit/part5/basketball_app.py index 108d1c8..c0ae5f1 100644 --- a/streamlit/part5/basketball_app.py +++ b/streamlit/part5/basketball_app.py @@ -17,7 +17,6 @@ selected_year = st.sidebar.selectbox('Year', list(reversed(range(1950,2020)))) # Web scraping of NBA player stats -# year = 2020 @st.cache def load_data(year): url = "https://www.basketball-reference.com/leagues/NBA_" + str(year) + "_per_game.html" @@ -26,8 +25,7 @@ def load_data(year): raw = df.drop(df[df.Age == 'Age'].index) # Deletes repeating headers in content raw = raw.fillna(0) playerstats = raw.drop(['Rk'], axis=1) - playerstats.columns = [i.replace('%', '_percent') for i in playerstats.columns ] - for i in playerstats.filter(regex='percent').columns: + for i in playerstats.filter(regex='%').columns: playerstats[i] = playerstats[i].astype(float) return playerstats playerstats = load_data(selected_year) @@ -46,7 +44,6 @@ def load_data(year): st.header('Display Player Stats of Selected Team(s)') st.write('Data Dimension: ' + str(df_selected_team.shape[0]) + ' rows and ' + str(df_selected_team.shape[1]) + ' columns.') st.dataframe(df_selected_team) -# st.dataframe(df_selected_team.iloc[::,0:10]) # Download NBA player stats data