コード例 #1
0
ファイル: app.py プロジェクト: andrewbowen19/SoccerDash
def update_league(league):
    # Getting data
    # soccer_data = SoccerDataAPI()
    print(f'League Selected by user {league}')
    soccer_data = SoccerDataAPI()
    data = pd.DataFrame()
    # Checking for each type of league dfata call
    if league == "Premier League":
        data = soccer_data.english_premier()
        # df = pd.DataFrame(data)

    elif league == "La Liga":
        data = soccer_data.la_liga()
        # df = pd.DataFrame(data)

    elif league == "Serie A":
        data = soccer_data.serie_a()
        # df = pd.DataFrame(data)

    elif league == "Ligue 1":
        data = soccer_data.ligue_1()
        # df = pd.DataFrame(data)

    elif league == "Bundesliga":
        data = soccer_data.bundesliga()
        # df = pd.DataFrame(data)

    # Setting up and converting df
    df = pd.DataFrame(data)

    # Reformatting data in table to be plotly friendly
    cols2int = [
        'pos',
        'wins',
        'losses',
        'draws',
        'losses',
        'goals_for',
        'goals_against',
        'goal_diff',
    ]
    for col in cols2int:
        df[col] = df[col].astype(int)

    # Adding top scorer goals
    get_goals = lambda x: int(x['top_scorer'].split(' - ')[1])
    df['top_scorer_goals'] = df.apply(get_goals, axis=1)

    print(f'{league} data:\n', df)

    # Seeting up scatter
    f = px.scatter(df,
                   x="goal_diff",
                   y="points",
                   text='team',
                   title=league,
                   hover_data=['team', 'top_scorer'],
                   labels={
                       'goal_diff': 'Goal Differential',
                       'points': 'Points'
                   })
    f.update_traces(textposition='middle right')
    f.update_yaxes(autorange="reversed")

    # Attack bar graph
    a_bar = px.bar(df,
                   x='team',
                   y='goals_for',
                   title=f'{league} Attack',
                   labels={
                       'team': '',
                       'goals_for': 'Goals For'
                   })

    # Defense Bar graph
    d_bar = px.bar(df,
                   x='team',
                   y='goals_against',
                   title=f'{league} Defense',
                   labels={
                       'team': '',
                       'goals_against': 'Goals Against'
                   })

    # Goal differential bar graph
    diff_bar = px.bar(df,
                      x='team',
                      y='goal_diff',
                      title=f'{league} Goal Differential',
                      labels={
                          'team': '',
                          'goal_diff': 'Goal Differential'
                      })

    s_bar = px.bar(df,
                   x='top_scorer',
                   y='top_scorer_goals',
                   title=f'{league} Top Scorers',
                   hover_data=['team', 'top_scorer'],
                   labels={
                       'top_scorer': 'Player',
                       'top_scorer_goals': 'Goals'
                   })

    # Goal Diff Bar Graph
    return f, a_bar, d_bar, diff_bar, s_bar
コード例 #2
0
    Output('goal-diff-graph', 'figure')],
    Input('league-dropdown', 'value')
    )
def update_league(league):
    # Getting data
    # soccer_data = SoccerDataAPI()
    print(f'League Selected by user {league}')
    soccer_data = SoccerDataAPI()
    data = pd.DataFrame()
    # Checking for each type of league dfata call
    if league == "Premier League":
        data = soccer_data.english_premier()
        # df = pd.DataFrame(data)

    elif league == "La Liga":
        data = soccer_data.la_liga()
        # df = pd.DataFrame(data)

    elif league == "Serie A":
        data = soccer_data.serie_a()
        # df = pd.DataFrame(data)

    elif league == "Ligue 1":
        data = soccer_data.ligue_1()
        # df = pd.DataFrame(data)

    elif league == "Bundesliga":
        data = soccer_data.bundesliga()
        # df = pd.DataFrame(data)
    
    # Setting up and converting df