Spaces:
Sleeping
Sleeping
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: | |
col1, col2 = st.columns(2) | |
with col1: | |
# Bar Chart - 100s and 50s | |
hundreds = [ | |
player_data.get("100s_Test", 0), | |
player_data.get("100s_ODI", 0), | |
player_data.get("100s_T20", 0), | |
player_data.get("100s_IPL", 0) | |
] | |
fifties = [ | |
player_data.get("50s_Test", 0), | |
player_data.get("50s_ODI", 0), | |
player_data.get("50s_T20", 0), | |
player_data.get("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 col2: | |
# Line Chart - Strike Rate & Average | |
strike_rate = [ | |
player_data.get("SR_Test", 0), | |
player_data.get("SR_ODI", 0), | |
player_data.get("SR_T20", 0), | |
player_data.get("SR_IPL", 0) | |
] | |
batting_avg = [ | |
player_data.get("Avg_Test", 0), | |
player_data.get("Avg_ODI", 0), | |
player_data.get("Avg_T20", 0), | |
player_data.get("Avg_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) | |
if show_bowling: | |
col1, col2 = st.columns(2) | |
with col1: | |
# Bar Chart - Economy Rate | |
economy_rate = [ | |
player_data.get("Econ_Test", 0), | |
player_data.get("Econ_ODI", 0), | |
player_data.get("Econ_T20", 0), | |
player_data.get("Econ_IPL", 0) | |
] | |
fig, ax = plt.subplots() | |
ax.bar(labels, economy_rate, color=["purple", "orange", "cyan", "brown"]) | |
ax.set_ylabel("Economy Rate") | |
ax.set_title(f"Economy Rate of {selected_player}") | |
st.pyplot(fig) | |
with col2: | |
# Scatter Plot - Bowling Average & Strike Rate | |
bowling_avg = [ | |
player_data.get("Bowl_Avg_Test", 0), | |
player_data.get("Bowl_Avg_ODI", 0), | |
player_data.get("Bowl_Avg_T20", 0), | |
player_data.get("Bowl_Avg_IPL", 0) | |
] | |
bowling_sr = [ | |
player_data.get("Bowl_SR_Test", 0), | |
player_data.get("Bowl_SR_ODI", 0), | |
player_data.get("Bowl_SR_T20", 0), | |
player_data.get("Bowl_SR_IPL", 0) | |
] | |
fig, ax = plt.subplots() | |
ax.scatter(labels, bowling_avg, color='blue', label="Bowling Average") | |
ax.scatter(labels, bowling_sr, color='red', label="Bowling Strike Rate") | |
ax.set_ylabel("Value") | |
ax.set_title(f"Bowling Average & Strike Rate of {selected_player}") | |
ax.legend() | |
st.pyplot(fig) |