import streamlit as st import pandas as pd import matplotlib.pyplot as plt # Set page configuration st.set_page_config(page_title="Career Insights", layout="wide") # Load data df = pd.read_csv("Team_Info.csv") # Get unique player names player_names = df["Player"].unique() # Search box for filtering player names search_query = st.text_input("Search Player Name:") filtered_players = [name for name in player_names if search_query.lower() in name.lower()] if search_query else player_names # Player selection dropdown selected_player = st.selectbox("Select Player", filtered_players) # Buttons for Batting and Bowling show_batting = st.button("Show Batting Stats") show_bowling = st.button("Show Bowling Stats") if selected_player: player_data = df[df["Player"] == selected_player].iloc[0] labels = ["Test", "ODI", "T20", "IPL"] if show_batting: st.subheader(f"Batting Stats for {selected_player}") col1, col2 = st.columns(2) with col1: # Pie Chart - Matches Played matches = [ player_data.get("Matches_Test", 0), player_data.get("Matches_ODI", 0), player_data.get("Matches_T20", 0), player_data.get("Matches_IPL", 0) ] fig, ax = plt.subplots() ax.pie(matches, labels=labels, autopct="%1.1f%%", startangle=90) ax.set_title(f"Matches Played by {selected_player}") st.pyplot(fig) with col2: # Bar Chart - Runs Scored batting_runs = [ player_data.get("batting_Runs_Test", 0), player_data.get("batting_Runs_ODI", 0), player_data.get("batting_Runs_T20", 0), player_data.get("batting_Runs_IPL", 0) ] fig, ax = plt.subplots() ax.bar(labels, batting_runs, color=["gold", "green", "blue", "red"]) ax.set_ylabel("Runs Scored") ax.set_title(f"Runs Scored by {selected_player}") st.pyplot(fig) if show_bowling: st.subheader(f"Bowling Stats for {selected_player}") col1, col2 = st.columns(2) with col1: # Pie Chart - Wickets Taken wickets = [ 0 if pd.isna(player_data.get("bowling_Test_Avg", 0)) else float(player_data.get("bowling_Test_Avg", 0)), 0 if pd.isna(player_data.get("bowling_ODI_Wickets", 0)) else int(player_data.get("bowling_ODI_Wickets", 0)), 0 if pd.isna(player_data.get("bowling_T20_Wickets", 0)) else int(player_data.get("bowling_T20_Wickets", 0)), 0 if pd.isna(player_data.get("bowling_IPL_Wickets", 0)) else int(player_data.get("bowling_IPL_Wickets", 0)) ] fig, ax = plt.subplots() ax.pie(wickets, labels=labels, autopct="%1.1f%%", startangle=90) ax.set_title(f"Wickets Taken by {selected_player}") st.pyplot(fig) with col2: # Bar Chart - Maidens Bowled maidens_bowled = [ player_data.get("bowling_Maidens_Test", 0), player_data.get("bowling_Maidens_ODI", 0), player_data.get("bowling_Maidens_T20", 0), player_data.get("bowling_Maidens_IPL", 0) ] fig, ax = plt.subplots(figsize=(5, 3)) ax.bar(labels, maidens_bowled, color=["cyan", "magenta", "yellow", "black"]) ax.set_ylabel("Maidens Bowled") ax.set_title(f"Maidens Bowled by {selected_player}") st.pyplot(fig)