Guía para la elaboración de mapas
con Python y GeoPandas
Guía de Mapas con Python y GeoPandas
Autor: Sergio Diaz Paredes
Contacto: Linkedin
Archivo shape extraido de: geogpsperu
Importando paquetes
In [ ]: pip install geopandas
In [ ]: import geopandas as gpd
import [Link] as plt
import [Link] as gc
Conectando coolab a Drive
In [ ]: [Link]('/content/drive')
Mounted at /content/drive
Leyendo archivos
In [ ]: peru = gpd.read_file("/content/drive/MyDrive/python/[Link]")
Explorando el data frame
In [ ]: [Link]
Index(['OBJECTID', 'NOMBDEP', 'IDPROV', 'CCPP', 'CCDD', 'NOMBPROV', 'FUENTE',
Out[ ]:
'POB_PROYEC', 'POBTOTAL', 'POB_EDAD_T', 'POB_EDAD_1', 'POB_EDAD_E',
'POB_EDAD_2', 'DENSIDAD', 'POBMASCU', 'POBFEMEN', 'POBMASCU_P',
'POBFEMEN_P', 'R_MASCULIN', 'POBURBANA', 'POBRURAL', 'POBURBANA_',
'POBRURAL_P', 'EDAD_PROME', 'EDAD_MEDIA', 'POB_0_14', 'POB_0_14_P',
'POB_15_29', 'POB_15_29_', 'POB_30_59', 'POB_30_59_', 'POB_60_MAS',
'POB_60_M_1', 'POB_ANALFA', 'POB_ANAL_1', 'HOMBRES_AN', 'HOMBRES__1',
'MUJERES_AN', 'MUJERES__1', 'MUJERES_ED', 'MUJERES__2', 'TOTAL_MADR',
'MADRES_SOL', 'MADRES_S_1', 'MUJERES_AD', 'MADRES_ADO', 'MADRES_A_1',
'AL_MENOS_1', 'AL_MENOS_2', 'SIN_DISCAP', 'SIN_DISC_1', 'ALGUNA_NBI',
'NBI_PORC', 'VIV_PARTIC', 'VIV_PART_1', 'VIV_PART_2', 'HOGARES',
'IC_INF', 'IC_SUP', 'UBIC_POBMO', 'TOTAL_DEFU', 'TOTAL_DE_1',
'TOTAL_DE_2', 'NAC_BAJOPE', 'NAC_BAJO_1', 'MUJERES_NA', 'MUJERES__3',
'HOMBRES_NA', 'HOMBRES__2', 'TOTAL_NACI', 'IND_121951', 'IND_122042',
'IND_122047', 'IND_516462', 'IND_516484', 'Shape_Leng', 'Shape_Area',
'Shape_Le_1', 'Shape_Ar_1', 'geometry', 'tasa_nat'],
dtype='object')
Identificando mapa
In [ ]: fig, ax = [Link](figsize=(8, 10))
[Link](ax=ax, color=None, edgecolor='black')
[Link]()
Graficos a nivel nacional
Edad promedio
In [ ]: fig, ax = [Link](figsize=(8,10))
[Link](ax=ax, column='EDAD_PROME',legend=True)
ax.set_title("Distribución de la Edad Promedio por Provincia en el Perú", fontsize=
ax.set_xlabel("Longitud")
ax.set_ylabel("Latitud")
[Link]()
Tasa de poblacion Rural
In [ ]: fig, ax = [Link](figsize=(8,10))
[Link](ax=ax, column='POBRURAL_P',legend=True)
ax.set_title("Distribución de la tasa de poblacion rural por Provincia en el Perú",
ax.set_xlabel("Longitud")
ax.set_ylabel("Latitud")
[Link]()
Poblacion
In [ ]: fig, ax = [Link](figsize=(8,10))
[Link](ax=ax, column='POBTOTAL',legend=True)
ax.set_title("Distribución de la Población por Provincia en el Perú", fontsize=16)
ax.set_xlabel("Longitud")
ax.set_ylabel("Latitud")
[Link]()
Hay un valor atipico
In [ ]: fig, ax = [Link](figsize=(8, 4))
peru['POBTOTAL'].hist(ax=ax)
[Link]()
In [ ]: fig, ax = [Link](figsize=(8,10))
[Link]("POBTOTAL < 8.e6").plot(ax=ax, column='POBTOTAL',legend=True)
ax.set_title("Distribución de la Población por Provincia en el Perú", fontsize=16)
ax.set_xlabel("Longitud")
ax.set_ylabel("Latitud")
[Link]()
Creando la variable tasa de natalidad
Para fines de este analisis se esta considerando:
N úmero de Nacimientos
Tasa de Natalidad = ( ) × 1000
Población Total
In [ ]: peru['tasa_nat'] = peru['TOTAL_NACI'] / peru['POBTOTAL']*1000 #TOTAL_NACI
Revisando posibles valores atipicos
In [ ]: fig, ax = [Link](figsize=(8, 4))
peru['tasa_nat'].hist(ax=ax)
[Link]()
In [ ]: fig, ax = [Link](figsize=(8,10))
[Link](ax=ax, column='tasa_nat',legend=True)
ax.set_title("Tasa de natalidad(x1000 hab) por Provincia en el Perú", fontsize=16)
ax.set_xlabel("Longitud")
ax.set_ylabel("Latitud")
[Link]()
Graficos sub nacionales
Grafico vacio de junin
In [ ]: fig, ax = [Link](figsize=(8, 4))
[Link]("NOMBDEP == 'JUNIN'").[Link](ax=ax, color=None, edgecolor='black'
[Link]()
Poblacion en Junin
In [ ]: fig, ax = [Link](figsize=(8,4))
[Link]("NOMBDEP == 'JUNIN'").plot(ax=ax, column='POBTOTAL',legend=True)
ax.set_title("Distribución de la Población por Provincia en el Perú", fontsize=16)
ax.set_xlabel("Longitud")
ax.set_ylabel("Latitud")
[Link]()