Sathwikchowdary commited on
Commit
4b8ab3d
·
verified ·
1 Parent(s): 6e53772

Update pages/1player_information.py

Browse files
Files changed (1) hide show
  1. pages/1player_information.py +55 -47
pages/1player_information.py CHANGED
@@ -40,55 +40,63 @@ st.title("🏏Career Insights")
40
  file_path = "Final.csv" # Ensure this file exists in your working directory
41
  df = pd.read_csv(file_path)
42
 
43
- # Enter Player Name
44
- player_input = st.text_input("Enter Player Name:")
45
 
46
- if player_input:
47
- selected_player = player_input.strip()
48
-
49
- if selected_player in df["Player"].values:
50
- player_data = df[df["Player"] == selected_player].iloc[0]
51
 
52
- # Pie Chart - Matches Played Across Formats
53
- matches = [
54
- player_data["Matches_Test"],
55
- player_data["Matches_ODI"],
56
- player_data["Matches_T20"],
57
- player_data["Matches_IPL"]
58
- ]
59
- labels = ["Test", "ODI", "T20", "IPL"]
60
-
61
- fig, ax = plt.subplots()
62
- ax.pie(matches, labels=labels, autopct="%1.1f%%", startangle=90,
63
- colors=["#87CEEB", "#90EE90", "#FFA07A", "#9370DB"])
64
- ax.set_title(f"Matches Played by {selected_player}", fontsize=14)
65
- st.pyplot(fig)
66
 
67
- # Bar Chart - Runs Scored in Different Formats
68
- batting_runs = [
69
- player_data["batting_Runs_Test"],
70
- player_data["batting_Runs_ODI"],
71
- player_data["batting_Runs_T20"],
72
- player_data["batting_Runs_IPL"]
73
- ]
74
- fig, ax = plt.subplots()
75
- ax.bar(labels, batting_runs, color=["#FFD700", "#008000", "#1E90FF", "#FF4500"])
76
- ax.set_ylabel("Runs Scored", fontsize=12)
77
- ax.set_title(f"Runs Scored by {selected_player}", fontsize=14)
78
- st.pyplot(fig)
79
 
80
- # Line Chart - Batting Average Over Formats
81
- batting_average = [
82
- player_data["batting_Runs_Test"] / max(1, player_data["batting_Innings_Test"]),
83
- player_data["batting_Runs_ODI"] / max(1, player_data["batting_Innings_ODI"]),
84
- player_data["batting_Runs_T20"] / max(1, player_data["batting_Innings_T20"]),
85
- player_data["batting_Runs_IPL"] / max(1, player_data["batting_Innings_IPL"])
86
- ]
87
- fig, ax = plt.subplots()
88
- ax.plot(labels, batting_average, marker='o', linestyle='-', color='#FFA500', linewidth=2)
89
- ax.set_ylabel("Batting Average", fontsize=12)
90
- ax.set_title(f"Batting Average of {selected_player}", fontsize=14)
91
- st.pyplot(fig)
92
 
93
- else:
94
- st.error("🚨 Player not found! Please enter a valid player name.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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)