File size: 3,698 Bytes
fcb92fa
 
 
 
32331b8
d7d91e9
30fe6c5
fcb92fa
5611ccc
fcb92fa
4b8ab3d
fae6d46
 
 
 
 
fcb92fa
2013f2d
4437d7f
 
fae6d46
4437d7f
fcb92fa
fae6d46
 
 
e8a947e
4b8ab3d
 
fae6d46
 
1d44339
03b9d6c
4437d7f
03b9d6c
e405c05
03b9d6c
f272351
 
 
 
 
 
 
 
 
 
5492c3f
f272351
 
 
 
 
 
 
 
 
 
 
 
 
5492c3f
e148a04
03b9d6c
e148a04
03b9d6c
e148a04
f415382
 
03b9d6c
f415382
 
 
e148a04
03b9d6c
f415382
 
e148a04
 
 
f415382
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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("Teams.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

if len(filtered_players) == 0:
    st.warning("Player not found. Please try a different name.")

# Player selection dropdown
selected_player = st.selectbox("Select Player", filtered_players) if filtered_players else None

# 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 - Bowling Averages
            bowling_avg = [
                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_Avg", 0)) else float(player_data.get("bowling_ODI_Avg", 0)),
                0 if pd.isna(player_data.get("bowling_T20_Avg", 0)) else float(player_data.get("bowling_T20_Avg", 0)),
                0 if pd.isna(player_data.get("bowling_IPL_Avg", 0)) else float(player_data.get("bowling_IPL_Avg", 0))
            ]
            fig, ax = plt.subplots()
            ax.pie(bowling_avg, labels=labels, autopct="%1.1f%%", startangle=90)
            ax.set_title(f"Bowling Averages of {selected_player}")
            st.pyplot(fig)

        with col2:
            # Bar Chart - Bowling Innings
            bowling_innings = [
                player_data.get("bowling_Test_Innings", 0),
                player_data.get("bowling_ODI_Innings", 0),
                player_data.get("bowling_T20_Innings", 0),
                player_data.get("bowling_IPL_Innings", 0)
            ]
            fig, ax = plt.subplots()
            ax.bar(labels, bowling_innings, color=["blue", "green", "purple", "orange"])
            ax.set_ylabel("Innings Bowled")
            ax.set_title(f"Bowling Innings of {selected_player}")
            st.pyplot(fig)