Spaces:
Sleeping
Sleeping
File size: 11,590 Bytes
21ab2c7 b150b16 21ab2c7 b150b16 21ab2c7 df65c53 21ab2c7 df65c53 21ab2c7 4fe7c52 21ab2c7 03d5826 21ab2c7 4fe7c52 | 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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | import streamlit as st
import pandas as pd
import plotly.express as px
# Load Data (Replace with your CSV path)
#@st.cache_data
# def load_data():
# return pd.read_csv('All_Teams_updated.csv')
df = pd.read_csv('All_Teams_updated.csv')
# Create a Single Tab
tab1, = st.tabs(["π Player Information"])
# Helper function to safely get values or return 0 if column doesn't exist
def get_value(filtered_data, column_name):
return filtered_data[column_name].values[0] if column_name in filtered_data.columns else 0
# Tab for Player Stats
with tab1:
# Streamlit App Title
st.title("π Player Dashboard")
st.header("View Player Stats")
# Creating columns for side-by-side layout
col1, col2, col3 = st.columns([1.5, 1.5, 1])
with col1:
# Select Team
team_name = st.selectbox("π Select Team:", df['Player_Team'].unique())
with col2:
# Filter Players by Team
team_players = df[df['Player_Team'] == team_name]['Player'].unique()
player_name = st.selectbox("π€ Select Player:", team_players)
with col3:
# Select Player Type (Batsman/Bowler)
player_type = st.radio("π Select Type:", ["Batsman", "Bowler"])
# Filter Data for Selected Player
filtered_data = df[(df['Player'] == player_name) & (df['Player_Team'] == team_name)]
if filtered_data.empty:
st.warning(f"No data found for {player_name} in {team_name}.")
else:
if player_type == "Batsman":
# Extract Batting Data
batsman_data = pd.DataFrame({
'Format': ['IPL', 'Test', 'ODI', 'T20'],
'Matches': [get_value(filtered_data, f'Matches_{fmt}') for fmt in ['IPL', 'Test', 'ODI', 'T20']],
'Innings': [get_value(filtered_data, f'batting_Innings_{fmt}') for fmt in ['IPL', 'Test', 'ODI', 'T20']],
'Balls': [get_value(filtered_data, f'batting_Balls_{fmt}') for fmt in ['IPL', 'Test', 'ODI', 'T20']],
'Runs': [get_value(filtered_data, f'batting_Runs_{fmt}') for fmt in ['IPL', 'Test', 'ODI', 'T20']],
'Average': [get_value(filtered_data, f'batting_Average_{fmt}') for fmt in ['IPL', 'Test', 'ODI', 'T20']],
'Strike Rate': [get_value(filtered_data, f'batting_SR_{fmt}') for fmt in ['IPL', 'Test', 'ODI', 'T20']],
"Duck's" : [get_value(filtered_data, f'batting_Ducks_{fmt}') for fmt in ['IPL', 'Test', 'ODI', 'T20']],
"NOT OUT" : [get_value(filtered_data, f'batting_Not Out_{fmt}') for fmt in ['IPL', 'Test', 'ODI', 'T20']],
"4's" : [get_value(filtered_data, f'batting_Fours_{fmt}') for fmt in ['IPL', 'Test', 'ODI', 'T20']],
"6's" : [get_value(filtered_data, f'batting_Sixes_{fmt}') for fmt in ['IPL', 'Test', 'ODI', 'T20']],
'50s': [get_value(filtered_data, f'batting_50s_{fmt}') for fmt in ['IPL', 'Test', 'ODI', 'T20']],
'100s': [get_value(filtered_data, f'batting_100s_{fmt}') for fmt in ['IPL', 'Test', 'ODI', 'T20']],
'200s': [get_value(filtered_data, f'batting_200s_{fmt}') if fmt != 'T20' else 0 for fmt in ['IPL', 'Test', 'ODI', 'T20']],
'300s': [get_value(filtered_data, f'batting_300s_Test') if fmt == 'Test' else 0 for fmt in ['IPL', 'Test', 'ODI', 'T20']]
})
st.subheader(f"Batting Stats for {player_name} ({team_name})")
st.dataframe(batsman_data)
# Extract Data Matches vs innings
formats = ['Test', 'ODI', 'T20', 'IPL']
matches = [get_value(filtered_data, f'Matches_{fmt}') for fmt in formats]
innings = [get_value(filtered_data, f'batting_Innings_{fmt}') for fmt in formats]
# Create DataFrame
comparison_data = pd.DataFrame({
'Format': formats,
'Matches': matches,
'Innings': innings
})
# Melt Data
comparison_data_melted = comparison_data.melt(id_vars='Format', var_name='Category', value_name='Count')
# Plot Grouped Bar Chart
fig_comparison = px.bar(
comparison_data_melted,
x='Format',
y='Count',
color='Category',
barmode='group',
title=f'{player_name} - Matches vs Innings Across Formats',
labels={'Count': 'Number of Matches/Innings', 'Format': 'Match Format'}
)
st.plotly_chart(fig_comparison)
## Balls Vs Runs
formats = ['IPL', 'Test', 'ODI', 'T20']
runs = [get_value(filtered_data, f'batting_Runs_{fmt}') for fmt in formats]
balls = [get_value(filtered_data, f'batting_Balls_{fmt}') for fmt in formats]
# Create DataFrame
line_data = pd.DataFrame({
'Format': formats,
'Runs': runs,
'Balls Faced': balls
})
# Melt Data for Plotly
line_data_melted = line_data.melt(id_vars='Format', var_name='Metric', value_name='Count')
# Plot Line Chart
fig_line = px.line(
line_data_melted,
x='Format',
y='Count',
color='Metric',
markers=True,
title=f'{player_name} - Runs vs Balls Faced Across Formats'
)
# Display Chart in Streamlit
st.plotly_chart(fig_line)
# Extract Player Data for Pie Chart runs across all formats
player_data = df[df['Player'] == player_name].iloc[0]
run_columns = ['batting_Runs_Test', 'batting_Runs_ODI', 'batting_Runs_T20', 'batting_Runs_IPL']
runs_data = player_data[run_columns]
plot_data = pd.DataFrame({'Format': ['Test', 'ODI', 'T20', 'IPL'], 'Runs': runs_data.values})
# Plot Pie Chart
fig = px.pie(plot_data, names='Format', values='Runs', title=f'{player_name} - Distribution of Batting Runs Across all Formats')
st.plotly_chart(fig)
# Bar Chart for 4s and 6s
fours_sixes_data = pd.DataFrame({
'Format': ['IPL', 'Test', 'ODI', 'T20'],
"4's": [get_value(filtered_data, f'batting_Fours_{fmt}') for fmt in ['IPL', 'Test', 'ODI', 'T20']],
"6's": [get_value(filtered_data, f'batting_Sixes_{fmt}') for fmt in ['IPL', 'Test', 'ODI', 'T20']]
})
# Data Extraction 50,100,200,300,400
formats = ['Test', 'ODI', 'T20', 'IPL']
fifties = [get_value(filtered_data, f'batting_50s_{fmt}') for fmt in formats]
hundreds = [get_value(filtered_data, f'batting_100s_{fmt}') for fmt in formats]
double_hundreds = [get_value(filtered_data, f'batting_200s_{fmt}') for fmt in formats]
triple_hundreds = [get_value(filtered_data, f'batting_300s_{fmt}') for fmt in formats]
four_hundreds = [get_value(filtered_data, f'batting_400s_{fmt}') for fmt in formats]
# Create DataFrame
comparison_data = pd.DataFrame({
'Format': formats,
'50s': fifties,
'100s': hundreds,
'200s': double_hundreds,
'300s': triple_hundreds,
'400s' : four_hundreds
})
# Melt Data for Plotly
comparison_data_melted = comparison_data.melt(id_vars='Format', var_name='Category', value_name='Count')
# Plot Grouped Bar Chart
fig_comparison = px.bar(
comparison_data_melted,
x='Format',
y='Count',
color='Category',
barmode='group',
title=f'{player_name} - Milestones Across Formats (Grouped Bar Chart)',
labels={'Count': 'Number of Milestones', 'Format': 'Match Format'}
)
# Display Chart in Streamlit
st.plotly_chart(fig_comparison)
# Data Extraction ducks vs notouts
formats = ['IPL', 'Test', 'ODI', 'T20']
not_outs = [get_value(filtered_data, f'batting_Not Out_{fmt}') for fmt in formats]
ducks = [get_value(filtered_data, f'batting_Ducks_{fmt}') for fmt in formats]
else:
# Extract Bowling Data
bowler_data = pd.DataFrame({
'Format': ['IPL', 'Test', 'ODI', 'T20'],
'Matches': [get_value(filtered_data, f'Matches_{fmt}') for fmt in ['IPL', 'Test', 'ODI', 'T20']],
'Innings': [get_value(filtered_data, f'bowling_{fmt}_Innings') for fmt in ['IPL', 'Test', 'ODI', 'T20']],
'Balls': [get_value(filtered_data, f'bowling_{fmt}_Balls') for fmt in ['IPL', 'Test', 'ODI', 'T20']],
'Runs': [get_value(filtered_data, f'bowling_{fmt}_Runs') for fmt in ['IPL', 'Test', 'ODI', 'T20']],
'Maidens': [get_value(filtered_data, f'bowling_{fmt}_Maidens') for fmt in ['IPL', 'Test', 'ODI', 'T20']],
'Wickets': [get_value(filtered_data, f'bowling_{fmt}_Wickets') for fmt in ['IPL', 'Test', 'ODI', 'T20']],
'Average': [get_value(filtered_data, f'bowling_{fmt}_Avg') for fmt in ['IPL', 'Test', 'ODI', 'T20']],
'Economy': [get_value(filtered_data, f'bowling_{fmt}_Eco') for fmt in ['IPL', 'Test', 'ODI', 'T20']],
'Strike Rate': [get_value(filtered_data, f'bowling_{fmt}_SR') for fmt in ['IPL', 'Test', 'ODI', 'T20']],
'BBI': [get_value(filtered_data, f'bowling_{fmt}_BBI') for fmt in ['IPL', 'Test', 'ODI', 'T20']],
'BBM': [get_value(filtered_data, f'bowling_{fmt}_BBM') for fmt in ['IPL', 'Test', 'ODI', 'T20']],
'4W': [get_value(filtered_data, f'bowling_{fmt}_4w') for fmt in ['IPL', 'Test', 'ODI', 'T20']],
'5W': [get_value(filtered_data, f'bowling_{fmt}_5w') for fmt in ['IPL', 'Test', 'ODI', 'T20']],
'10W': [get_value(filtered_data, f'bowling_{fmt}_10w') for fmt in ['IPL', 'Test', 'ODI', 'T20']],
})
st.subheader(f"Bowling Stats for {player_name} ({team_name})")
st.dataframe(bowler_data)
# Bar Chart for Matches Played
matches_data = pd.DataFrame({
'Format': ['IPL', 'Test', 'ODI', 'T20'],
'Matches': [get_value(filtered_data, f'Matches_{fmt}') for fmt in ['IPL', 'Test', 'ODI', 'T20']]
})
fig_matches = px.bar(matches_data, x='Format', y='Matches', title=f'{player_name} - Matches Played Across Formats', color='Format')
st.plotly_chart(fig_matches)
# Extract the player data
player_data = df[df['Player'] == player_name].iloc[0]
wickets_columns = ['bowling_Test_Wickets','bowling_ODI_Wickets','bowling_T20_Wickets','bowling_IPL_Wickets']
runs_data = player_data[wickets_columns]
# Create a DataFrame for Plotly
plot_data = pd.DataFrame({'Format': ['Test', 'ODI', 'T20', 'IPL'], 'Runs': runs_data.values})
fig = px.pie(plot_data, names='Format', values='Runs', title=f'{player_name} - Distribution of Bowling Wickets Across all Formats')
st.plotly_chart(fig)
st.header("Author: L Sai Sreeja") |