Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import pandas as pd | |
| import plotly.express as px | |
| import plotly.graph_objects as go | |
| # Streamlit App Title | |
| st.title("π Cricket Data Analysis π") | |
| # Load CSV Files using Streamlit Cache | |
| def load_batting_data(): | |
| return pd.read_csv("Batting_10_Teams_Final.csv") | |
| def load_bowling_data(): | |
| return pd.read_csv("Bowling_10_Teams_Final.csv") | |
| # Load Data | |
| try: | |
| batting_df = load_batting_data() | |
| bowling_df = load_bowling_data() | |
| except FileNotFoundError as e: | |
| st.error(f"β File not found: {e}") | |
| st.stop() | |
| # Main Page Filters | |
| selected_country = st.selectbox("Select Country", sorted(batting_df["Country"].unique())) | |
| option = st.selectbox("Choose the Player", sorted(batting_df[batting_df["Country"] == selected_country]["player_name"].unique())) | |
| selected_format = st.selectbox("Select Format", ["All"] + list(batting_df["Format"].unique()) + ["IPL"]) | |
| st.write("You selected:", option) | |
| # Filter Data | |
| filtered_batting_df = batting_df[(batting_df["player_name"] == option) & (batting_df["Country"] == selected_country)] | |
| filtered_bowling_df = bowling_df[(bowling_df["player_name"] == option) & (bowling_df["Country"] == selected_country)] | |
| if selected_format != "All": | |
| filtered_batting_df = filtered_batting_df[filtered_batting_df["Format"] == selected_format] | |
| filtered_bowling_df = filtered_bowling_df[filtered_bowling_df["Format"] == selected_format] | |
| # Convert NaN values to zero | |
| filtered_batting_df = filtered_batting_df.fillna(0) | |
| filtered_bowling_df = filtered_bowling_df.fillna(0) | |
| # Drop Unnecessary Columns | |
| display_batting_df = filtered_batting_df.drop(columns=["player_name", "Country"]).reset_index(drop=True) | |
| display_bowling_df = filtered_bowling_df.drop(columns=["player_name", "Country"]).reset_index(drop=True) | |
| # Display Raw Data | |
| st.subheader(f"π Batting Stats - {option}") | |
| st.dataframe(display_batting_df) | |
| st.subheader(f"π― Bowling Stats - {option}") | |
| st.dataframe(display_bowling_df) | |
| # Batting Efficiency | |
| filtered_batting_df["Balls per Four"] = filtered_batting_df["Balls"] / filtered_batting_df["Fours"] | |
| filtered_batting_df["Balls per Six"] = filtered_batting_df["Balls"] / filtered_batting_df["Sixes"] | |
| # Bowling Efficiency | |
| filtered_bowling_df["Balls per Wicket"] = filtered_bowling_df["Balls"] / filtered_bowling_df["Wickets"] | |
| # Batting Visualizations | |
| st.subheader(f"π Boundary Efficiency - {option}") | |
| fig = px.bar(filtered_batting_df, x="Format", y="Balls per Four", title="Balls Taken per Four Across Formats", color="Format") | |
| st.plotly_chart(fig) | |
| fig = px.bar(filtered_batting_df, x="Format", y="Balls per Six", title="Balls Taken per Six Across Formats", color="Format") | |
| st.plotly_chart(fig) | |
| # Bowling Visualizations | |
| st.subheader(f"π― Bowling Efficiency - {option}") | |
| fig = px.bar(filtered_bowling_df, x="Format", y="Eco", title="Bowling Economy Across Formats", color="Format") | |
| st.plotly_chart(fig) | |
| fig = px.bar(filtered_bowling_df, x="Format", y="Balls per Wicket", title="Balls Taken per Wicket Across Formats", color="Format") | |
| st.plotly_chart(fig) |