-
Notifications
You must be signed in to change notification settings - Fork 6
/
app.py
67 lines (48 loc) · 1.76 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# -*- coding: utf-8 -*-
"""
Created on Tue Aug 9 13:30:07 2022
@author: avery
"""
import pandas as pd
import streamlit as st
import plotly.express as px
# import data
df = pd.read_csv('NBALineup2021.csv')
# Title for app
st.set_page_config(layout="wide")
st.title('NBA Lineup Analysis Tool ')
# User chooses team
team = st.selectbox(
'Choose Your Team:',
df['team'].unique())
# Get just the selected team
df_team = df[df['team'] == team].reset_index(drop=True)
# Get players on roster
df_team['players_list'] = df_team['players_list'].str.replace(r"[\"\' \[\]]", '').str.split(',')
duplicate_roster = df_team['players_list'].apply(pd.Series).stack()
roster = duplicate_roster.unique()
players = st.multiselect(
'Select your players',
roster,
roster[0:5])
# Find the right line up
df_lineup = df_team[df_team['players_list'].apply(lambda x: set(x)==set(players))]
df_important = df_lineup[['MIN', 'PLUS_MINUS','FG_PCT', 'FG3_PCT']]
st.dataframe(df_important)
col1, col2, col3, col4 = st.columns(4)
with col1:
fig_min = px.histogram(df_team, x="MIN")
fig_min.add_vline(x=df_important['MIN'].values[0],line_color='red')
st.plotly_chart(fig_min, use_container_width=True)
with col2:
fig_2 = px.histogram(df_team, x="PLUS_MINUS")
fig_2.add_vline(x=df_important['PLUS_MINUS'].values[0],line_color='red')
st.plotly_chart(fig_2, use_container_width=True)
with col3:
fig_3 = px.histogram(df_team, x="FG_PCT")
fig_3.add_vline(x=df_important['FG_PCT'].values[0],line_color='red')
st.plotly_chart(fig_3, use_container_width=True)
with col4:
fig_4 = px.histogram(df_team, x="FG3_PCT")
fig_4.add_vline(x=df_important['FG3_PCT'].values[0],line_color='red')
st.plotly_chart(fig_4, use_container_width=True)