Spaces:
Sleeping
Sleeping
Update pages/player_stats.py
Browse files- pages/player_stats.py +97 -33
pages/player_stats.py
CHANGED
@@ -1,54 +1,118 @@
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
|
|
|
|
|
|
3 |
|
4 |
# Load the dataset
|
5 |
df = pd.read_csv("cric_final.csv")
|
6 |
|
7 |
st.title("π Player Performance Dashboard")
|
8 |
|
9 |
-
#
|
10 |
selected_player = st.selectbox("Select a Player", df["Player"].unique())
|
11 |
|
12 |
# Get Player Data
|
13 |
player_data = df[df["Player"] == selected_player]
|
14 |
|
15 |
if not player_data.empty:
|
16 |
-
#
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
with tab1:
|
20 |
-
st.
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
st.
|
34 |
-
|
35 |
-
|
36 |
-
st.write(
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
with tab2:
|
40 |
-
st.
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
else:
|
54 |
st.warning("β οΈ Player not found in the dataset.")
|
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
+
import seaborn as sns
|
4 |
+
import matplotlib.pyplot as plt
|
5 |
+
import plotly.express as px
|
6 |
|
7 |
# Load the dataset
|
8 |
df = pd.read_csv("cric_final.csv")
|
9 |
|
10 |
st.title("π Player Performance Dashboard")
|
11 |
|
12 |
+
# Dropdown to Select Player
|
13 |
selected_player = st.selectbox("Select a Player", df["Player"].unique())
|
14 |
|
15 |
# Get Player Data
|
16 |
player_data = df[df["Player"] == selected_player]
|
17 |
|
18 |
if not player_data.empty:
|
19 |
+
# Replace None/NaN with "-" only in batting and bowling columns
|
20 |
+
batting_cols = [col for col in df.columns if "batting" in col.lower()]
|
21 |
+
bowling_cols = [col for col in df.columns if "bowling" in col.lower()]
|
22 |
+
|
23 |
+
player_data[batting_cols] = player_data[batting_cols].fillna("-")
|
24 |
+
player_data[bowling_cols] = player_data[bowling_cols].fillna("-")
|
25 |
+
|
26 |
+
# Only 2 tabs now: Batting Performance and Bowling Performance
|
27 |
+
tab1, tab2 = st.tabs(["π Batting Performance", "π― Bowling Performance"])
|
28 |
|
29 |
with tab1:
|
30 |
+
st.write("### π Batting Performance")
|
31 |
+
|
32 |
+
# Bar Chart for Batting Runs
|
33 |
+
fig, ax = plt.subplots(figsize=(7, 5))
|
34 |
+
sns.barplot(
|
35 |
+
x=["Test", "ODI", "T20", "IPL"],
|
36 |
+
y=player_data.iloc[0][["batting_Runs_Test", "batting_Runs_ODI", "batting_Runs_T20", "batting_Runs_IPL"]],
|
37 |
+
palette="magma",
|
38 |
+
ax=ax
|
39 |
+
)
|
40 |
+
ax.set_ylabel("Total Runs", fontsize=14)
|
41 |
+
ax.set_title(f"Batting Performance of {selected_player}", fontsize=16)
|
42 |
+
ax.grid(True, axis='y', linestyle='--', alpha=0.7)
|
43 |
+
st.pyplot(fig)
|
44 |
+
|
45 |
+
# Side-by-Side Bar Chart for 50s & 100s
|
46 |
+
st.write("### Half-Centuries (50s) vs Centuries (100s)")
|
47 |
+
fig, ax = plt.subplots(figsize=(7, 5))
|
48 |
+
x_labels = ["Test", "ODI", "T20", "IPL"]
|
49 |
+
x = range(len(x_labels))
|
50 |
+
|
51 |
+
fifties = player_data.iloc[0][["batting_50s_Test", "batting_50s_ODI", "batting_50s_T20", "batting_50s_IPL"]]
|
52 |
+
hundreds = player_data.iloc[0][["batting_100s_Test", "batting_100s_ODI", "batting_100s_T20", "batting_100s_IPL"]]
|
53 |
+
|
54 |
+
width = 0.4
|
55 |
+
|
56 |
+
ax.bar([i - width/2 for i in x], fifties, width=width, label="50s", color="skyblue")
|
57 |
+
ax.bar([i + width/2 for i in x], hundreds, width=width, label="100s", color="orange")
|
58 |
+
|
59 |
+
ax.set_xticks(x)
|
60 |
+
ax.set_xticklabels(x_labels)
|
61 |
+
ax.set_ylabel("Count", fontsize=14)
|
62 |
+
ax.set_title(f"50s vs 100s of {selected_player}", fontsize=16)
|
63 |
+
ax.legend()
|
64 |
+
ax.grid(axis="y", linestyle="--", alpha=0.7)
|
65 |
+
st.pyplot(fig)
|
66 |
+
|
67 |
+
# Pie Chart for Batting Runs Distribution
|
68 |
+
st.write("### Batting Runs Distribution")
|
69 |
+
runs = player_data.iloc[0][["batting_Runs_Test", "batting_Runs_ODI", "batting_Runs_T20", "batting_Runs_IPL"]]
|
70 |
+
labels = ["Test", "ODI", "T20", "IPL"]
|
71 |
+
fig_pie = px.pie(values=runs, names=labels, title="Batting Runs Distribution", color=labels)
|
72 |
+
st.plotly_chart(fig_pie)
|
73 |
+
|
74 |
+
# Line Chart for Batting Averages
|
75 |
+
st.write("### Batting Averages Over Different Formats")
|
76 |
+
batting_averages = player_data.iloc[0][["batting_Average_Test", "batting_Average_ODI", "batting_Average_T20", "batting_Average_IPL"]]
|
77 |
+
fig_line, ax = plt.subplots(figsize=(7, 5))
|
78 |
+
ax.plot(["Test", "ODI", "T20", "IPL"], batting_averages, marker='o', color='tab:blue')
|
79 |
+
ax.set_ylabel("Batting Average", fontsize=14)
|
80 |
+
ax.set_title(f"Batting Averages of {selected_player}", fontsize=16)
|
81 |
+
ax.grid(True, axis='y', linestyle='--', alpha=0.7)
|
82 |
+
st.pyplot(fig_line)
|
83 |
|
84 |
with tab2:
|
85 |
+
st.write("### π― Bowling Performance")
|
86 |
+
|
87 |
+
# Bar Chart for Bowling Wickets
|
88 |
+
fig, ax = plt.subplots(figsize=(7, 5))
|
89 |
+
sns.barplot(
|
90 |
+
x=["Test", "ODI", "T20", "IPL"],
|
91 |
+
y=player_data.iloc[0][["bowling_Test_Wickets", "bowling_ODI_Wickets", "bowling_T20_Wickets", "bowling_IPL_Wickets"]],
|
92 |
+
palette="coolwarm",
|
93 |
+
ax=ax
|
94 |
+
)
|
95 |
+
ax.set_ylabel("Total Wickets", fontsize=14)
|
96 |
+
ax.set_title(f"Bowling Performance of {selected_player}", fontsize=16)
|
97 |
+
ax.grid(True, axis='y', linestyle='--', alpha=0.7)
|
98 |
+
st.pyplot(fig)
|
99 |
+
|
100 |
+
# Pie Chart for Bowling Wickets Distribution
|
101 |
+
st.write("### Bowling Wickets Distribution")
|
102 |
+
wickets = player_data.iloc[0][["bowling_Test_Wickets", "bowling_ODI_Wickets", "bowling_T20_Wickets", "bowling_IPL_Wickets"]]
|
103 |
+
labels = ["Test", "ODI", "T20", "IPL"]
|
104 |
+
fig_pie_bowl = px.pie(values=wickets, names=labels, title="Bowling Wickets Distribution", color=labels)
|
105 |
+
st.plotly_chart(fig_pie_bowl)
|
106 |
+
|
107 |
+
# Line Chart for Bowling Average
|
108 |
+
st.write("### Bowling Averages Over Different Formats")
|
109 |
+
bowling_averages = player_data.iloc[0][["bowling_Test_Avg", "bowling_ODI_Avg", "bowling_T20_Avg", "bowling_IPL_Avg"]]
|
110 |
+
fig_line_bowl, ax = plt.subplots(figsize=(7, 5))
|
111 |
+
ax.plot(["Test", "ODI", "T20", "IPL"], bowling_averages, marker='o', color='tab:green')
|
112 |
+
ax.set_ylabel("Bowling Average", fontsize=14)
|
113 |
+
ax.set_title(f"Bowling Averages of {selected_player}", fontsize=16)
|
114 |
+
ax.grid(True, axis='y', linestyle='--', alpha=0.7)
|
115 |
+
st.pyplot(fig_line_bowl)
|
116 |
|
117 |
else:
|
118 |
st.warning("β οΈ Player not found in the dataset.")
|