mopaoleonel commited on
Commit
eadddad
·
verified ·
1 Parent(s): 2046427

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +165 -0
  2. bank.csv +0 -0
app.py ADDED
@@ -0,0 +1,165 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import numpy as np
4
+ import seaborn as sns
5
+ import matplotlib.pyplot as plt
6
+ from streamlit_extras.stylable_container import stylable_container
7
+
8
+ # Charger les données
9
+ try:
10
+ df = pd.read_csv('bank.csv')
11
+ except FileNotFoundError:
12
+ 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.")
13
+ st.stop()
14
+
15
+ st.set_page_config(page_title='Analyse Bancaire Professionnelle',
16
+ page_icon='🏦', layout="wide")
17
+
18
+ # --- Styles CSS Personnalisés ---
19
+ st.markdown(
20
+ """
21
+ <style>
22
+ .reportview-container {
23
+ background: #f7f8fa; /* Fond gris très clair */
24
+ }
25
+ .main {
26
+ background-color: #fff;
27
+ padding: 2rem 3rem;
28
+ border-radius: 12px;
29
+ box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
30
+ }
31
+ h1 {
32
+ color: #2c3e50; /* Bleu foncé élégant */
33
+ text-align: center;
34
+ margin-bottom: 2.5rem;
35
+ font-size: 2.5rem;
36
+ font-weight: 600;
37
+ }
38
+ h3 {
39
+ color: #34495e; /* Bleu légèrement plus clair */
40
+ margin-top: 2rem;
41
+ font-size: 1.3rem;
42
+ font-weight: 500;
43
+ border-bottom: 2px solid #bdc3c7; /* Séparateur subtil */
44
+ padding-bottom: 0.5rem;
45
+ margin-bottom: 1rem;
46
+ }
47
+ .kpi-container {
48
+ background-color: #e7f5ff; /* Bleu très clair pour les KPIs */
49
+ border-radius: 8px;
50
+ padding: 1.5rem;
51
+ text-align: center;
52
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.04);
53
+ border-left: 5px solid #3498db; /* Couleur d'accentuation */
54
+ }
55
+ .kpi-label {
56
+ color: #7f8c8d; /* Gris bleuté */
57
+ font-size: 0.9rem;
58
+ margin-bottom: 0.5rem;
59
+ font-weight: 500;
60
+ }
61
+ .kpi-value {
62
+ font-size: 1.8rem;
63
+ font-weight: 700;
64
+ color: #3498db; /* Couleur d'accentuation */
65
+ }
66
+ .chart-container {
67
+ background-color: #fff;
68
+ border-radius: 12px;
69
+ box-shadow: 0 6px 12px rgba(0, 0, 0, 0.06);
70
+ padding: 1.5rem 2rem;
71
+ margin-top: 2rem;
72
+ }
73
+ .dataframe-container {
74
+ background-color: #fff;
75
+ border-radius: 12px;
76
+ box-shadow: 0 6px 12px rgba(0, 0, 0, 0.06);
77
+ padding: 1.5rem;
78
+ margin-top: 2rem;
79
+ }
80
+ /* Style pour le selectbox */
81
+ .st-selectbox > div > div > div > div {
82
+ background-color: #f0f0f0;
83
+ border: 1px solid #ccc;
84
+ border-radius: 6px;
85
+ color: #333;
86
+ padding: 0.5rem;
87
+ }
88
+ /* Style pour le bouton */
89
+ .st-button > button {
90
+ background-color: #3498db;
91
+ color: white;
92
+ border: none;
93
+ border-radius: 6px;
94
+ padding: 0.75rem 1.5rem;
95
+ font-weight: 500;
96
+ cursor: pointer;
97
+ transition: background-color 0.3s ease;
98
+ }
99
+ .st-button > button:hover {
100
+ background-color: #2980b9;
101
+ }
102
+ </style>
103
+ """,
104
+ unsafe_allow_html=True,
105
+ )
106
+
107
+ with stylable_container(key="main_container", css_styles="""
108
+ padding: 2rem 3rem;
109
+ border-radius: 12px;
110
+ box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
111
+ background-color: #fff;
112
+ """):
113
+ # --- Titre du Dashboard ---
114
+ st.title('Analyse Approfondie des Données Bancaires')
115
+
116
+ # --- Filtre sur le type de job ---
117
+ job_filter = st.selectbox('Filtrer par métier', pd.unique(df['job']))
118
+ df_filtered = df[df['job'] == job_filter]
119
+
120
+ # --- Création d'indicateurs clés (KPIs) ---
121
+ avg_age = np.mean(df_filtered['age'])
122
+ count_married = int(df_filtered[df_filtered['marital'] == 'married']['marital'].count())
123
+ avg_balance = np.mean(df_filtered['balance'])
124
+
125
+ kpi1, kpi2, kpi3 = st.columns(3)
126
+
127
+ with kpi1:
128
+ 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)
129
+
130
+ with kpi2:
131
+ 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)
132
+
133
+ with kpi3:
134
+ 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)
135
+
136
+ # --- Graphiques ---
137
+ col1, col2 = st.columns(2)
138
+
139
+ with col1:
140
+ st.markdown('### Répartition de l\'âge par statut marital')
141
+ fig_age_marital = plt.figure(figsize=(10, 5))
142
+ sns.barplot(data=df_filtered, y='age', x='marital', palette='Blues_r')
143
+ plt.title('Âge moyen par statut marital', fontsize=14, fontweight='bold', color='#34495e')
144
+ plt.xlabel('Statut Marital', color='#555')
145
+ plt.ylabel('Âge Moyen', color='#555')
146
+ plt.xticks(fontsize=10)
147
+ plt.yticks(fontsize=10)
148
+ sns.despine() # Supprimer les bordures superflues
149
+ st.pyplot(fig_age_marital)
150
+
151
+ with col2:
152
+ st.markdown('### Distribution des soldes des clients')
153
+ fig_balance_dist = plt.figure(figsize=(10, 5))
154
+ sns.histplot(df_filtered['balance'], bins=30, kde=True, color='#3498db', edgecolor='black')
155
+ plt.title('Distribution des soldes', fontsize=14, fontweight='bold', color='#34495e')
156
+ plt.xlabel('Solde', color='#555')
157
+ plt.ylabel('Fréquence', color='#555')
158
+ plt.xticks(fontsize=10)
159
+ plt.yticks(fontsize=10)
160
+ sns.despine()
161
+ st.pyplot(fig_balance_dist)
162
+
163
+ # --- Vue détaillée des données filtrées ---
164
+ st.markdown('### Données Détaillées')
165
+ st.dataframe(df_filtered)
bank.csv ADDED
The diff for this file is too large to render. See raw diff