jaimalklyde commited on
Commit
8efd6be
·
verified ·
1 Parent(s): 2c2949e

Update src/module/Data_Exploration.py

Browse files
Files changed (1) hide show
  1. src/module/Data_Exploration.py +78 -0
src/module/Data_Exploration.py CHANGED
@@ -65,6 +65,84 @@ class AdvancedAnalyzer: # <--- RENOMMAGE ICI
65
 
66
  return None
67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
  # --- VUES ANALYTIQUES AVANCÉES ---
69
 
70
  def tab_time_series_advanced(self):
 
65
 
66
  return None
67
 
68
+
69
+ # --- Matrice de missing values (heatmap)
70
+
71
+ def plot_missing_matrix(self, table_keyword=''):
72
+
73
+ df = self.get_df(table_keyword) if table_keyword else next(iter(self.dataframes.values()))
74
+
75
+ if df is None:
76
+
77
+ st.warning("Table introuvable pour missing matrix.")
78
+
79
+ return
80
+
81
+ miss = df.isnull().astype(int)
82
+
83
+ # réduire si trop large
84
+
85
+ if miss.shape[1] > 40:
86
+
87
+ st.warning("Beaucoup de colonnes (>40) — afficher un résumé des top colonnes manquantes.")
88
+
89
+ col_missing = (miss.sum().sort_values(ascending=False) / len(df) * 100).head(40)
90
+ df_plot = pd.DataFrame({'col': col_missing.index, 'pct_missing': col_missing.values})
91
+ fig = px.bar(df_plot, x='col', y='pct_missing', title=f"Colonnes les plus manquantes ({table_keyword or 'table'})", text='pct_missing')
92
+ fig.update_traces(texttemplate='%{text:.1f}%', textposition='outside')
93
+ fig.update_layout(xaxis_tickangle=-45)
94
+ st.plotly_chart(fig, use_container_width=True)
95
+
96
+ # --- Distribution numérique + boxplot résumé
97
+
98
+
99
+ def plot_numeric_summary(self, table_keyword, top_n=8):
100
+ df = self.get_df(table_keyword)
101
+ if df is None: return
102
+ num_cols = df.select_dtypes(include='number').columns.tolist()
103
+ if not num_cols:
104
+ st.info("Aucune colonne numérique.")
105
+ return
106
+ num_cols = num_cols[:top_n]
107
+ for col in num_cols:
108
+ c1, c2 = st.columns([2,1])
109
+ with c1:
110
+ fig = px.histogram(df, x=col, nbins=60, marginal='box', title=f"Distribution : {col}")
111
+ st.plotly_chart(fig, use_container_width=True)
112
+ with c2:
113
+ st.write(df[col].describe().to_frame().T)
114
+
115
+
116
+ #----Corrélation (heatmap) pour numériques
117
+
118
+ def plot_correlation(self, table_keyword):
119
+ df = self.get_df(table_keyword)
120
+ if df is None: return
121
+ num = df.select_dtypes(include='number').dropna(axis=1, how='all')
122
+ if num.shape[1] < 2:
123
+ st.info("Pas assez de colonnes numériques pour corrélation.")
124
+ return
125
+ corr = num.corr()
126
+ fig = px.imshow(corr, text_auto=".2f", title=f"Heatmap corrélations ({table_keyword})")
127
+ st.plotly_chart(fig, use_container_width=True)
128
+
129
+ # ----- Vérification d'intégrité référentielle (join rates)
130
+
131
+ def referential_check(self, left_table, right_table, key='patient_id'):
132
+ left = self.get_df(left_table); right = self.get_df(right_table)
133
+ if left is None or right is None:
134
+ st.warning("Tables introuvables pour check référentiel.")
135
+ return
136
+ left_keys = set(left[key].dropna().unique())
137
+ right_keys = set(right[key].dropna().unique())
138
+ in_left_not_right = len(left_keys - right_keys)
139
+ in_right_not_left = len(right_keys - left_keys)
140
+ st.write(f"- Clés {key} dans {left_table}: {len(left_keys):,}")
141
+ st.write(f"- Clés {key} dans {right_table}: {len(right_keys):,}")
142
+ st.metric("Dans left mais pas right", f"{in_left_not_right:,}")
143
+ st.metric("Dans right mais pas left", f"{in_right_not_left:,}")
144
+
145
+
146
  # --- VUES ANALYTIQUES AVANCÉES ---
147
 
148
  def tab_time_series_advanced(self):