guille03 commited on
Commit
0da3765
·
1 Parent(s): d6cce75
Files changed (1) hide show
  1. analisis.py +9 -12
analisis.py CHANGED
@@ -79,30 +79,27 @@ class AnalizadorDatos:
79
 
80
  def generar_graficos(self, columnas_analisis: list) -> dict:
81
  """Genera gráficos para las columnas especificadas"""
82
-
83
- # CAMBIO: Usar /tmp en lugar de "graficos"
84
  graficos_dir = "/tmp/graficos"
85
- os.makedirs(graficos_dir, exist_ok=True)
86
 
87
  for col in columnas_analisis:
88
  if col not in self.df.columns:
89
  continue
90
 
91
- # CAMBIO: Usar os.path.join con el nuevo directorio
92
- output_path = os.path.join(graficos_dir, f"{col}.png")
93
 
94
  if pd.api.types.is_numeric_dtype(self.df[col]):
95
  path = generar_histograma_r(self.df, col, output_path)
96
  if path:
97
  self.graficos[col] = {'tipo': 'histograma', 'path': path}
98
-
99
- categoricas = [c for c in self.df.columns
100
- if pd.api.types.is_categorical_dtype(self.df[c])
101
- or pd.api.types.is_object_dtype(self.df[c])]
102
-
103
  if categoricas and len(self.df[categoricas[0]].unique()) <= 10:
104
- boxplot_path = os.path.join(graficos_dir, f"{col}_by_{categoricas[0]}.png")
105
- path = generar_boxplot_r(self.df, col, categoricas[0], boxplot_path)
106
  if path:
107
  self.graficos[f"{col}_by_{categoricas[0]}"] = {'tipo': 'boxplot', 'path': path}
108
  else:
 
79
 
80
  def generar_graficos(self, columnas_analisis: list) -> dict:
81
  """Genera gráficos para las columnas especificadas"""
82
+
 
83
  graficos_dir = "/tmp/graficos"
84
+ os.makedirs("graficos", exist_ok=True)
85
 
86
  for col in columnas_analisis:
87
  if col not in self.df.columns:
88
  continue
89
 
90
+ output_path = os.path.join(graficos_dir,f"{col}.png")
 
91
 
92
  if pd.api.types.is_numeric_dtype(self.df[col]):
93
  path = generar_histograma_r(self.df, col, output_path)
94
  if path:
95
  self.graficos[col] = {'tipo': 'histograma', 'path': path}
96
+
97
+ # Gráfico adicional si hay una columna categórica adecuada
98
+ categoricas = [c for c in self.df.columns
99
+ if pd.api.types.is_categorical_dtype(self.df[c])
100
+ or pd.api.types.is_object_dtype(self.df[c])]
101
  if categoricas and len(self.df[categoricas[0]].unique()) <= 10:
102
+ path = generar_boxplot_r(self.df, col, categoricas[0], f"graficos/{col}_by_{categoricas[0]}.png")
 
103
  if path:
104
  self.graficos[f"{col}_by_{categoricas[0]}"] = {'tipo': 'boxplot', 'path': path}
105
  else: