Spaces:
Running
Running
Update pages/1player_information.py
Browse files- pages/1player_information.py +106 -55
pages/1player_information.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
import matplotlib.pyplot as plt
|
4 |
-
import seaborn as sns
|
5 |
|
6 |
# Set page configuration
|
7 |
st.set_page_config(page_title="Career Insights", layout="wide")
|
@@ -34,69 +33,121 @@ page_bg = """
|
|
34 |
st.markdown(page_bg, unsafe_allow_html=True)
|
35 |
|
36 |
# App Title
|
37 |
-
st.title("πCareer Insights")
|
38 |
|
39 |
# Load data
|
40 |
file_path = "Final.csv" # Ensure this file exists in your working directory
|
41 |
df = pd.read_csv(file_path)
|
42 |
|
43 |
# Get unique player names
|
44 |
-
player_names = df["Player"].unique()
|
45 |
|
46 |
-
#
|
47 |
-
|
48 |
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
selected_player = st.selectbox("Select Player", filtered_players)
|
54 |
-
else:
|
55 |
-
st.warning("No matching player found.")
|
56 |
-
selected_player = None
|
57 |
-
else:
|
58 |
-
selected_player = None
|
59 |
|
60 |
if selected_player:
|
61 |
player_data = df[df["Player"] == selected_player].iloc[0]
|
62 |
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
import matplotlib.pyplot as plt
|
|
|
4 |
|
5 |
# Set page configuration
|
6 |
st.set_page_config(page_title="Career Insights", layout="wide")
|
|
|
33 |
st.markdown(page_bg, unsafe_allow_html=True)
|
34 |
|
35 |
# App Title
|
36 |
+
st.title("π Career Insights")
|
37 |
|
38 |
# Load data
|
39 |
file_path = "Final.csv" # Ensure this file exists in your working directory
|
40 |
df = pd.read_csv(file_path)
|
41 |
|
42 |
# Get unique player names
|
43 |
+
player_names = sorted(df["Player"].unique())
|
44 |
|
45 |
+
# Dropdown for Player Selection
|
46 |
+
selected_player = st.selectbox("Select a Player:", player_names)
|
47 |
|
48 |
+
# Buttons for Batting & Bowling
|
49 |
+
col1, col2 = st.columns(2)
|
50 |
+
show_batting = col1.button("π Show Batting Stats")
|
51 |
+
show_bowling = col2.button("π― Show Bowling Stats")
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
if selected_player:
|
54 |
player_data = df[df["Player"] == selected_player].iloc[0]
|
55 |
|
56 |
+
if show_batting:
|
57 |
+
st.subheader(f"π Batting Stats of {selected_player}")
|
58 |
+
|
59 |
+
# Pie Chart - Matches Played Across Formats
|
60 |
+
matches = [
|
61 |
+
player_data["Matches_Test"],
|
62 |
+
player_data["Matches_ODI"],
|
63 |
+
player_data["Matches_T20"],
|
64 |
+
player_data["Matches_IPL"]
|
65 |
+
]
|
66 |
+
labels = ["Test", "ODI", "T20", "IPL"]
|
67 |
+
|
68 |
+
fig, ax = plt.subplots()
|
69 |
+
ax.pie(matches, labels=labels, autopct="%1.1f%%", startangle=90,
|
70 |
+
colors=["#87CEEB", "#90EE90", "#FFA07A", "#9370DB"])
|
71 |
+
ax.set_title(f"Matches Played by {selected_player}", fontsize=14)
|
72 |
+
st.pyplot(fig)
|
73 |
+
|
74 |
+
# Bar Chart - Runs Scored in Different Formats
|
75 |
+
batting_runs = [
|
76 |
+
player_data["batting_Runs_Test"],
|
77 |
+
player_data["batting_Runs_ODI"],
|
78 |
+
player_data["batting_Runs_T20"],
|
79 |
+
player_data["batting_Runs_IPL"]
|
80 |
+
]
|
81 |
+
fig, ax = plt.subplots()
|
82 |
+
ax.bar(labels, batting_runs, color=["#FFD700", "#008000", "#1E90FF", "#FF4500"])
|
83 |
+
ax.set_ylabel("Runs Scored", fontsize=12)
|
84 |
+
ax.set_title(f"Runs Scored by {selected_player}", fontsize=14)
|
85 |
+
st.pyplot(fig)
|
86 |
+
|
87 |
+
# Line Chart - Batting Average Over Formats
|
88 |
+
batting_average = [
|
89 |
+
player_data["batting_Runs_Test"] / max(1, player_data["batting_Innings_Test"]),
|
90 |
+
player_data["batting_Runs_ODI"] / max(1, player_data["batting_Innings_ODI"]),
|
91 |
+
player_data["batting_Runs_T20"] / max(1, player_data["batting_Innings_T20"]),
|
92 |
+
player_data["batting_Runs_IPL"] / max(1, player_data["batting_Innings_IPL"])
|
93 |
+
]
|
94 |
+
fig, ax = plt.subplots()
|
95 |
+
ax.plot(labels, batting_average, marker='o', linestyle='-', color='#FFA500', linewidth=2)
|
96 |
+
ax.set_ylabel("Batting Average", fontsize=12)
|
97 |
+
ax.set_title(f"Batting Average of {selected_player}", fontsize=14)
|
98 |
+
st.pyplot(fig)
|
99 |
+
|
100 |
+
if show_bowling:
|
101 |
+
st.subheader(f"π― Bowling Stats of {selected_player}")
|
102 |
+
|
103 |
+
# Pie Chart - Overs Bowled in Different Formats
|
104 |
+
overs_bowled = [
|
105 |
+
player_data["Overs_Bowled_Test"],
|
106 |
+
player_data["Overs_Bowled_ODI"],
|
107 |
+
player_data["Overs_Bowled_T20"],
|
108 |
+
player_data["Overs_Bowled_IPL"]
|
109 |
+
]
|
110 |
+
fig, ax = plt.subplots()
|
111 |
+
ax.pie(overs_bowled, labels=labels, autopct="%1.1f%%", startangle=90,
|
112 |
+
colors=["#FF5733", "#C70039", "#900C3F", "#581845"])
|
113 |
+
ax.set_title(f"Overs Bowled by {selected_player}", fontsize=14)
|
114 |
+
st.pyplot(fig)
|
115 |
+
|
116 |
+
# Bar Chart - Wickets Taken Across Formats
|
117 |
+
wickets = [
|
118 |
+
player_data["Wickets_Test"],
|
119 |
+
player_data["Wickets_ODI"],
|
120 |
+
player_data["Wickets_T20"],
|
121 |
+
player_data["Wickets_IPL"]
|
122 |
+
]
|
123 |
+
fig, ax = plt.subplots()
|
124 |
+
ax.bar(labels, wickets, color=["#FF5733", "#C70039", "#900C3F", "#581845"])
|
125 |
+
ax.set_ylabel("Wickets Taken", fontsize=12)
|
126 |
+
ax.set_title(f"Wickets Taken by {selected_player}", fontsize=14)
|
127 |
+
st.pyplot(fig)
|
128 |
+
|
129 |
+
# Line Chart - Bowling Economy Over Formats
|
130 |
+
bowling_economy = [
|
131 |
+
player_data["Economy_Test"],
|
132 |
+
player_data["Economy_ODI"],
|
133 |
+
player_data["Economy_T20"],
|
134 |
+
player_data["Economy_IPL"]
|
135 |
+
]
|
136 |
+
fig, ax = plt.subplots()
|
137 |
+
ax.plot(labels, bowling_economy, marker='o', linestyle='-', color='#2E86C1', linewidth=2)
|
138 |
+
ax.set_ylabel("Bowling Economy", fontsize=12)
|
139 |
+
ax.set_title(f"Bowling Economy of {selected_player}", fontsize=14)
|
140 |
+
st.pyplot(fig)
|
141 |
+
|
142 |
+
# Line Chart - Bowling Strike Rate Over Formats
|
143 |
+
bowling_strike_rate = [
|
144 |
+
player_data["Strike_Rate_Test"],
|
145 |
+
player_data["Strike_Rate_ODI"],
|
146 |
+
player_data["Strike_Rate_T20"],
|
147 |
+
player_data["Strike_Rate_IPL"]
|
148 |
+
]
|
149 |
+
fig, ax = plt.subplots()
|
150 |
+
ax.plot(labels, bowling_strike_rate, marker='o', linestyle='-', color='#1ABC9C', linewidth=2)
|
151 |
+
ax.set_ylabel("Bowling Strike Rate", fontsize=12)
|
152 |
+
ax.set_title(f"Bowling Strike Rate of {selected_player}", fontsize=14)
|
153 |
+
st.pyplot(fig)
|