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
+
|
| 6 |
+
st.markdown("""
|
| 7 |
+
<style>
|
| 8 |
+
.stApp {
|
| 9 |
+
background-color: #E3F2FD;
|
| 10 |
+
}
|
| 11 |
+
.title {
|
| 12 |
+
text-align: center;
|
| 13 |
+
font-size: 28px;
|
| 14 |
+
font-weight: bold;
|
| 15 |
+
color: #2C3E50;
|
| 16 |
+
}
|
| 17 |
+
.subtitle {
|
| 18 |
+
text-align: center;
|
| 19 |
+
font-size: 30px;
|
| 20 |
+
font-weight: bold;
|
| 21 |
+
color: #003366;
|
| 22 |
+
margin-top: 10px;
|
| 23 |
+
}
|
| 24 |
+
.stButton > button {
|
| 25 |
+
width: 100%;
|
| 26 |
+
background-color: #1E88E5;
|
| 27 |
+
color: white;
|
| 28 |
+
font-size: 16px;
|
| 29 |
+
font-weight: bold;
|
| 30 |
+
border-radius: 6px;
|
| 31 |
+
padding: 8px;
|
| 32 |
+
transition: 0.3s;
|
| 33 |
+
}
|
| 34 |
+
.stButton > button:hover {
|
| 35 |
+
background-color: #1565C0;
|
| 36 |
+
}
|
| 37 |
+
.result-box {
|
| 38 |
+
text-align: center;
|
| 39 |
+
font-size: 22px;
|
| 40 |
+
font-weight: bold;
|
| 41 |
+
color: white;
|
| 42 |
+
padding: 15px;
|
| 43 |
+
border-radius: 8px;
|
| 44 |
+
margin-top: 20px;
|
| 45 |
+
background-color: #388E3C;
|
| 46 |
+
}
|
| 47 |
+
</style>
|
| 48 |
+
""", unsafe_allow_html=True)
|
| 49 |
+
|
| 50 |
+
# Load dataset
|
| 51 |
+
df = pd.read_csv("Cleaned_data.csv")
|
| 52 |
+
|
| 53 |
+
st.markdown("<h1 class='title'>Player Performance Analysis</h1>", unsafe_allow_html=True)
|
| 54 |
+
|
| 55 |
+
st.markdown("<hr style='border:1px solid #ddd;'>", unsafe_allow_html=True)
|
| 56 |
+
|
| 57 |
+
default_player = "Virat Kohli"
|
| 58 |
+
player_name = st.selectbox(
|
| 59 |
+
"Select a Player:",
|
| 60 |
+
df['Player'].unique(),
|
| 61 |
+
index=list(df['Player'].unique()).index(default_player)
|
| 62 |
+
)
|
| 63 |
+
|
| 64 |
+
# Filter data for selected player
|
| 65 |
+
player_data = df[df['Player'] == player_name].iloc[0]
|
| 66 |
+
formats = ['Test', 'ODI', 'T20', 'IPL']
|
| 67 |
+
|
| 68 |
+
st.markdown("<br>", unsafe_allow_html=True)
|
| 69 |
+
|
| 70 |
+
st.markdown("<h3 class='title'>Batting Career Summary</h3>", unsafe_allow_html=True)
|
| 71 |
+
|
| 72 |
+
batting_summary = []
|
| 73 |
+
|
| 74 |
+
for fmt in formats:
|
| 75 |
+
batting_summary.append([
|
| 76 |
+
fmt,
|
| 77 |
+
player_data[f'Matches_{fmt}'],
|
| 78 |
+
player_data[f'batting_Innings_{fmt}'],
|
| 79 |
+
player_data[f'batting_Runs_{fmt}'],
|
| 80 |
+
player_data[f'batting_Balls_{fmt}'],
|
| 81 |
+
player_data[f'batting_Highest_{fmt}'],
|
| 82 |
+
player_data[f'batting_Average_{fmt}'],
|
| 83 |
+
player_data[f'batting_SR_{fmt}'],
|
| 84 |
+
player_data[f'batting_Not Out_{fmt}'],
|
| 85 |
+
player_data[f'batting_Fours_{fmt}'],
|
| 86 |
+
player_data[f'batting_Sixes_{fmt}'],
|
| 87 |
+
player_data[f'batting_50s_{fmt}'],
|
| 88 |
+
player_data[f'batting_100s_{fmt}'],
|
| 89 |
+
player_data[f'batting_200s_{fmt}']
|
| 90 |
+
])
|
| 91 |
+
|
| 92 |
+
batting_df = pd.DataFrame(batting_summary, columns=[
|
| 93 |
+
'Format', 'M', 'Inn', 'Runs', 'BF', 'HS', 'Avg', 'SR', 'NO', 'Fours', 'Sixes', '50s', '100s', '200s'
|
| 94 |
+
])
|
| 95 |
+
|
| 96 |
+
st.dataframe(batting_df.style.set_properties(**{'text-align': 'center'}))
|
| 97 |
+
|
| 98 |
+
st.markdown("<br>", unsafe_allow_html=True)
|
| 99 |
+
|
| 100 |
+
st.markdown("<h3 class='title'>Bowling Career Summary</h3>", unsafe_allow_html=True)
|
| 101 |
+
|
| 102 |
+
bowling_summary = []
|
| 103 |
+
|
| 104 |
+
for fmt in formats:
|
| 105 |
+
bowling_summary.append([
|
| 106 |
+
fmt,
|
| 107 |
+
player_data[f'Matches_{fmt}'],
|
| 108 |
+
player_data[f'bowling_{fmt}_Innings'],
|
| 109 |
+
player_data[f'bowling_{fmt}_Balls'],
|
| 110 |
+
player_data[f'bowling_{fmt}_Runs'],
|
| 111 |
+
player_data[f'bowling_{fmt}_Wickets'],
|
| 112 |
+
player_data[f'bowling_{fmt}_Avg'],
|
| 113 |
+
player_data[f'bowling_{fmt}_Eco'],
|
| 114 |
+
player_data[f'bowling_{fmt}_SR'],
|
| 115 |
+
player_data[f'bowling_{fmt}_BBI'],
|
| 116 |
+
player_data[f'bowling_{fmt}_BBM'],
|
| 117 |
+
player_data[f'bowling_{fmt}_5w'],
|
| 118 |
+
player_data[f'bowling_{fmt}_10w']
|
| 119 |
+
])
|
| 120 |
+
|
| 121 |
+
bowling_df = pd.DataFrame(bowling_summary, columns=[
|
| 122 |
+
'Format', 'M', 'Inn', 'B', 'Runs', 'Wkts', 'Avg', 'Econ', 'SR', 'BBI', 'BBM', '5w', '10w'
|
| 123 |
+
])
|
| 124 |
+
|
| 125 |
+
st.dataframe(bowling_df.style.set_properties(**{'text-align': 'center'}))
|
| 126 |
+
|
| 127 |
+
st.markdown("<hr style='border:1px solid #ddd;'>", unsafe_allow_html=True)
|
| 128 |
+
|
| 129 |
+
st.markdown("<h2 class='title'>π Advanced Performance Insights π</h2>", unsafe_allow_html=True)
|
| 130 |
+
|
| 131 |
+
fig1 = px.bar(
|
| 132 |
+
batting_df, x="Format", y="Runs", title="π Total Runs per Format",
|
| 133 |
+
text_auto=True, color_discrete_sequence=["#1E90FF"], opacity=0.9
|
| 134 |
+
)
|
| 135 |
+
st.plotly_chart(fig1)
|
| 136 |
+
|
| 137 |
+
fig2 = px.bar(
|
| 138 |
+
bowling_df, x="Format", y="Wkts", title="π― Total Wickets per Format",
|
| 139 |
+
text_auto=True, color_discrete_sequence=["#FF4500"], opacity=0.9
|
| 140 |
+
)
|
| 141 |
+
st.plotly_chart(fig2)
|
| 142 |
+
|
| 143 |
+
fig3 = px.pie(
|
| 144 |
+
names=["Centuries", "Fifties"],
|
| 145 |
+
values=[batting_df["100s"].sum(), batting_df["50s"].sum()],
|
| 146 |
+
title="π Centuries vs Fifties Contribution",
|
| 147 |
+
hole=0.3, color_discrete_sequence=["#5DADEC", "#FFB6C1", "#7FDBB6", "#FFD700", "#FFA07A", "#BA55D3"]
|
| 148 |
+
)
|
| 149 |
+
st.plotly_chart(fig3)
|