Spaces:
Running
Running
Update pages/1player_information.py
Browse files- pages/1player_information.py +53 -22
pages/1player_information.py
CHANGED
@@ -3,17 +3,46 @@ import pandas as pd
|
|
3 |
import matplotlib.pyplot as plt
|
4 |
import seaborn as sns
|
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
# Load data
|
7 |
-
file_path = "Final.csv"
|
8 |
df = pd.read_csv(file_path)
|
9 |
|
10 |
-
st.title("South Africa Cricket Players - Career Visualizations")
|
11 |
-
|
12 |
# Enter Player Name
|
13 |
player_input = st.text_input("Enter Player Name:")
|
14 |
|
15 |
if player_input:
|
16 |
selected_player = player_input.strip()
|
|
|
17 |
if selected_player in df["Player"].values:
|
18 |
player_data = df[df["Player"] == selected_player].iloc[0]
|
19 |
|
@@ -25,9 +54,11 @@ if player_input:
|
|
25 |
player_data["Matches_IPL"]
|
26 |
]
|
27 |
labels = ["Test", "ODI", "T20", "IPL"]
|
|
|
28 |
fig, ax = plt.subplots()
|
29 |
-
ax.pie(matches, labels=labels, autopct="%1.1f%%", startangle=90,
|
30 |
-
|
|
|
31 |
st.pyplot(fig)
|
32 |
|
33 |
# Bar Chart - Runs Scored in Different Formats
|
@@ -38,17 +69,17 @@ if player_input:
|
|
38 |
player_data["batting_Runs_IPL"]
|
39 |
]
|
40 |
fig, ax = plt.subplots()
|
41 |
-
ax.bar(labels, batting_runs, color=["
|
42 |
-
ax.set_ylabel("Runs Scored")
|
43 |
-
ax.set_title(f"Runs Scored by {selected_player}")
|
44 |
st.pyplot(fig)
|
45 |
|
46 |
-
# Scatter Plot - Matches vs Runs
|
47 |
fig, ax = plt.subplots()
|
48 |
-
sns.scatterplot(x=df["Matches_ODI"], y=df["batting_Runs_ODI"], ax=ax)
|
49 |
-
ax.set_xlabel("Matches Played")
|
50 |
-
ax.set_ylabel("Runs Scored")
|
51 |
-
ax.set_title("Matches vs Runs in ODIs (All Players)")
|
52 |
st.pyplot(fig)
|
53 |
|
54 |
# Line Chart - Batting Average Over Formats
|
@@ -59,18 +90,18 @@ if player_input:
|
|
59 |
player_data["batting_Runs_IPL"] / max(1, player_data["batting_Innings_IPL"])
|
60 |
]
|
61 |
fig, ax = plt.subplots()
|
62 |
-
ax.plot(labels, batting_average, marker='o', linestyle='-', color='
|
63 |
-
ax.set_ylabel("Batting Average")
|
64 |
-
ax.set_title(f"Batting Average of {selected_player}")
|
65 |
st.pyplot(fig)
|
66 |
|
67 |
# Histogram - Distribution of Runs Scored by All Players in ODIs
|
68 |
fig, ax = plt.subplots()
|
69 |
-
sns.histplot(df["batting_Runs_ODI"], bins=20, kde=True, color='
|
70 |
-
ax.set_xlabel("Runs Scored")
|
71 |
-
ax.set_ylabel("Frequency")
|
72 |
-
ax.set_title("Distribution of Runs Scored in ODIs (All Players)")
|
73 |
st.pyplot(fig)
|
74 |
-
else:
|
75 |
-
st.error("Player not found! Please enter a valid player name.")
|
76 |
|
|
|
|
|
|
3 |
import matplotlib.pyplot as plt
|
4 |
import seaborn as sns
|
5 |
|
6 |
+
# Set page configuration
|
7 |
+
st.set_page_config(page_title="Cricket Legends: Career Insights & Visualizations", layout="wide")
|
8 |
+
|
9 |
+
# Cricket-Themed Background
|
10 |
+
page_bg = """
|
11 |
+
<style>
|
12 |
+
[data-testid="stAppViewContainer"] {
|
13 |
+
background: url("https://wallpapercave.com/wp/wp7418478.jpg");
|
14 |
+
background-size: cover;
|
15 |
+
}
|
16 |
+
[data-testid="stHeader"] {
|
17 |
+
background: rgba(0,0,0,0);
|
18 |
+
}
|
19 |
+
[data-testid="stSidebar"] {
|
20 |
+
background: rgba(0,0,0,0.9);
|
21 |
+
}
|
22 |
+
h1, h2, h3, h4, h5, h6 {
|
23 |
+
color: white !important;
|
24 |
+
}
|
25 |
+
.stTextInput>div>div>input {
|
26 |
+
background-color: #f5f5f5;
|
27 |
+
color: black;
|
28 |
+
}
|
29 |
+
</style>
|
30 |
+
"""
|
31 |
+
st.markdown(page_bg, unsafe_allow_html=True)
|
32 |
+
|
33 |
+
# App Title
|
34 |
+
st.title("🏏 Cricket Legends: Career Insights & Visualizations")
|
35 |
+
|
36 |
# Load data
|
37 |
+
file_path = "Final.csv" # Ensure this file exists in your working directory
|
38 |
df = pd.read_csv(file_path)
|
39 |
|
|
|
|
|
40 |
# Enter Player Name
|
41 |
player_input = st.text_input("Enter Player Name:")
|
42 |
|
43 |
if player_input:
|
44 |
selected_player = player_input.strip()
|
45 |
+
|
46 |
if selected_player in df["Player"].values:
|
47 |
player_data = df[df["Player"] == selected_player].iloc[0]
|
48 |
|
|
|
54 |
player_data["Matches_IPL"]
|
55 |
]
|
56 |
labels = ["Test", "ODI", "T20", "IPL"]
|
57 |
+
|
58 |
fig, ax = plt.subplots()
|
59 |
+
ax.pie(matches, labels=labels, autopct="%1.1f%%", startangle=90,
|
60 |
+
colors=["#6495ED", "#3CB371", "#FF6347", "#9370DB"])
|
61 |
+
ax.set_title(f"Matches Played by {selected_player}", fontsize=14)
|
62 |
st.pyplot(fig)
|
63 |
|
64 |
# Bar Chart - Runs Scored in Different Formats
|
|
|
69 |
player_data["batting_Runs_IPL"]
|
70 |
]
|
71 |
fig, ax = plt.subplots()
|
72 |
+
ax.bar(labels, batting_runs, color=["#FFD700", "#008000", "#1E90FF", "#FF4500"])
|
73 |
+
ax.set_ylabel("Runs Scored", fontsize=12)
|
74 |
+
ax.set_title(f"Runs Scored by {selected_player}", fontsize=14)
|
75 |
st.pyplot(fig)
|
76 |
|
77 |
+
# Scatter Plot - Matches vs Runs (ODIs)
|
78 |
fig, ax = plt.subplots()
|
79 |
+
sns.scatterplot(x=df["Matches_ODI"], y=df["batting_Runs_ODI"], ax=ax, color="#1E90FF", edgecolor='black')
|
80 |
+
ax.set_xlabel("Matches Played", fontsize=12)
|
81 |
+
ax.set_ylabel("Runs Scored", fontsize=12)
|
82 |
+
ax.set_title("Matches vs Runs in ODIs (All Players)", fontsize=14)
|
83 |
st.pyplot(fig)
|
84 |
|
85 |
# Line Chart - Batting Average Over Formats
|
|
|
90 |
player_data["batting_Runs_IPL"] / max(1, player_data["batting_Innings_IPL"])
|
91 |
]
|
92 |
fig, ax = plt.subplots()
|
93 |
+
ax.plot(labels, batting_average, marker='o', linestyle='-', color='#FFA500', linewidth=2)
|
94 |
+
ax.set_ylabel("Batting Average", fontsize=12)
|
95 |
+
ax.set_title(f"Batting Average of {selected_player}", fontsize=14)
|
96 |
st.pyplot(fig)
|
97 |
|
98 |
# Histogram - Distribution of Runs Scored by All Players in ODIs
|
99 |
fig, ax = plt.subplots()
|
100 |
+
sns.histplot(df["batting_Runs_ODI"], bins=20, kde=True, color='#3CB371', ax=ax)
|
101 |
+
ax.set_xlabel("Runs Scored", fontsize=12)
|
102 |
+
ax.set_ylabel("Frequency", fontsize=12)
|
103 |
+
ax.set_title("Distribution of Runs Scored in ODIs (All Players)", fontsize=14)
|
104 |
st.pyplot(fig)
|
|
|
|
|
105 |
|
106 |
+
else:
|
107 |
+
st.error("🚨 Player not found! Please enter a valid player name.")
|