File size: 3,067 Bytes
220b608
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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
@st.cache_data
def load_batting_data():
    return pd.read_csv("Batting_10_Teams_Final.csv")

@st.cache_data
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)