Spaces:
Sleeping
Sleeping
Update analisis.py
Browse files- analisis.py +19 -33
analisis.py
CHANGED
|
@@ -144,41 +144,27 @@ def mostrar_analisis_aerolinea(df, airline):
|
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
-
st.markdown("### 📊
|
| 148 |
-
|
| 149 |
-
#
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
#
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 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 |
-
|
| 181 |
-
|
|
|
|
|
|
|
| 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 |
|