Spaces:
Sleeping
Sleeping
import streamlit as st | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
import seaborn as sns | |
# Load data | |
file_path = "South_Africa_Final2.csv" | |
df = pd.read_csv(file_path) | |
st.title("South Africa Cricket Players - Career Visualizations") | |
# Enter Player Name | |
player_input = st.text_input("Enter Player Name:") | |
if player_input: | |
selected_player = player_input.strip() | |
if selected_player in df["Player"].values: | |
player_data = df[df["Player"] == selected_player].iloc[0] | |
# Pie Chart - Matches Played Across Formats | |
matches = [ | |
player_data["Matches_Test"], | |
player_data["Matches_ODI"], | |
player_data["Matches_T20"], | |
player_data["Matches_IPL"] | |
] | |
labels = ["Test", "ODI", "T20", "IPL"] | |
fig, ax = plt.subplots() | |
ax.pie(matches, labels=labels, autopct="%1.1f%%", startangle=90, colors=["blue", "green", "red", "purple"]) | |
ax.set_title(f"Matches Played by {selected_player}") | |
st.pyplot(fig) | |
# Bar Chart - Runs Scored in Different Formats | |
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=["blue", "green", "red", "purple"]) | |
ax.set_ylabel("Runs Scored") | |
ax.set_title(f"Runs Scored by {selected_player}") | |
st.pyplot(fig) | |
# Scatter Plot - Matches vs Runs | |
fig, ax = plt.subplots() | |
sns.scatterplot(x=df["Matches_ODI"], y=df["batting_Runs_ODI"], ax=ax) | |
ax.set_xlabel("Matches Played") | |
ax.set_ylabel("Runs Scored") | |
ax.set_title("Matches vs Runs in ODIs (All Players)") | |
st.pyplot(fig) | |
else: | |
st.error("Player not found! Please enter a valid player name.") | |
st.write("Enter a player's name to explore their statistics!") | |