ManuelMC commited on
Commit
4702fde
·
verified ·
1 Parent(s): 0f83b82

Update analisis.py

Browse files
Files changed (1) hide show
  1. analisis.py +19 -33
analisis.py CHANGED
@@ -144,41 +144,27 @@ def mostrar_analisis_aerolinea(df, airline):
144
 
145
 
146
 
147
- st.markdown("### 📊 Sentimiento por rating")
148
-
149
- # Agrupar por Rating y Sentimiento
150
- conteo = df_aerolinea.groupby(['Rating', 'Sentimiento']).size().unstack(fill_value=0)
151
-
152
- # Asegurar columnas y orden
153
- for col in ['Negativo', 'Neutral', 'Positivo']:
154
- if col not in conteo.columns:
155
- conteo[col] = 0
156
- conteo = conteo[['Negativo', 'Neutral', 'Positivo']]
157
-
158
- # Asegurar presencia de todos los ratings del 1 al 10
159
- conteo = conteo.reindex(range(1, 11), fill_value=0)
160
-
161
- # Convertir a formato largo para plotly
162
- conteo_reset = conteo.reset_index().melt(id_vars='Rating', var_name='Sentimiento', value_name='Cantidad')
163
-
164
- # Gráfico de barras apiladas con Plotly
165
- fig_barras = px.bar(
166
- conteo_reset,
167
- x='Rating',
168
- y='Cantidad',
169
- color='Sentimiento',
170
- category_orders={"Sentimiento": ["Negativo", "Neutral", "Positivo"]},
171
- color_discrete_map={
172
- 'Negativo': '#FF9999',
173
- 'Neutral': '#FFF5B1',
174
- 'Positivo': '#A6F3A6'
175
- },
176
- title=f"Distribución de sentimientos por rating en {airline}",
177
- labels={"Cantidad": "Número de reseñas", "Rating": "Rating"},
178
  )
179
 
180
- fig_barras.update_layout(barmode='stack', xaxis=dict(dtick=1))
181
- st.plotly_chart(fig_barras)
 
 
182
 
183
 
184
 
 
144
 
145
 
146
 
147
+ st.markdown("### 📊 Número de reseñas por rating")
148
+
149
+ # Asegurar que Rating sea numérico y válido
150
+ ratings_validos = df_aerolinea['Rating'].dropna().astype(int)
151
+
152
+ # Contar cuántas reseñas hay por cada rating (1 a 10)
153
+ conteo_rating = ratings_validos.value_counts().sort_index()
154
+ conteo_rating = conteo_rating.reindex(range(1, 11), fill_value=0)
155
+
156
+ # Crear gráfico de barras con Plotly
157
+ fig_rating = px.bar(
158
+ x=conteo_rating.index,
159
+ y=conteo_rating.values,
160
+ labels={'x': 'Rating', 'y': 'Número de reseñas'},
161
+ title=f'📊 Reseñas por rating en {airline}',
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
162
  )
163
 
164
+ fig_rating.update_traces(marker_color='#3498db')
165
+ fig_rating.update_layout(xaxis=dict(dtick=1))
166
+ st.plotly_chart(fig_rating)
167
+
168
 
169
 
170