Spaces:
Sleeping
Sleeping
| 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( | |
| """ | |
| <style> | |
| .reportview-container { | |
| background: #f7f8fa; /* Fond gris très clair */ | |
| } | |
| .main { | |
| background-color: #fff; | |
| padding: 2rem 3rem; | |
| border-radius: 12px; | |
| box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08); | |
| } | |
| h1 { | |
| color: #2c3e50; /* Bleu foncé élégant */ | |
| text-align: center; | |
| margin-bottom: 2.5rem; | |
| font-size: 2.5rem; | |
| font-weight: 600; | |
| } | |
| h3 { | |
| color: #34495e; /* Bleu légèrement plus clair */ | |
| margin-top: 2rem; | |
| font-size: 1.3rem; | |
| font-weight: 500; | |
| border-bottom: 2px solid #bdc3c7; /* Séparateur subtil */ | |
| padding-bottom: 0.5rem; | |
| margin-bottom: 1rem; | |
| } | |
| .kpi-container { | |
| background-color: #e7f5ff; /* Bleu très clair pour les KPIs */ | |
| border-radius: 8px; | |
| padding: 1.5rem; | |
| text-align: center; | |
| box-shadow: 0 4px 8px rgba(0, 0, 0, 0.04); | |
| border-left: 5px solid #3498db; /* Couleur d'accentuation */ | |
| } | |
| .kpi-label { | |
| color: #7f8c8d; /* Gris bleuté */ | |
| font-size: 0.9rem; | |
| margin-bottom: 0.5rem; | |
| font-weight: 500; | |
| } | |
| .kpi-value { | |
| font-size: 1.8rem; | |
| font-weight: 700; | |
| color: #3498db; /* Couleur d'accentuation */ | |
| } | |
| .chart-container { | |
| background-color: #fff; | |
| border-radius: 12px; | |
| box-shadow: 0 6px 12px rgba(0, 0, 0, 0.06); | |
| padding: 1.5rem 2rem; | |
| margin-top: 2rem; | |
| } | |
| .dataframe-container { | |
| background-color: #fff; | |
| border-radius: 12px; | |
| box-shadow: 0 6px 12px rgba(0, 0, 0, 0.06); | |
| padding: 1.5rem; | |
| margin-top: 2rem; | |
| } | |
| /* Style pour le selectbox */ | |
| .st-selectbox > div > div > div > div { | |
| background-color: #f0f0f0; | |
| border: 1px solid #ccc; | |
| border-radius: 6px; | |
| color: #333; | |
| padding: 0.5rem; | |
| } | |
| /* Style pour le bouton */ | |
| .st-button > button { | |
| background-color: #3498db; | |
| color: white; | |
| border: none; | |
| border-radius: 6px; | |
| padding: 0.75rem 1.5rem; | |
| font-weight: 500; | |
| cursor: pointer; | |
| transition: background-color 0.3s ease; | |
| } | |
| .st-button > button:hover { | |
| background-color: #2980b9; | |
| } | |
| </style> | |
| """, | |
| 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"<div class='kpi-container'><p class='kpi-label'>Âge Moyen</p><p class='kpi-value'>{round(avg_age)} <span style='font-size: 0.8rem;'>ans</span></p></div>", unsafe_allow_html=True) | |
| with kpi2: | |
| st.markdown(f"<div class='kpi-container'><p class='kpi-label'>Clients Mariés</p><p class='kpi-value'>{count_married} <span style='font-size: 0.8rem;'>clients</span></p></div>", unsafe_allow_html=True) | |
| with kpi3: | |
| st.markdown(f"<div class='kpi-container'><p class='kpi-label'>Solde Moyen</p><p class='kpi-value'>$<span style='font-size: 0.8rem;'> {round(avg_balance, 2)}</span></p></div>", 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) |