import streamlit as st import pandas as pd import numpy as np import seaborn as sns import matplotlib.pyplot as plt from streamlit_extras.stylable_container import stylable_container # Charger les données try: df = pd.read_csv('bank.csv') except FileNotFoundError: st.error("Le fichier 'bank.csv' n'a pas été trouvé. Veuillez vous assurer qu'il se trouve dans le même répertoire que le script.") st.stop() st.set_page_config(page_title='Analyse Bancaire Professionnelle', page_icon='🏦', layout="wide") # --- Styles CSS Personnalisés --- st.markdown( """ """, unsafe_allow_html=True, ) with stylable_container(key="main_container", css_styles=""" padding: 2rem 3rem; border-radius: 12px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08); background-color: #fff; """): # --- Titre du Dashboard --- st.title('Analyse Approfondie des Données Bancaires') # --- Filtre sur le type de job --- job_filter = st.selectbox('Filtrer par métier', pd.unique(df['job'])) df_filtered = df[df['job'] == job_filter] # --- Création d'indicateurs clés (KPIs) --- avg_age = np.mean(df_filtered['age']) count_married = int(df_filtered[df_filtered['marital'] == 'married']['marital'].count()) avg_balance = np.mean(df_filtered['balance']) kpi1, kpi2, kpi3 = st.columns(3) with kpi1: st.markdown(f"

Âge Moyen

{round(avg_age)} ans

", unsafe_allow_html=True) with kpi2: st.markdown(f"

Clients Mariés

{count_married} clients

", unsafe_allow_html=True) with kpi3: st.markdown(f"

Solde Moyen

$ {round(avg_balance, 2)}

", unsafe_allow_html=True) # --- Graphiques --- col1, col2 = st.columns(2) with col1: st.markdown('### Répartition de l\'âge par statut marital') fig_age_marital = plt.figure(figsize=(10, 5)) sns.barplot(data=df_filtered, y='age', x='marital', palette='Blues_r') plt.title('Âge moyen par statut marital', fontsize=14, fontweight='bold', color='#34495e') plt.xlabel('Statut Marital', color='#555') plt.ylabel('Âge Moyen', color='#555') plt.xticks(fontsize=10) plt.yticks(fontsize=10) sns.despine() # Supprimer les bordures superflues st.pyplot(fig_age_marital) with col2: st.markdown('### Distribution des soldes des clients') fig_balance_dist = plt.figure(figsize=(10, 5)) sns.histplot(df_filtered['balance'], bins=30, kde=True, color='#3498db', edgecolor='black') plt.title('Distribution des soldes', fontsize=14, fontweight='bold', color='#34495e') plt.xlabel('Solde', color='#555') plt.ylabel('Fréquence', color='#555') plt.xticks(fontsize=10) plt.yticks(fontsize=10) sns.despine() st.pyplot(fig_balance_dist) # --- Vue détaillée des données filtrées --- st.markdown('### Données Détaillées') st.dataframe(df_filtered)