Adityaganesh commited on
Commit
220b608
Β·
verified Β·
1 Parent(s): efb5928

Rename pages/Player Stats to pages/Player Stats.py

Browse files
Files changed (2) hide show
  1. pages/Player Stats +0 -0
  2. pages/Player Stats.py +77 -0
pages/Player Stats DELETED
File without changes
pages/Player Stats.py ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import plotly.express as px
4
+ import plotly.graph_objects as go
5
+
6
+ # Streamlit App Title
7
+ st.title("🏏 Cricket Data Analysis πŸ“Š")
8
+
9
+ # Load CSV Files using Streamlit Cache
10
+ @st.cache_data
11
+ def load_batting_data():
12
+ return pd.read_csv("Batting_10_Teams_Final.csv")
13
+
14
+ @st.cache_data
15
+ def load_bowling_data():
16
+ return pd.read_csv("Bowling_10_Teams_Final.csv")
17
+
18
+ # Load Data
19
+ try:
20
+ batting_df = load_batting_data()
21
+ bowling_df = load_bowling_data()
22
+ except FileNotFoundError as e:
23
+ st.error(f"❌ File not found: {e}")
24
+ st.stop()
25
+
26
+ # Main Page Filters
27
+ selected_country = st.selectbox("Select Country", sorted(batting_df["Country"].unique()))
28
+ option = st.selectbox("Choose the Player", sorted(batting_df[batting_df["Country"] == selected_country]["player_name"].unique()))
29
+ selected_format = st.selectbox("Select Format", ["All"] + list(batting_df["Format"].unique()) + ["IPL"])
30
+
31
+ st.write("You selected:", option)
32
+
33
+ # Filter Data
34
+ filtered_batting_df = batting_df[(batting_df["player_name"] == option) & (batting_df["Country"] == selected_country)]
35
+ filtered_bowling_df = bowling_df[(bowling_df["player_name"] == option) & (bowling_df["Country"] == selected_country)]
36
+
37
+ if selected_format != "All":
38
+ filtered_batting_df = filtered_batting_df[filtered_batting_df["Format"] == selected_format]
39
+ filtered_bowling_df = filtered_bowling_df[filtered_bowling_df["Format"] == selected_format]
40
+
41
+ # Convert NaN values to zero
42
+ filtered_batting_df = filtered_batting_df.fillna(0)
43
+ filtered_bowling_df = filtered_bowling_df.fillna(0)
44
+
45
+ # Drop Unnecessary Columns
46
+ display_batting_df = filtered_batting_df.drop(columns=["player_name", "Country"]).reset_index(drop=True)
47
+ display_bowling_df = filtered_bowling_df.drop(columns=["player_name", "Country"]).reset_index(drop=True)
48
+
49
+ # Display Raw Data
50
+ st.subheader(f"🏏 Batting Stats - {option}")
51
+ st.dataframe(display_batting_df)
52
+
53
+ st.subheader(f"🎯 Bowling Stats - {option}")
54
+ st.dataframe(display_bowling_df)
55
+
56
+ # Batting Efficiency
57
+ filtered_batting_df["Balls per Four"] = filtered_batting_df["Balls"] / filtered_batting_df["Fours"]
58
+ filtered_batting_df["Balls per Six"] = filtered_batting_df["Balls"] / filtered_batting_df["Sixes"]
59
+
60
+ # Bowling Efficiency
61
+ filtered_bowling_df["Balls per Wicket"] = filtered_bowling_df["Balls"] / filtered_bowling_df["Wickets"]
62
+
63
+ # Batting Visualizations
64
+ st.subheader(f"🏏 Boundary Efficiency - {option}")
65
+ fig = px.bar(filtered_batting_df, x="Format", y="Balls per Four", title="Balls Taken per Four Across Formats", color="Format")
66
+ st.plotly_chart(fig)
67
+
68
+ fig = px.bar(filtered_batting_df, x="Format", y="Balls per Six", title="Balls Taken per Six Across Formats", color="Format")
69
+ st.plotly_chart(fig)
70
+
71
+ # Bowling Visualizations
72
+ st.subheader(f"🎯 Bowling Efficiency - {option}")
73
+ fig = px.bar(filtered_bowling_df, x="Format", y="Eco", title="Bowling Economy Across Formats", color="Format")
74
+ st.plotly_chart(fig)
75
+
76
+ fig = px.bar(filtered_bowling_df, x="Format", y="Balls per Wicket", title="Balls Taken per Wicket Across Formats", color="Format")
77
+ st.plotly_chart(fig)