Spaces:
Sleeping
Sleeping
File size: 3,385 Bytes
fcb92fa 32331b8 8380a1e 32331b8 fcb92fa 32331b8 fcb92fa 32331b8 fcb92fa e8a947e fcb92fa 32331b8 fcb92fa 32331b8 8380a1e 32331b8 fcb92fa 32331b8 fcb92fa e8a947e 9e50fe1 32331b8 9e50fe1 32331b8 9e50fe1 fcb92fa e8a947e 32331b8 |
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 |
import streamlit as st
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
# Set page configuration
st.set_page_config(page_title="Cricket Legends: Career Insights", layout="wide")
# App Title
st.title("π Cricket Legends: Career Insights & Visualizations")
# Load data
file_path = "Final.csv" # Ensure this file exists in your working directory
df = pd.read_csv(file_path)
# 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=["#87CEEB", "#90EE90", "#FFA07A", "#9370DB"])
ax.set_title(f"Matches Played by {selected_player}", fontsize=14)
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=["#FFD700", "#008000", "#1E90FF", "#FF4500"])
ax.set_ylabel("Runs Scored", fontsize=12)
ax.set_title(f"Runs Scored by {selected_player}", fontsize=14)
st.pyplot(fig)
# Scatter Plot - Matches vs Runs (ODIs)
fig, ax = plt.subplots()
sns.scatterplot(x=df["Matches_ODI"], y=df["batting_Runs_ODI"], ax=ax, color="#4682B4", edgecolor='black')
ax.set_xlabel("Matches Played", fontsize=12)
ax.set_ylabel("Runs Scored", fontsize=12)
ax.set_title("Matches vs Runs in ODIs (All Players)", fontsize=14)
st.pyplot(fig)
# Line Chart - Batting Average Over Formats
batting_average = [
player_data["batting_Runs_Test"] / max(1, player_data["batting_Innings_Test"]),
player_data["batting_Runs_ODI"] / max(1, player_data["batting_Innings_ODI"]),
player_data["batting_Runs_T20"] / max(1, player_data["batting_Innings_T20"]),
player_data["batting_Runs_IPL"] / max(1, player_data["batting_Innings_IPL"])
]
fig, ax = plt.subplots()
ax.plot(labels, batting_average, marker='o', linestyle='-', color='#FFA500', linewidth=2)
ax.set_ylabel("Batting Average", fontsize=12)
ax.set_title(f"Batting Average of {selected_player}", fontsize=14)
st.pyplot(fig)
# Histogram - Distribution of Runs Scored by All Players in ODIs
fig, ax = plt.subplots()
sns.histplot(df["batting_Runs_ODI"], bins=20, kde=True, color='#3CB371', ax=ax)
ax.set_xlabel("Runs Scored", fontsize=12)
ax.set_ylabel("Frequency", fontsize=12)
ax.set_title("Distribution of Runs Scored in ODIs (All Players)", fontsize=14)
st.pyplot(fig)
else:
st.error("π¨ Player not found! Please enter a valid player name.")
|