Sathwikchowdary commited on
Commit
fae6d46
Β·
verified Β·
1 Parent(s): 1d44339

Update pages/1player_information.py

Browse files
Files changed (1) hide show
  1. pages/1player_information.py +40 -110
pages/1player_information.py CHANGED
@@ -5,57 +5,29 @@ import matplotlib.pyplot as plt
5
  # Set page configuration
6
  st.set_page_config(page_title="Career Insights", layout="wide")
7
 
8
- # Light-Themed Background with Light Blue Color
9
- page_bg = """
10
- <style>
11
- body {
12
- background-color: #E3F2FD;
13
- }
14
- [data-testid="stAppViewContainer"] {
15
- background-color: #E3F2FD;
16
- }
17
- [data-testid="stSidebar"] {
18
- background-color: #ffffff;
19
- border-right: 1px solid #ddd;
20
- }
21
- h1, h2, h3, h4, h5, h6 {
22
- color: #333333 !important;
23
- }
24
- .stTextInput>div>div>input {
25
- background-color: white;
26
- color: black;
27
- border-radius: 5px;
28
- padding: 10px;
29
- border: 1px solid #ccc;
30
- }
31
- </style>
32
- """
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"],
@@ -63,15 +35,12 @@ if selected_player:
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"],
@@ -79,75 +48,36 @@ if selected_player:
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)
 
5
  # Set page configuration
6
  st.set_page_config(page_title="Career Insights", layout="wide")
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  # Load data
9
+ file_path = "Final.csv"
10
  df = pd.read_csv(file_path)
11
 
12
  # Get unique player names
13
+ player_names = df["Player"].unique()
14
+
15
+ # Search box for filtering player names
16
+ search_query = st.text_input("Search Player Name:")
17
+ filtered_players = [name for name in player_names if search_query.lower() in name.lower()] if search_query else player_names
18
 
19
+ # Player selection dropdown
20
+ selected_player = st.selectbox("Select Player", filtered_players)
21
 
22
+ # Buttons for Batting and Bowling
23
+ show_batting = st.button("Show Batting Stats")
24
+ show_bowling = st.button("Show Bowling Stats")
 
25
 
26
  if selected_player:
27
  player_data = df[df["Player"] == selected_player].iloc[0]
28
+ labels = ["Test", "ODI", "T20", "IPL"]
29
+
30
  if show_batting:
 
 
31
  # Pie Chart - Matches Played Across Formats
32
  matches = [
33
  player_data["Matches_Test"],
 
35
  player_data["Matches_T20"],
36
  player_data["Matches_IPL"]
37
  ]
 
 
38
  fig, ax = plt.subplots()
39
+ ax.pie(matches, labels=labels, autopct="%1.1f%%", startangle=90)
40
+ ax.set_title(f"Matches Played by {selected_player}")
 
41
  st.pyplot(fig)
42
 
43
+ # Bar Chart - Runs Scored
44
  batting_runs = [
45
  player_data["batting_Runs_Test"],
46
  player_data["batting_Runs_ODI"],
 
48
  player_data["batting_Runs_IPL"]
49
  ]
50
  fig, ax = plt.subplots()
51
+ ax.bar(labels, batting_runs, color=["gold", "green", "blue", "red"])
52
+ ax.set_ylabel("Runs Scored")
53
+ ax.set_title(f"Runs Scored by {selected_player}")
54
  st.pyplot(fig)
55
+
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  if show_bowling:
57
+ # Calculate Overs Bowled
 
 
58
  overs_bowled = [
59
+ player_data["bowling_Test_Balls"] // 6,
60
+ player_data["bowling_ODI_Balls"] // 6,
61
+ player_data["bowling_T20_Balls"] // 6,
62
+ player_data["bowling_IPL_Balls"] // 6
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  ]
64
+
65
+ # Bar Chart - Overs Bowled
66
  fig, ax = plt.subplots()
67
+ ax.bar(labels, overs_bowled, color=["purple", "orange", "cyan", "brown"])
68
+ ax.set_ylabel("Overs Bowled")
69
+ ax.set_title(f"Overs Bowled by {selected_player}")
70
  st.pyplot(fig)
71
+
72
+ # Line Chart - Wickets Taken
73
+ wickets_taken = [
74
+ player_data["bowling_Wickets_Test"],
75
+ player_data["bowling_Wickets_ODI"],
76
+ player_data["bowling_Wickets_T20"],
77
+ player_data["bowling_Wickets_IPL"]
 
 
 
 
 
 
 
 
 
 
 
 
 
78
  ]
79
  fig, ax = plt.subplots()
80
+ ax.plot(labels, wickets_taken, marker='o', linestyle='-', color='red')
81
+ ax.set_ylabel("Wickets Taken")
82
+ ax.set_title(f"Wickets Taken by {selected_player}")
83
  st.pyplot(fig)