import streamlit as st import pandas as pd import plotly.express as px import numpy as np # Configure page st.set_page_config( page_title="Cricket Analytics Pro", page_icon="🏏", layout="wide" ) # Custom CSS st.markdown(""" """, unsafe_allow_html=True) @st.cache_data def load_data(): try: df = pd.read_csv("All_Cric_Stats.csv") # Convert numeric columns, handling errors numeric_cols = ['Batting_Runs', 'Batting_Average', 'Batting_SR', 'Bowling_Wickets', 'Bowling_Avg', 'Bowling_SR', 'Bowling_Eco'] for col in numeric_cols: if col in df.columns: df[col] = pd.to_numeric(df[col], errors='coerce') return df except Exception as e: st.error(f"Error loading data: {str(e)}") return pd.DataFrame() df = load_data() # --- Home Page Content --- st.markdown('

🏏 Cricket Analytics Dashboard

', unsafe_allow_html=True) # ====== NEW SECTIONS ====== # About the Dashboard with st.container(): st.markdown('

About This Dashboard

', unsafe_allow_html=True) st.markdown("""

This Cricket Analytics Dashboard transforms raw cricket statistics into actionable insights through:

The dashboard serves cricket analysts, team selectors, fantasy players, and enthusiasts who want deeper understanding beyond traditional statistics.

""", unsafe_allow_html=True) # Goals Section with st.container(): st.markdown('

Our Goals

', unsafe_allow_html=True) col1, col2 = st.columns(2) with col1: st.markdown("""

📊 Analytical Objectives

""", unsafe_allow_html=True) with col2: st.markdown("""

🚀 Technical Objectives

""", unsafe_allow_html=True) # About Author with st.container(): st.markdown('

About the Author

', unsafe_allow_html=True) st.markdown("""
Saikumar Nambaru

Saikumar Nambaru

Data Scientist Traine| Cricket Analyst

A passionate data enthusiast with a deep interest in cricket analytics, Saikumar Nambaru leverages data science techniques to extract meaningful insights from cricket statistics. He is driven to bridge the gap between traditional cricket analysis and modern, data-driven insight Tis work combines technical expertise in data science with deep understanding of cricket dynamics.

"My mission is to bridge the gap between traditional cricket statistics and modern analytics, making advanced insights accessible to everyone from coaches to casual fans."

""", unsafe_allow_html=True) # ====== DATA ANALYSIS SECTIONS ====== if not df.empty: st.markdown('

Data Analysis

', unsafe_allow_html=True) # Format Selection selected_format = st.selectbox( "Select Cricket Format", options=df['Format'].unique(), index=0 ) # Filter data by selected format format_df = df[df['Format'] == selected_format].copy() # Key Metrics st.markdown(f'

Top Performers in {selected_format}

', unsafe_allow_html=True) col1, col2, col3 = st.columns(3) # Batting Metrics with col1: if not format_df.empty: top_batter = format_df.loc[format_df['Batting_Runs'].idxmax()] st.markdown(f"""

Top Batter

{top_batter['Player Name']}

{top_batter['Batting_Runs']:,.0f} runs | Avg: {top_batter['Batting_Average']:.1f} | SR: {top_batter['Batting_SR']:.1f}

""", unsafe_allow_html=True) # Bowling Metrics with col2: if 'Bowling_Wickets' in format_df.columns: bowlers = format_df[format_df['Bowling_Wickets'] > 0] if not bowlers.empty: top_wicket_taker = bowlers.loc[bowlers['Bowling_Wickets'].idxmax()] st.markdown(f"""

Top Wicket Taker

{top_wicket_taker['Player Name']}

{top_wicket_taker['Bowling_Wickets']} wickets | Avg: {top_wicket_taker['Bowling_Avg']:.1f}

""", unsafe_allow_html=True) # Best Bowling Average with col3: if 'Bowling_Avg' in format_df.columns and 'Bowling_Wickets' in format_df.columns: qualified_bowlers = format_df[(format_df['Bowling_Wickets'] >= 5) & (format_df['Bowling_Avg'] > 0)] if not qualified_bowlers.empty: best_bowler = qualified_bowlers.loc[qualified_bowlers['Bowling_Avg'].idxmin()] st.markdown(f"""

Best Bowling Average

{best_bowler['Player Name']}

Avg: {best_bowler['Bowling_Avg']:.1f} | Wkts: {best_bowler['Bowling_Wickets']}

""", unsafe_allow_html=True) # Visualizations st.markdown('

Performance Analysis

', unsafe_allow_html=True) tab1, tab2 = st.tabs(["Batting", "Bowling"]) with tab1: if not format_df.empty: top_batters = format_df.groupby('Player Name').agg({ 'Batting_Runs': 'sum', 'Batting_Average': 'mean', 'Batting_SR': 'mean', 'Team Name': 'first' }).nlargest(10, 'Batting_Runs').reset_index() fig = px.bar(top_batters, x='Batting_Runs', y='Player Name', color='Team Name', title=f'Top 10 Run Scorers in {selected_format}', labels={'Batting_Runs': 'Total Runs'}, hover_data=['Batting_Average', 'Batting_SR']) st.plotly_chart(fig, use_container_width=True) with tab2: if 'Bowling_Wickets' in format_df.columns: top_bowlers = format_df[format_df['Bowling_Wickets'] > 0].groupby('Player Name').agg({ 'Bowling_Wickets': 'sum', 'Bowling_Avg': 'mean', 'Bowling_SR': 'mean', 'Team Name': 'first' }).nlargest(10, 'Bowling_Wickets').reset_index() fig = px.bar(top_bowlers, x='Bowling_Wickets', y='Player Name', color='Team Name', title=f'Top 10 Wicket Takers in {selected_format}', labels={'Bowling_Wickets': 'Total Wickets'}, hover_data=['Bowling_Avg', 'Bowling_SR']) st.plotly_chart(fig, use_container_width=True) # Data Explorer st.markdown('

Data Explorer

', unsafe_allow_html=True) with st.expander("View Raw Data", expanded=False): st.dataframe(format_df, use_container_width=True, height=400) else: st.warning(""" Data loading issue detected. Please verify: 1. The CSV file is named 'All_Cric_Stats.csv' 2. It's in the same folder as this app 3. The file contains valid data """) # Footer st.markdown("---") st.markdown("""

© 2023 Cricket Analytics Pro | Developed by Saikumar Nambaru | Built with Streamlit

""", unsafe_allow_html=True)