Spaces:
Sleeping
Sleeping
File size: 6,620 Bytes
fcb92fa 32331b8 d7d91e9 30fe6c5 fcb92fa 432d880 fcb92fa 4b8ab3d fae6d46 fcb92fa fae6d46 fcb92fa fae6d46 e8a947e 4b8ab3d fae6d46 e148a04 1d44339 e148a04 e405c05 f272351 b4b1ff8 943bd1e b4b1ff8 943bd1e e405c05 b4b1ff8 e405c05 f272351 b4b1ff8 943bd1e b4b1ff8 943bd1e e405c05 b4b1ff8 e405c05 e148a04 |
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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
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"]
# **Batting Stats Section**
if show_batting:
st.subheader(f"Batting Statistics - {selected_player}")
col1, col2 = st.columns(2)
with col1:
# Pie Chart - Matches Played Across Formats
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)
col3, col4 = st.columns(2)
with col3:
# Bar Chart - 100s and 50s
hundreds = [
player_data.get("batting_100s_Test", 0),
player_data.get("batting_100s_ODI", 0),
player_data.get("batting_100s_T20", 0),
player_data.get("batting_100s_IPL", 0)
]
fifties = [
player_data.get("batting_50s_Test", 0),
player_data.get("batting_50s_ODI", 0),
player_data.get("batting_50s_T20", 0),
player_data.get("batting_50s_IPL", 0)
]
fig, ax = plt.subplots()
ax.bar(labels, hundreds, label="100s", color="gold")
ax.bar(labels, fifties, label="50s", color="blue", bottom=hundreds)
ax.set_ylabel("Count")
ax.set_title(f"Centuries & Fifties by {selected_player}")
ax.legend()
st.pyplot(fig)
with col4:
# Line Chart - Strike Rate & Average
strike_rate = [
player_data.get("batting_SR_Test", 0),
player_data.get("batting_SR_ODI", 0),
player_data.get("batting_SR_T20", 0),
player_data.get("batting_SR_IPL", 0)
]
batting_avg = [
player_data.get("batting_Average_Test", 0),
player_data.get("batting_Average_ODI", 0),
player_data.get("batting_Average_T20", 0),
player_data.get("batting_Average_IPL", 0)
]
fig, ax = plt.subplots()
ax.plot(labels, strike_rate, marker='o', linestyle='-', color='red', label="Strike Rate")
ax.plot(labels, batting_avg, marker='s', linestyle='--', color='green', label="Batting Average")
ax.set_ylabel("Value")
ax.set_title(f"Strike Rate & Batting Average of {selected_player}")
ax.legend()
st.pyplot(fig)
# **Bowling Stats Section**
if show_bowling:
st.subheader(f"Bowling Statistics - {selected_player}")
col1, col2 = st.columns(2)
with col1:
# Pie Chart - Wickets Taken Across Formats
wickets = [
player_data.get("Wickets_Test", 0),
player_data.get("Wickets_ODI", 0),
player_data.get("Wickets_T20", 0),
player_data.get("Wickets_IPL", 0)
]
fig, ax = plt.subplots(figsize=(5, 3))
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 - Economy Rate
economy_rate = [
player_data.get("Economy_Test", 0),
player_data.get("Economy_ODI", 0),
player_data.get("Economy_T20", 0),
player_data.get("Economy_IPL", 0)
]
fig, ax = plt.subplots(figsize=(5, 3))
ax.bar(labels, economy_rate, color=["gold", "green", "blue", "red"])
ax.set_ylabel("Economy Rate")
ax.set_title(f"Economy Rate of {selected_player}")
st.pyplot(fig)
col3, col4 = st.columns(2)
with col3:
# Bar Chart - Balls Bowled
balls_bowled = [
player_data.get("bowling_Balls_Test", 0),
player_data.get("bowling_Balls_ODI", 0),
player_data.get("bowling_Balls_T20", 0),
player_data.get("bowling_Balls_IPL", 0)
]
fig, ax = plt.subplots(figsize=(5, 3))
ax.bar(labels, balls_bowled, color=["red", "green", "blue", "purple"])
ax.set_ylabel("Balls Bowled")
ax.set_title(f"Balls Bowled by {selected_player}")
st.pyplot(fig)
with col4:
# 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)
|