|
import streamlit as st
|
|
import pandas as pd
|
|
import folium
|
|
from folium.plugins import MarkerCluster
|
|
from streamlit_folium import st_folium
|
|
import html
|
|
|
|
|
|
st.set_page_config(page_title="Puntajes SIMCE de centros escolares, para estudiantes de 2do medio 2024", page_icon=":school:", layout="wide")
|
|
st.title(":school: Puntajes SIMCE 2024")
|
|
|
|
|
|
dependencia_map = {
|
|
1: 'Municipal Corporaci贸n',
|
|
2: 'Municipal DAEM',
|
|
3: 'Particular subvencionado',
|
|
4: 'Particular pagado',
|
|
5: 'Corporaci贸n de administraci贸n delegada',
|
|
6: 'Servicio Local de Educaci贸n'
|
|
}
|
|
|
|
socioecon_map = {
|
|
1: 'Bajo',
|
|
2: 'Medio Bajo',
|
|
3: 'Medio',
|
|
4: 'Medio Alto',
|
|
5: 'Alto'
|
|
}
|
|
|
|
rural_map = {
|
|
1: 'Urbano',
|
|
2: 'Rural'
|
|
}
|
|
|
|
|
|
@st.cache_data
|
|
def load_data():
|
|
df = pd.read_csv(
|
|
"data/simce.csv",
|
|
sep=";",
|
|
decimal=",",
|
|
encoding="ISO-8859-1",
|
|
header=0,
|
|
on_bad_lines="skip"
|
|
)
|
|
|
|
|
|
df['dependencia_desc'] = df['dependencia'].map(dependencia_map)
|
|
df['grupo_socioecon_desc'] = df['grupo_socioecon'].map(socioecon_map)
|
|
df['es_rural_desc'] = df['es_rural'].map(rural_map)
|
|
|
|
return df
|
|
|
|
|
|
df = load_data()
|
|
|
|
|
|
st.subheader("Establecimientos educacionales en Chile")
|
|
st.markdown("Datos del MINEDUC")
|
|
|
|
|
|
col1, col2 = st.columns(2)
|
|
regiones = ["(Todas)"] + sorted(df["nombre_region"].dropna().unique().tolist())
|
|
ruralidades = ["(Todas)"] + sorted(df["es_rural_desc"].dropna().unique().tolist())
|
|
with col1:
|
|
sel_region = st.selectbox("Regi贸n", regiones, index=0)
|
|
with col2:
|
|
sel_ruralidad = st.selectbox("Ruralidad", ruralidades, index=0)
|
|
|
|
|
|
df_f = df.copy()
|
|
if sel_region != "(Todas)":
|
|
df_f = df_f[df_f["nombre_region"] == sel_region]
|
|
if sel_ruralidad != "(Todas)":
|
|
df_f = df_f[df_f["es_rural_desc"] == sel_ruralidad]
|
|
|
|
|
|
df_map = df_f.dropna(subset=["latitud", "longitud"])
|
|
|
|
|
|
color_map = {
|
|
'Municipal Corporaci贸n': 'blue',
|
|
'Municipal DAEM': 'green',
|
|
'Particular subvencionado': 'orange',
|
|
'Particular pagado': 'purple',
|
|
'Corporaci贸n de administraci贸n delegada': 'red',
|
|
'Servicio Local de Educaci贸n': 'cadetblue'
|
|
}
|
|
|
|
|
|
def tipo_color(tipo: str) -> str:
|
|
return color_map.get(tipo, "gray")
|
|
|
|
|
|
m = folium.Map(location=[-33.45, -70.65], zoom_start=6, tiles="CartoDB positron")
|
|
|
|
|
|
cluster = MarkerCluster().add_to(m)
|
|
|
|
|
|
for _, r in df_map.iterrows():
|
|
lat, lon = float(r["latitud"]), float(r["longitud"])
|
|
nombre = html.escape(str(r.get("nombre_colegio", "")))
|
|
comuna = html.escape(str(r.get("nombre_comuna", "")))
|
|
tipo = html.escape(str(r.get("dependencia_desc", "")))
|
|
lenguaje = html.escape(str(r.get("promedio_lectura", "")))
|
|
matematica = html.escape(str(r.get("promedio_matematica", "")))
|
|
rural = html.escape(str(r.get("es_rural_desc", "")))
|
|
grupoeconomico = html.escape(str(r.get("grupo_socioecon_desc", "")))
|
|
popup_html = f"""
|
|
<b>{nombre}</b><br>
|
|
<b>Tipo:</b> {tipo}<br>
|
|
<b>Comuna:</b> {comuna}<br>
|
|
<b>Promedio lenguaje:</b> {lenguaje}<br>
|
|
<b>Promedio matematica:</b> {matematica}<br>
|
|
<b>Es rural:</b> {rural}<br>
|
|
<b>Grupo socioeconomico:</b> {grupoeconomico}
|
|
"""
|
|
folium.Marker(
|
|
location=[lat, lon],
|
|
popup=folium.Popup(popup_html, max_width=350),
|
|
icon=folium.Icon(color=tipo_color(r.get("dependencia_desc")), icon="plus", prefix="fa"),
|
|
).add_to(cluster)
|
|
|
|
|
|
legend_html = """
|
|
<div style="
|
|
position: fixed;
|
|
bottom: 30px; left: 30px; z-index: 9999;
|
|
background: white; padding: 10px 12px; border: 1px solid #ddd; border-radius: 8px;
|
|
color: black; font-size: 13px;">
|
|
<b style="color:black;">Leyenda</b><br>
|
|
<span style="display:inline-block;width:12px;height:12px;background:blue;margin-right:6px;"></span><span style="color:black;">Municipal Corporaci贸n</span><br>
|
|
<span style="display:inline-block;width:12px;height:12px;background:green;margin-right:6px;"></span><span style="color:black;">Municipal DAEM</span><br>
|
|
<span style="display:inline-block;width:12px;height:12px;background:orange;margin-right:6px;"></span><span style="color:black;">Particular subvencionado</span><br>
|
|
<span style="display:inline-block;width:12px;height:12px;background:purple;margin-right:6px;"></span><span style="color:black;">Particular pagado</span><br>
|
|
<span style="display:inline-block;width:12px;height:12px;background:red;margin-right:6px;"></span><span style="color:black;">Corporaci贸n de administraci贸n delegada</span><br>
|
|
<span style="display:inline-block;width:12px;height:12px;background:cadetblue;margin-right:6px;"></span><span style="color:black;">Servicio Local de Educaci贸n</span><br>
|
|
<span style="display:inline-block;width:12px;height:12px;background:gray;margin-right:6px;"></span><span style="color:black;">Otros</span>
|
|
</div>
|
|
"""
|
|
m.get_root().html.add_child(folium.Element(legend_html))
|
|
|
|
|
|
st_folium(m, width=1200, height=650)
|
|
|
|
|
|
with st.expander("Ver tabla filtrada"):
|
|
columns_to_display = ['nombre_region', 'nombre_comuna', 'nombre_colegio', 'dependencia_desc', 'grupo_socioecon_desc', 'es_rural_desc', 'promedio_lectura', 'promedio_matematica']
|
|
st.dataframe(df_map[columns_to_display]) |