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

Update pages/1player_information.py

Browse files
Files changed (1) hide show
  1. 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
- # Autocomplete player selection
47
- player_prefix = st.text_input("Enter at least first three letters of Player Name:")
48
 
49
- if player_prefix and len(player_prefix) >= 3:
50
- filtered_players = [name for name in player_names if name.lower().startswith(player_prefix.lower())]
51
-
52
- if filtered_players:
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
- # Pie Chart - Matches Played Across Formats
64
- matches = [
65
- player_data["Matches_Test"],
66
- player_data["Matches_ODI"],
67
- player_data["Matches_T20"],
68
- player_data["Matches_IPL"]
69
- ]
70
- labels = ["Test", "ODI", "T20", "IPL"]
71
-
72
- fig, ax = plt.subplots()
73
- ax.pie(matches, labels=labels, autopct="%1.1f%%", startangle=90,
74
- colors=["#87CEEB", "#90EE90", "#FFA07A", "#9370DB"])
75
- ax.set_title(f"Matches Played by {selected_player}", fontsize=14)
76
- st.pyplot(fig)
77
-
78
- # Bar Chart - Runs Scored in Different Formats
79
- batting_runs = [
80
- player_data["batting_Runs_Test"],
81
- player_data["batting_Runs_ODI"],
82
- player_data["batting_Runs_T20"],
83
- player_data["batting_Runs_IPL"]
84
- ]
85
- fig, ax = plt.subplots()
86
- ax.bar(labels, batting_runs, color=["#FFD700", "#008000", "#1E90FF", "#FF4500"])
87
- ax.set_ylabel("Runs Scored", fontsize=12)
88
- ax.set_title(f"Runs Scored by {selected_player}", fontsize=14)
89
- st.pyplot(fig)
90
-
91
- # Line Chart - Batting Average Over Formats
92
- batting_average = [
93
- player_data["batting_Runs_Test"] / max(1, player_data["batting_Innings_Test"]),
94
- player_data["batting_Runs_ODI"] / max(1, player_data["batting_Innings_ODI"]),
95
- player_data["batting_Runs_T20"] / max(1, player_data["batting_Innings_T20"]),
96
- player_data["batting_Runs_IPL"] / max(1, player_data["batting_Innings_IPL"])
97
- ]
98
- fig, ax = plt.subplots()
99
- ax.plot(labels, batting_average, marker='o', linestyle='-', color='#FFA500', linewidth=2)
100
- ax.set_ylabel("Batting Average", fontsize=12)
101
- ax.set_title(f"Batting Average of {selected_player}", fontsize=14)
102
- st.pyplot(fig)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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)