Cric_Metrics / pages /1player_information.py
Sathwikchowdary's picture
Update pages/1player_information.py
fae6d46 verified
raw
history blame
2.88 kB
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
file_path = "Final.csv"
df = pd.read_csv(file_path)
# 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:
# Pie Chart - Matches Played Across Formats
matches = [
player_data["Matches_Test"],
player_data["Matches_ODI"],
player_data["Matches_T20"],
player_data["Matches_IPL"]
]
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)
# Bar Chart - Runs Scored
batting_runs = [
player_data["batting_Runs_Test"],
player_data["batting_Runs_ODI"],
player_data["batting_Runs_T20"],
player_data["batting_Runs_IPL"]
]
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:
# Calculate Overs Bowled
overs_bowled = [
player_data["bowling_Test_Balls"] // 6,
player_data["bowling_ODI_Balls"] // 6,
player_data["bowling_T20_Balls"] // 6,
player_data["bowling_IPL_Balls"] // 6
]
# Bar Chart - Overs Bowled
fig, ax = plt.subplots()
ax.bar(labels, overs_bowled, color=["purple", "orange", "cyan", "brown"])
ax.set_ylabel("Overs Bowled")
ax.set_title(f"Overs Bowled by {selected_player}")
st.pyplot(fig)
# Line Chart - Wickets Taken
wickets_taken = [
player_data["bowling_Wickets_Test"],
player_data["bowling_Wickets_ODI"],
player_data["bowling_Wickets_T20"],
player_data["bowling_Wickets_IPL"]
]
fig, ax = plt.subplots()
ax.plot(labels, wickets_taken, marker='o', linestyle='-', color='red')
ax.set_ylabel("Wickets Taken")
ax.set_title(f"Wickets Taken by {selected_player}")
st.pyplot(fig)