Skip to content

Commit

Permalink
Update football.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ceebeeaka89 authored Feb 21, 2023
1 parent 718545c commit dd95d21
Showing 1 changed file with 30 additions and 31 deletions.
61 changes: 30 additions & 31 deletions football.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# dribbler : high dribbling, concedes fowls
# ALL: played lots of games..!


#creating the columns for the radar through a function
def extra_columns(df):
df["goals_per_game"] = df["goals"] / df["games"]
df["assists_per_game"] = df["assists"] / df["games"]
Expand All @@ -32,6 +34,8 @@ def extra_columns(df):
extra_columns(df)


#calling values for the radar through a function

def plot_radars(df):
ranks = df.copy()

Expand All @@ -40,15 +44,20 @@ def plot_radars(df):
include = list(set(target_man_cols + dribbler_cols))
print(include)


# add up the rank for each of these columns

ranks[include] = ranks[include].rank(method="dense", ascending=True)
factor = len(df) / 10
ranks[include] = ranks[include] / factor
targetmen = ranks.loc[ranks["player type"] == "target man", include + ["name"]]
targetmen["ranksum"] = targetmen[target_man_cols].sum(axis=1)
dribblers = ranks.loc[ranks["player type"] == "dribbler", include + ["name"]]
dribblers["ranksum"] = dribblers[dribbler_cols].sum(axis=1)



#ranking for top target man and dribbler

targetmen = targetmen.sort_values("ranksum", ascending=False)
dribblers = dribblers.sort_values("ranksum", ascending=False)

Expand All @@ -58,14 +67,13 @@ def plot_radars(df):
top_dribbler = dribblers.iloc[0]
top_dribbler_name = top_dribbler["name"]
top_dribbler_values = top_dribbler[include]
print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@")

print(targetmen)

print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@")

print(dribblers)
print("################################")



#creating a range for the attributes

ranges = []
targetman_value = []
dribbler_value = []
Expand All @@ -81,6 +89,9 @@ def plot_radars(df):

print(ranges)


# Adding visualise presentation for the radar plot

T = dict(
title_name=top_target_man_name,
title_color='blue',
Expand All @@ -96,42 +107,30 @@ def plot_radars(df):

plt.rcParams["font.family"] = "Arial"

# Plotting the data

radar = Radar(fontfamily="Arial", background_color="black", patch_color="#28252C", label_color="white",
range_color="#BFE9BF")

fig, ax = radar.plot_radar(ranges=ranges, params=include, fontfamily="Arial",
values=S1, alphas=[0.76, 0.6],
title=T, endnote="hello there noe", radar_color=['#0f4c75', '#e94560'], compare=True)
title=T, endnote="Data from API Football", radar_color=['#0f4c75', '#e94560'], compare=True)
plt.show()


pandas.set_option('display.max_columns', None)
plot_radars(df)

pandas.set_option('display.max_columns', None)
plot_radars(df)
1 / 0
params = ["goals_per_game", "assists_per_game", "duels_win_percent",
"dribble_percent", "duels_win_percent", "penalty scored per game"]



pandas.set_option('display.max_columns', None)
print(df)
range()

# Params is a variable that lists the attributes for the radar

# plot_radars(df)
params = ["goals_per_game", "assists_per_game", "duels_win_percent",
"dribble_percent", "duels_win_percent", "penalty scored per game"]

def comparetogoals(df, y):
ax = sns.scatterplot(df, x="goals", y=y, hue="name")
plt.xlabel('Goals Scored')
plt.ylabel(y)
plt.title('Goals Scored vs Duels Won')

sns.move_legend(ax, "upper left", bbox_to_anchor=(1, 1))
plt.show()
pandas.set_option('display.max_columns', None)
print(df)
range()


def top_goals_assists(df):
df.plot.bar(x="name", y=["goals", "assists"], figsize=(9, 8))
plt.show()


0 comments on commit dd95d21

Please sign in to comment.