zoya23 commited on
Commit
aa2501e
Β·
verified Β·
1 Parent(s): ee1bc32

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +94 -0
app.py CHANGED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import seaborn as sns
4
+ import matplotlib.pyplot as plt
5
+ import plotly.express as px
6
+
7
+ # Load the dataset
8
+ df = pd.read_csv("cric_final.csv")
9
+
10
+ st.title("🏏 Player Performance Dashboard")
11
+
12
+ # βœ… Dropdown to Select Player
13
+ selected_player = st.selectbox("Select a Player", df["Player"].unique())
14
+
15
+ # Get Player Data
16
+ player_data = df[df["Player"] == selected_player]
17
+
18
+ if not player_data.empty:
19
+ # Replace None/NaN with "-" only in batting and bowling columns
20
+ batting_cols = [col for col in df.columns if "batting" in col.lower()]
21
+ bowling_cols = [col for col in df.columns if "bowling" in col.lower()]
22
+
23
+ player_data[batting_cols] = player_data[batting_cols].fillna("-")
24
+ player_data[bowling_cols] = player_data[bowling_cols].fillna("-")
25
+
26
+ # βœ… Only 2 Tabs now: Batting and Bowling
27
+ tab1, tab2 = st.tabs(["πŸ“ˆ Batting Performance", "🎯 Bowling Performance"])
28
+
29
+ with tab1:
30
+ st.write("### πŸ“Š Batting Performance")
31
+
32
+ # Bar Chart for Batting Runs
33
+ fig, ax = plt.subplots(figsize=(7, 5))
34
+ sns.barplot(
35
+ x=["Test", "ODI", "T20", "IPL"],
36
+ y=player_data.iloc[0][["batting_Runs_Test", "batting_Runs_ODI", "batting_Runs_T20", "batting_Runs_IPL"]],
37
+ palette="magma",
38
+ ax=ax
39
+ )
40
+ ax.set_ylabel("Total Runs", fontsize=14)
41
+ ax.set_title(f"Batting Performance of {selected_player}", fontsize=16)
42
+ ax.grid(True, axis='y', linestyle='--', alpha=0.7)
43
+ st.pyplot(fig)
44
+
45
+ # Half-Centuries (50s) vs Centuries (100s)
46
+ st.write("### Half-Centuries (50s) vs Centuries (100s)")
47
+ fig, ax = plt.subplots(figsize=(7, 5))
48
+ x_labels = ["Test", "ODI", "T20", "IPL"]
49
+ x = range(len(x_labels))
50
+ fifties = player_data.iloc[0][["batting_50s_Test", "batting_50s_ODI", "batting_50s_T20", "batting_50s_IPL"]]
51
+ hundreds = player_data.iloc[0][["batting_100s_Test", "batting_100s_ODI", "batting_100s_T20", "batting_100s_IPL"]]
52
+
53
+ width = 0.4
54
+ ax.bar([i - width/2 for i in x], fifties, width=width, label="50s", color="skyblue")
55
+ ax.bar([i + width/2 for i in x], hundreds, width=width, label="100s", color="orange")
56
+
57
+ ax.set_xticks(x)
58
+ ax.set_xticklabels(x_labels)
59
+ ax.set_ylabel("Count", fontsize=14)
60
+ ax.set_title(f"50s vs 100s of {selected_player}", fontsize=16)
61
+ ax.legend()
62
+ ax.grid(axis="y", linestyle="--", alpha=0.7)
63
+ st.pyplot(fig)
64
+
65
+ # Pie Chart for Batting Runs Distribution
66
+ st.write("### Batting Runs Distribution")
67
+ runs = player_data.iloc[0][["batting_Runs_Test", "batting_Runs_ODI", "batting_Runs_T20", "batting_Runs_IPL"]]
68
+ fig_pie = px.pie(values=runs, names=x_labels, title="Batting Runs Distribution")
69
+ st.plotly_chart(fig_pie)
70
+
71
+ with tab2:
72
+ st.write("### 🎯 Bowling Performance")
73
+
74
+ # Bar Chart for Bowling Wickets
75
+ fig, ax = plt.subplots(figsize=(7, 5))
76
+ sns.barplot(
77
+ x=["Test", "ODI", "T20", "IPL"],
78
+ y=player_data.iloc[0][["bowling_Test_Wickets", "bowling_ODI_Wickets", "bowling_T20_Wickets", "bowling_IPL_Wickets"]],
79
+ palette="coolwarm",
80
+ ax=ax
81
+ )
82
+ ax.set_ylabel("Total Wickets", fontsize=14)
83
+ ax.set_title(f"Bowling Performance of {selected_player}", fontsize=16)
84
+ ax.grid(True, axis='y', linestyle='--', alpha=0.7)
85
+ st.pyplot(fig)
86
+
87
+ # Pie Chart for Bowling Wickets Distribution
88
+ st.write("### Bowling Wickets Distribution")
89
+ wickets = player_data.iloc[0][["bowling_Test_Wickets", "bowling_ODI_Wickets", "bowling_T20_Wickets", "bowling_IPL_Wickets"]]
90
+ fig_pie_bowl = px.pie(values=wickets, names=x_labels, title="Bowling Wickets Distribution")
91
+ st.plotly_chart(fig_pie_bowl)
92
+
93
+ else:
94
+ st.warning("⚠️ Player not found in the dataset.")