Explorando los datos de los presupuestos nacionales

 

Exploración de datos de presupuestos nacionales

En el post anterior mostré el scrape hecho al sistema de contabilidad del estado SICOIN. Ahora tomaré esos datos para explorarlos.

Una cosa que quiero mencionar antes, para quienes no estén familiarizados con estos datos es el significado del presupuesto asignado, vigente y devengado.

El dinero Asignado es lo que sale de la alcantarilla del congreso. Así como el presupuesto 2021 fue discutido entre varios sectores, cada ministerio solicitó ciertas cantidades para cada programa, renglón, etc, hay un presupuesto solicitado pero luego eso llega al deshonorable congreso de la república y allí entre los 160 diputados, negocian y reparten el dinero casi a su antojo. Claro que hay límites y no pueden en realidad tomar todo el dinero, digamos, para sus bonos. Pero sí negocian obras, empleo, plazas fantasma, aumentos, posiciones de poder en los ministerios, favores políticos, y quién sabe qué más. Aunque un ministerio solicite una cantidad, el congreso lo puede modificar. Del congreso sale, entonces, un presupuesto Asignado. Luego ya al momento de enfrentar la realidad tal asignación va quedando obsoleta y se hace necesario modificar los montos presupuestados. Hay una columna de Modificado y luego Asignado + Modificado = Vigente. Finalmente, se llega a lo Devengado, que es lo que sale de las cuentas del estado para pagar todo lo que se ha ido Ejecutando. No se llega a ejecutar todo, usualmente y siempre hay un excedente que queda para el próximo ciclo.

In [178]:
import pandas as pd
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn
import altair
%matplotlib inline

 

In [7]:
datos = pd.read_csv("sicoin_programas_acts_2004-2020.csv.gz", index_col=0)

 

In [14]:
datos.columns

 

 

Out[14]:
Index(['CodEntidad', 'CodPrograma', 'CodActOb', 'Programa', 'ActOb',
       'Asignado', 'Modificado', 'Vigente', 'PreCompromiso', 'Comprometido',
       'Devengado', 'Pagado', 'SaldoPorComprometer', 'SaldoPorDevengar',
       'SaldoPorPagar', 'PorcentajeE', 'Year'],
      dtype='object')
 

Presupuestos totales (Asignado, Vigente y Devengado) por año

In [642]:
#seaborn.lineplot(
plot = datos.groupby("Year").agg({
    "Asignado": "sum",
    "Vigente": "sum",
    "Devengado": "sum"
}).plot()
plt.gca().yaxis.set_major_formatter(plt.matplotlib.ticker.FuncFormatter(lambda x, i: str(int(x/1e9))+"B"))
plt.grid(True)

 

 

 
 

En 2020 se dispara lo vigente por la emergencia del COVID-19 (aunque los beneficios no fueron pagados a la mayoría de la población) y hay poca ejecución (seguramente porque estos datos fueron obtenidos sin que finalice el año).

In [114]:
import re
import unicodedata

 

In [617]:
espacios = re.compile('\s+')
puntofinal = re.compile("\.\s*
 
quot;) pgnfinal = re.compile("\(PGN\)\s*
 
quot;) def remove_accents(input_str): try: nfkd_form = unicodedata.normalize('NFKD', input_str) only_ascii = nfkd_form.encode('ASCII', 'ignore') return str(only_ascii.decode()).strip() except: return ""

 

In [129]:
datos.CodEntidad.replace(espacios, " ").replace(puntofinal,"").replace(pgnfinal,"").apply(remove_accents)\
.apply(lambda x: x.split(" - ")[1]).value_counts()

 

 

Out[129]:
MINISTERIO DE COMUNICACIONES, INFRAESTRUCTURA Y VIVIENDA    3687
SECRETARIAS Y OTRAS DEPENDENCIAS DEL EJECUTIVO              3196
MINISTERIO DE EDUCACION                                     1387
MINISTERIO DE SALUD PUBLICA Y ASISTENCIA SOCIAL             1286
OBLIGACIONES DEL ESTADO A CARGO DEL TESORO                  1042
MINISTERIO DE AGRICULTURA, GANADERIA Y ALIMENTACION          930
MINISTERIO DE CULTURA Y DEPORTES                             702
MINISTERIO DE GOBERNACION                                    682
MINISTERIO DE TRABAJO Y PREVISION SOCIAL                     552
MINISTERIO DE FINANZAS PUBLICAS                              454
MINISTERIO DE ECONOMIA                                       448
MINISTERIO DE DESARROLLO SOCIAL                              447
MINISTERIO DE AMBIENTE Y RECURSOS NATURALES                  409
MINISTERIO DE LA DEFENSA NACIONAL                            383
MINISTERIO DE ENERGIA Y MINAS                                359
MINISTERIO DE RELACIONES EXTERIORES                          265
PRESIDENCIA DE LA REPUBLICA                                  158
PROCURADURIA GENERAL DE LA NACION                             93
CONTRALORIA GENERAL DE CUENTAS                                59
SERVICIOS DE LA DEUDA PUBLICA                                 34
Name: CodEntidad, dtype: int64
In [130]:
datos["Entidad"] = datos.CodEntidad.replace(espacios, " ").replace(puntofinal,"").replace(pgnfinal,"").apply(remove_accents)\
.apply(lambda x: x.split(" - ")[1])

 

In [159]:
datosentidad = datos.groupby(["Entidad", "Year"]).agg({
    "Asignado": "sum",
    "Vigente": "sum",
    "Devengado": "sum"
})

 

In [205]:
datosentidad.reset_index().columns

 

 

Out[205]:
Index(['Entidad', 'Year', 'Asignado', 'Vigente', 'Devengado'], dtype='object')
 

Heatmap logarítmico que muestra la concentración del dinero devengado

In [552]:
altair.Chart.from_dict(
    {
  "$schema": "https://vega.github.io/schema/vega-lite/v4.json",
  "description": "A simple bar chart with embedded data.",
  "data": {
      "values":  datosentidad.reset_index().to_dict(orient = "records")
  },
  "mark": "rect",
  "encoding": {
    "x": {
      "field": "Year",
      "type": "nominal"
    },
    "y": {
      "field": "Entidad",
      "type": "nominal"
    },
    "color": {
      "aggregate": "sum", "field": "Devengado",
      "type": "quantitative",
      "scale": {
          "type":"log",
        "scheme": "viridis",
      }
    }
  }
}
)

 

 

Out[552]:
 

In [297]:
plotdata = datosentidad.reset_index().sort_values(["Devengado"],ascending=False).assign(Entidad = lambda x: \
                   x.Entidad.apply(lambda y : y.replace("MINISTERIO", "M.")\
                                  .replace("SECRETARIA", "SEC.").replace("OBLIGACIONES", "OB."))).to_dict(orient = "records")

 

 

Intentando visualizar la distribución del presupuesto por año en un sólo gráfico es difícil porque hay entidades que apenas se notan y otras que abarcan cantidades inmensas. Por lo menos se puede observar que los mayores montos están en Obligaciones del estado a cargo del tesoro (aportes a municipalidades, congreso de la república, sistema de justicia, SAT y otras cosas), Servicios de la deuda pública (pago de deuda pública), Min. de Educación, Min. de Salud, Min. de comunicaciones, infraestructura y vivienda, Min. de gobernación (PNC, MP, etc), El ejército (Min. de defensa (¿defensa de qué?)).

Dinero devengado por Entidad (miles de millones)

In [467]:
campo = "Devengado"
altair.Chart.from_dict(
{
  "$schema": "https://vega.github.io/schema/vega-lite/v4.json",
  "description": "Chart",
  "data": {
      "values":  plotdata
  },
    "layer":[
        {
          "mark": {"type": "bar", "tooltip": True},
          "encoding": {
            "tooltip": [
              {"field": campo, "type": "quantitative", "title": campo, "format": ".2s"},
              {"field": "Entidad", "type": "nominal", "title": "Entidad"},
            ],
            #"order":  {"field": campo, "type": "quantitative"
            #},
            "y": {
              "field": campo,
              "type": "quantitative",
                "axis": {"format": ".2s", "title": campo},
             #   "scale": {"type": "pow", "exponent": 0.5,}
            },
            "x": {"field": "Year", "type": "nominal"},
            "color": {
              "field": "Entidad",
                "type": "nominal",
              "scale": {"scheme": "category20b"}
            }

          }
        }
    ],
  "width": 600
})

 

 

Out[467]:
 

 

Porcentaje de presupuesto devengado por entidad:

In [468]:
campo = "Devengado"
altair.Chart.from_dict(
{
  "$schema": "https://vega.github.io/schema/vega-lite/v4.json",
  "description": "Chart",
  "data": {
      "values":  plotdata
  },
    "layer":[
        {
          "mark": {"type": "bar", "tooltip": True},
          "encoding": {
            "order":  {"field": campo, "type": "quantitative", "sort":"descending"
            },
            "y": {
              "field": campo,
              "type": "quantitative",
                "stack": "normalize",
                "axis": {"format": "%", "title": campo}
            },
            "x": {"field": "Year", "type": "nominal"},
            "color": {
              "field": "Entidad",
                "type": "nominal",
              "scale": {"scheme": "category20b"}
            },
            "tooltip": [
              {"field": campo, "type": "quantitative", "title": campo, "format": ".2s"},
              {"field": "Entidad", "type": "nominal", "title": "Entidad"},
            ],

          }
        }
    ],
  "width": 600
})

 

 

Out[468]:
 

 

Veamos la tendencia de cada entidad de 2004 a 2020 por separado para que la gran diferencia entre las cantidades no invisibilice a las entidades con menor presupuesto.

In [433]:
campo = "Devengado"
altair.Chart.from_dict(
{
  "$schema": "https://vega.github.io/schema/vega-lite/v4.json",
  "description": "Chart",
  "data": {
      "values":  plotdata
  },
          "mark": {"type": "line", "tooltip": True},
          "encoding": {
              "facet": {"field": "Entidad", "type": "ordinal", "columns": 3},
            "y": {
              "field": campo,
              "type": "quantitative",
                "axis": {"format": ".2s", "title": campo}
            },
            "x": {"field": "Year", "type": "nominal"},
            "tooltip": [
              {"field": campo, "type": "quantitative", "title": campo, "format": ".2s"},
              {"field": "Entidad", "type": "nominal", "title": "Entidad"},
            ],

          },
  "width": 200, "height": 50,
  "resolve": {
      "axis": {"y": "independent"},
      "scale": {"y": "independent"},
  },
    "title": "Presupuestos por entidad por año"

})

 

 

Out[433]:
 

In [427]:
temp = datosentidad.Devengado.unstack(level=0)
temp["total"] = temp.sum(axis=1)

 

In [428]:
temp = temp.divide(temp.total, axis="rows")

 

In [429]:
temp = temp.drop(columns="total").stack().rename("Devengado").reset_index().to_dict("records")

 

In [430]:
temp[0]

 

 

Out[430]:
{'Year': 2004.0,
 'Entidad': 'CONTRALORIA GENERAL DE CUENTAS',
 'Devengado': 0.004246229279755743}
 

Y ahora las series temporales de porcentaje de cada entidad en el presupuesto devengado entre 2004-2020.

In [438]:
campo = "Devengado"
altair.Chart.from_dict(
{
  "$schema": "https://vega.github.io/schema/vega-lite/v4.json",
  "description": "Chart",
  "data": {
      "values":  temp
  },
          "mark": {"type": "line", "tooltip": True},
          "encoding": {
              "facet": {"field": "Entidad", "type": "ordinal", "columns": 3},
            "y": {
              "field": campo,
              "type": "quantitative",
                "axis": {"format": "%", "title": campo}
            },
            "x": {"field": "Year", "type": "nominal"},
            "tooltip": [
              {"field": campo, "type": "quantitative", "title": campo, "format": ".2s"},
              {"field": "Entidad", "type": "nominal", "title": "Entidad"},
            ],

          },
  "width": 250, "height": 50,
  "resolve": {
      "axis": {"y": "independent"},
      "scale": {"y": "independent"},
  },
    "title": "Porcentaje por entidad cada año"

})

 

 

Out[438]:
 

In [548]:
temp = datosentidad.Devengado.unstack(level=0)
temp["total"] = temp.sum(axis=1)

 

In [549]:
temp = temp.divide(temp.total, axis="rows")

 

In [550]:
temp = temp.drop(columns="total").stack().rename("Devengado").reset_index()\
[lambda x: x.Entidad.map(lambda y: "GOBERN" in y)].to_dict("records")

 

 

Las actividades más costosas en 2019 de la categoría “Oblicaciones del estado a cargo el tesoro” :

In [534]:
plotdata = datos[datos.Entidad.map(lambda x: "OBLIG" in x)].groupby(["Year","ActOb"]).agg({
    "Devengado": "sum",
    "Vigente": "sum",
    "Asignado": "sum"
})
plotdata = plotdata[["Devengado"]].divide(1e6).round().unstack(0).reset_index().sort_values(("Devengado", 2019),ascending=False).head(20)
plotdata.fillna(0)

 

 

Out[534]:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  ActOb Devengado
Year   2004.0 2005.0 2006.0 2007.0 2008.0 2009.0 2010.0 2011.0 2012.0 2013.0 2014.0 2015.0 2016.0 2017.0 2018.0 2019.0 2020.0
38 APORTE A MUNICIPALIDADES 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 6070.0 6146.0 6391.0 6621.0 6812.0 6789.0 7615.0 6809.0
90 CLASES PASIVAS CIVILES DEL ESTADO 0.0 0.0 0.0 0.0 0.0 0.0 0.0 2890.0 3136.0 3429.0 3607.0 3739.0 4174.0 4686.0 5012.0 5138.0 4151.0
288 SISTEMA DE JUSTICIA 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1968.0 2298.0 2434.0 2422.0 2739.0 3199.0 3998.0 4099.0 3845.0 3476.0
118 EDUCACIÓN 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1476.0 1397.0 1752.0 1911.0 1805.0 2151.0 2169.0 1568.0
22 ADMINISTRACIÓN FISCAL 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 771.0 1120.0 1244.0 1054.0 956.0 852.0
220 PROTECCIÓN SOCIAL 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 603.0 498.0 537.0 621.0 726.0 724.0 817.0 769.0
279 SERVICIOS ELECTORALES 0.0 0.0 0.0 0.0 0.0 0.0 0.0 661.0 147.0 157.0 150.0 654.0 157.0 181.0 194.0 670.0 150.0
24 ADMINISTRACIÓN LEGISLATIVA 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 549.0 549.0 672.0 719.0 615.0 615.0 613.0 532.0
0 ABASTECIMIENTO DE AGUA 0.0 0.0 0.0 0.0 0.0 0.0 0.0 170.0 217.0 115.0 180.0 62.0 251.0 502.0 605.0 550.0 263.0
136 FOMENTO Y PROMOCIÓN DEL DEPORTE 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 398.0 403.0 377.0 425.0 450.0 458.0 451.0 386.0
271 SERVICIOS DE FISCALIZACIÓN 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 286.0 328.0 335.0 375.0 422.0 428.0
123 EDUCACIÓN PRIMARIA 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 106.0 167.0 52.0 205.0 340.0 421.0 374.0 216.0
171 ORDENACIÓN DE AGUAS RESIDUALES 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 87.0 121.0 36.0 138.0 351.0 445.0 358.0 228.0
155 INCENTIVOS FORESTALES PINPEP 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 74.0 124.0 142.0 271.0 290.0 300.0 304.0 241.0
60 APOYO AL SISTEMA DE JUSTICIA 0.0 0.0 0.0 0.0 0.0 0.0 0.0 255.0 353.0 313.0 296.0 159.0 181.0 224.0 244.0 277.0 235.0
85 ATENCIÓN A DESASTRES Y GESTIÓN DE RIESGOS 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 178.0 178.0 254.0 187.0 214.0 257.0 256.0 220.0
217 PROTECCIÓN AMBIENTAL 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 155.0 107.0 209.0 158.0 149.0 194.0 225.0 229.0
103 DEFENSORÍA PÚBLICA PENAL 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 121.0 157.0 205.0 201.0 213.0 200.0
104 DESARROLLO COMUNITARIO 0.0 0.0 0.0 0.0 0.0 0.0 0.0 228.0 132.0 162.0 183.0 57.0 59.0 167.0 235.0 211.0 59.0
290 TRANSPORTE 0.0 0.0 0.0 0.0 0.0 0.0 0.0 53.0 10.0 0.0 0.0 147.0 188.0 150.0 195.0 199.0 137.0
In [535]:
plotdata = datos[datos.Entidad.map(lambda x: "OBLIG" in x)].groupby(["Year","ActOb"]).agg({
    "Devengado": "sum",
    "Vigente": "sum",
    "Asignado": "sum"
})
plotdata = plotdata[["Devengado"]].divide(1e6).round().unstack(0)#.reset_index().sort_values(("Devengado", 2020),ascending=False)
plotdata.divide(plotdata.sum()/100.0, axis="columns").round(2).fillna(0).sort_values(("Devengado", 2019), ascending= False).head(20)

 

 

Out[535]:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  Devengado
Year 2004.0 2005.0 2006.0 2007.0 2008.0 2009.0 2010.0 2011.0 2012.0 2013.0 2014.0 2015.0 2016.0 2017.0 2018.0 2019.0 2020.0
ActOb                                  
APORTE A MUNICIPALIDADES 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.00 0.00 30.79 31.30 31.48 28.19 26.88 26.15 28.42 26.81
CLASES PASIVAS CIVILES DEL ESTADO 0.0 0.0 0.0 0.0 0.0 0.0 0.0 16.27 16.35 17.39 18.37 18.42 17.77 18.49 19.30 19.17 16.35
SISTEMA DE JUSTICIA 0.0 0.0 0.0 0.0 0.0 0.0 0.0 11.08 11.98 12.35 12.33 13.49 13.62 15.77 15.79 14.35 13.69
EDUCACIÓN 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.00 0.00 7.49 7.11 8.63 8.14 7.12 8.28 8.09 6.17
ADMINISTRACIÓN FISCAL 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.00 0.00 0.00 0.00 3.80 4.77 4.91 4.06 3.57 3.35
PROTECCIÓN SOCIAL 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.00 0.00 3.06 2.54 2.64 2.64 2.86 2.79 3.05 3.03
SERVICIOS ELECTORALES 0.0 0.0 0.0 0.0 0.0 0.0 0.0 3.72 0.77 0.80 0.76 3.22 0.67 0.71 0.75 2.50 0.59
ADMINISTRACIÓN LEGISLATIVA 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.00 0.00 2.78 2.80 3.31 3.06 2.43 2.37 2.29 2.09
ABASTECIMIENTO DE AGUA 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.96 1.13 0.58 0.92 0.31 1.07 1.98 2.33 2.05 1.04
FOMENTO Y PROMOCIÓN DEL DEPORTE 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.00 0.00 2.02 2.05 1.86 1.81 1.78 1.76 1.68 1.52
SERVICIOS DE FISCALIZACIÓN 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.00 0.00 0.00 0.00 1.41 1.40 1.32 1.44 1.57 1.69
EDUCACIÓN PRIMARIA 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.00 0.00 0.54 0.85 0.26 0.87 1.34 1.62 1.40 0.85
ORDENACIÓN DE AGUAS RESIDUALES 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.00 0.00 0.44 0.62 0.18 0.59 1.38 1.71 1.34 0.90
INCENTIVOS FORESTALES PINPEP 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.00 0.00 0.38 0.63 0.70 1.15 1.14 1.16 1.13 0.95
APOYO AL SISTEMA DE JUSTICIA 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.44 1.84 1.59 1.51 0.78 0.77 0.88 0.94 1.03 0.93
ATENCIÓN A DESASTRES Y GESTIÓN DE RIESGOS 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.00 0.00 0.90 0.91 1.25 0.80 0.84 0.99 0.96 0.87
PROTECCIÓN AMBIENTAL 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.00 0.00 0.79 0.54 1.03 0.67 0.59 0.75 0.84 0.90
DESARROLLO COMUNITARIO 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.28 0.69 0.82 0.93 0.28 0.25 0.66 0.91 0.79 0.23
DEFENSORÍA PÚBLICA PENAL 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.00 0.00 0.00 0.00 0.60 0.67 0.81 0.77 0.79 0.79
TRANSPORTE 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.30 0.05 0.00 0.00 0.72 0.80 0.59 0.75 0.74 0.54
 

Las actividades más costosas en 2004 de la categoría “Oblicaciones del estado a cargo el tesoro” :

In [532]:
plotdata = datos[datos.Entidad.map(lambda x: "OBLIG" in x)].groupby(["Year","ActOb"]).agg({
    "Devengado": "sum",
    "Vigente": "sum",
    "Asignado": "sum"
})
plotdata = plotdata[["Devengado"]].divide(1e6).round().unstack(0).reset_index().sort_values(("Devengado", 2010),ascending=False).head(20)
plotdata.fillna(0)

 

 

Out[532]:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  ActOb Devengado
Year   2004.0 2005.0 2006.0 2007.0 2008.0 2009.0 2010.0 2011.0 2012.0 2013.0 2014.0 2015.0 2016.0 2017.0 2018.0 2019.0 2020.0
6 ACTIVIDADES DE DESARROLLO URBANO Y RURAL 2141.0 2661.0 3044.0 3052.0 3782.0 3830.0 4237.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
13 ACTIVIDADES DE TRABAJO Y PREVISION SOCIAL 2008.0 2147.0 2554.0 2724.0 2877.0 3144.0 3329.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
17 ACTIVIDADES JUDICIALES 1172.0 1213.0 1327.0 1301.0 1841.0 1785.0 1818.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
7 ACTIVIDADES DE EDUCACION 566.0 725.0 805.0 850.0 1003.0 1048.0 1025.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
3 ACTIVIDADES DE ADMINISTRACION FISCAL 607.0 675.0 843.0 913.0 996.0 921.0 984.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
88 CAMINOS VECINALES 293.0 319.0 570.0 510.0 608.0 699.0 743.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
260 REGISTRO NACIONAL DE PERSONAS 0.0 0.0 0.0 35.0 0.0 300.0 684.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
18 ACTIVIDADES LEGISLATIVAS -CONGRESO DE LA REPUB… 250.0 260.0 270.0 304.0 304.0 359.0 427.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
168 OBRAS MUNICIPALES 53.0 44.0 114.0 144.0 120.0 255.0 378.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
33 AGUA Y SANEAMIENTO AMBIENTAL 275.0 284.0 311.0 197.0 287.0 320.0 375.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
5 ACTIVIDADES DE CULTURA Y DEPORTES 217.0 237.0 269.0 277.0 304.0 312.0 319.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
96 CONSTRUCCIONES ESCOLARES 130.0 161.0 147.0 150.0 199.0 230.0 240.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
14 ACTIVIDADES DE TRANSPORTE 54.0 129.0 160.0 200.0 341.0 354.0 188.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
36 APORTE A LA CONTRALORIA GENERAL DE CUENTAS 0.0 0.0 0.0 0.0 228.0 167.0 173.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
8 ACTIVIDADES DE MEDIO AMBIENTE 106.0 103.0 123.0 157.0 167.0 166.0 130.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
11 ACTIVIDADES DE SEGURIDAD INTERNA 56.0 66.0 62.0 119.0 173.0 150.0 130.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
281 SERVICIOS FORENSES 0.0 0.0 0.0 0.0 275.0 95.0 127.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
12 ACTIVIDADES DE SERVICIOS GENERALES 65.0 91.0 93.0 91.0 131.0 116.0 127.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
19 ACTIVIDADES LEGISLATIVAS -PROCURADURIA DERECHO… 46.0 64.0 65.0 74.0 109.0 101.0 101.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
127 FIDEICOMISO DE TRANSPORTE DE LA CIUDAD DE GUAT… 0.0 0.0 0.0 0.0 65.0 90.0 100.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
In [533]:
plotdata = datos[datos.Entidad.map(lambda x: "OBLIG" in x)].groupby(["Year","ActOb"]).agg({
    "Devengado": "sum",
    "Vigente": "sum",
    "Asignado": "sum"
})
plotdata = plotdata[["Devengado"]].divide(1e6).round().unstack(0)#.reset_index().sort_values(("Devengado", 2020),ascending=False)
plotdata.divide(plotdata.sum()/100.0, axis="columns").round(2).fillna(0).sort_values(("Devengado", 2004), ascending= False).head(20)

 

 

Out[533]:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  Devengado
Year 2004.0 2005.0 2006.0 2007.0 2008.0 2009.0 2010.0 2011.0 2012.0 2013.0 2014.0 2015.0 2016.0 2017.0 2018.0 2019.0 2020.0
ActOb                                  
ACTIVIDADES DE DESARROLLO URBANO Y RURAL 23.24 26.24 26.13 24.07 25.49 25.32 26.10 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
ACTIVIDADES DE TRABAJO Y PREVISION SOCIAL 21.79 21.17 21.92 21.48 19.39 20.79 20.51 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
ACTIVIDADES JUDICIALES 12.72 11.96 11.39 10.26 12.41 11.80 11.20 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
ACTIVIDADES DE ADMINISTRACION FISCAL 6.59 6.66 7.24 7.20 6.71 6.09 6.06 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
ACTIVIDADES DE EDUCACION 6.14 7.15 6.91 6.70 6.76 6.93 6.31 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
AGENDA DE PAZ Y RECONCILIACION 4.34 0.00 0.00 0.00 0.00 0.00 0.00 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
CAMINOS VECINALES 3.18 3.15 4.89 4.02 4.10 4.62 4.58 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
AGUA Y SANEAMIENTO AMBIENTAL 2.98 2.80 2.67 1.55 1.93 2.12 2.31 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
ACTIVIDADES LEGISLATIVAS -CONGRESO DE LA REPUBLICA- 2.71 2.56 2.32 2.40 2.05 2.37 2.63 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
ACTIVIDADES DE CULTURA Y DEPORTES 2.36 2.34 2.31 2.18 2.05 2.06 1.97 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
FONDO FIDUCIARIO DE CAPITALIZACION BANCARIA, AJUSTE AL SECTOR FINANCIERO, PRESTAMO BIRF-7130 2.11 0.00 0.00 0.00 0.00 0.00 0.00 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
FONDO PARA LA PROTECCION DEL AHORRO, AJUSTE AL SECTOR FINANCIERO, PRESTAMO BIRF-7130 2.11 0.00 0.00 0.00 0.00 0.00 0.00 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
CONSTRUCCIONES ESCOLARES 1.41 1.59 1.26 1.18 1.34 1.52 1.48 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
ACTIVIDADES DE MEDIO AMBIENTE 1.15 1.02 1.06 1.24 1.13 1.10 0.80 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
ACTIVIDADES DE SERVICIOS GENERALES 0.71 0.90 0.80 0.72 0.88 0.77 0.78 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
ACTIVIDADES DE TURISMO 0.68 0.64 0.57 0.58 0.50 0.50 0.46 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
ACTIVIDADES DE SEGURIDAD INTERNA 0.61 0.65 0.53 0.94 1.17 0.99 0.80 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
ACTIVIDADES DE TRANSPORTE 0.59 1.27 1.37 1.58 2.30 2.34 1.16 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
OBRAS MUNICIPALES 0.58 0.43 0.98 1.14 0.81 1.69 2.33 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
ACTIVIDADES LEGISLATIVAS -PROCURADURIA DERECHOS HUMANOS- 0.50 0.63 0.56 0.58 0.73 0.67 0.62 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
 

Hay varias cosas que resaltar de esto. Ver por ejemplo los costos de el fideicomiso para el transporte público, los gastos del RENAP, SAT (administración fiscal), congreso (admin/actividades legislativas) o el sistema de justicia.

In [618]:
defensa = datos[datos.CodEntidad.apply(lambda x: "defensa" in x.lower())]

 

 

Buscando las actividades del ejército que tengan que ver con la presencia de militares en las calles

In [585]:
temp = defensa[defensa.ActOb.apply(lambda x: "CIUDADANA" in x or "SEGURIDAD P" in x\
                                         or "ESTADO DE SITIO" in x) | \
                      defensa.Programa.apply(lambda x: "DELI" in x or "HOMICIDIO" in x)
                     ][["Programa", "ActOb", "Year", "Devengado"]]
for i, row in temp.sort_values("Year").iterrows():
    print(str(row.Year) + "\n\tProg:" + row.Programa + "\n\tAct:" + row.ActOb + "\n\t\t\tQ " + str(round(row.Devengado/1e6,2))+ " M")

 

 

 
2009.0
	Prog:INDEPENDENCIA SOBERANIA E INTEGRIDAD DEL TERRITORIO
	Act:CUERPO DE SEGURIDAD CIUDADANA
			Q 103.73 M
2010.0
	Prog:INDEPENDENCIA SOBERANIA E INTEGRIDAD DEL TERRITORIO
	Act:CUERPO DE SEGURIDAD CIUDADANA
			Q 109.44 M
2011.0
	Prog:COOPERACION INTEGRAL
	Act:APOYO DE SEGURIDAD CIUDADANA
			Q 110.54 M
2012.0
	Prog:COOPERACIÓN INTERINSTITUCIONAL Y REGIONAL
	Act:APOYO DE SEGURIDAD CIUDADANA
			Q 133.52 M
2013.0
	Prog:PREVENCION DE HECHOS DELICTIVOS CONTRA EL PATRIMONIO
	Act:APOYO DE SEGURIDAD CIUDADANA
			Q 210.45 M
2013.0
	Prog:PREVENCION DE HECHOS DELICTIVOS CONTRA EL PATRIMONIO
	Act:APOYO A LAS FUERZAS DE SEGURIDAD PUBLICA
			Q 63.82 M
2014.0
	Prog:PREVENCION DE HECHOS DELICTIVOS CONTRA EL PATRIMONIO
	Act:APOYO DE SEGURIDAD CIUDADANA
			Q 193.42 M
2014.0
	Prog:PREVENCION DE HECHOS DELICTIVOS CONTRA EL PATRIMONIO
	Act:APOYO A LAS FUERZAS DE SEGURIDAD PUBLICA
			Q 66.11 M
2015.0
	Prog:PREVENCIÓN DE HECHOS DELICTIVOS CONTRA EL PATRIMONIO
	Act:APOYO DE SEGURIDAD CIUDADANA
			Q 191.66 M
2015.0
	Prog:PREVENCIÓN DE HECHOS DELICTIVOS CONTRA EL PATRIMONIO
	Act:APOYO A LAS FUERZAS DE SEGURIDAD PÚBLICA
			Q 68.23 M
2016.0
	Prog:PREVENCIÓN DE HECHOS DELICTIVOS CONTRA EL PATRIMONIO
	Act:APOYO A LAS FUERZAS DE SEGURIDAD PÚBLICA
			Q 72.07 M
2016.0
	Prog:PREVENCIÓN DE HECHOS DELICTIVOS CONTRA EL PATRIMONIO
	Act:APOYO DE SEGURIDAD CIUDADANA
			Q 201.03 M
2017.0
	Prog:PREVENCIÓN DE HECHOS DELICTIVOS CONTRA EL PATRIMONIO
	Act:APOYO DE SEGURIDAD CIUDADANA
			Q 199.28 M
2017.0
	Prog:PREVENCIÓN DE HECHOS DELICTIVOS CONTRA EL PATRIMONIO
	Act:APOYO A LAS FUERZAS DE SEGURIDAD PÚBLICA
			Q 75.37 M
2017.0
	Prog:ATENCIÓN POR DESASTRES NATURALES Y CALAMIDADES PÚBLICAS
	Act:SERVICIOS DE APOYO POR ESTADO DE SITIO
			Q 2.1 M
2017.0
	Prog:APOYO A LA REDUCCIÓN DEL ÍNDICE DE HOMICIDIOS
	Act:REGISTRO Y CONTROL DE ARMAS Y MUNICIONES
			Q 18.11 M
2017.0
	Prog:APOYO A LA REDUCCIÓN DEL ÍNDICE DE HOMICIDIOS
	Act:DIRECCIÓN Y COORDINACIÓN
			Q 7.36 M
2018.0
	Prog:PREVENCIÓN DE HECHOS DELICTIVOS CONTRA EL PATRIMONIO
	Act:APOYO DE SEGURIDAD CIUDADANA
			Q 175.3 M
2018.0
	Prog:PREVENCIÓN DE HECHOS DELICTIVOS CONTRA EL PATRIMONIO
	Act:APOYO A LAS FUERZAS DE SEGURIDAD PÚBLICA
			Q 41.76 M
2018.0
	Prog:APOYO A LA REDUCCIÓN DEL ÍNDICE DE HOMICIDIOS
	Act:DIRECCIÓN Y COORDINACIÓN
			Q 9.4 M
2018.0
	Prog:PREVENCIÓN DE HECHOS DELICTIVOS CONTRA EL PATRIMONIO
	Act:APOYO INTERINSTITUCIONAL
			Q 9.1 M
2018.0
	Prog:ATENCIÓN POR DESASTRES NATURALES Y CALAMIDADES PÚBLICAS
	Act:SERVICIOS DE APOYO POR ESTADO DE SITIO
			Q 0.0 M
2018.0
	Prog:APOYO A LA REDUCCIÓN DEL ÍNDICE DE HOMICIDIOS
	Act:REGISTRO Y CONTROL DE ARMAS Y MUNICIONES
			Q 26.45 M
2019.0
	Prog:PREVENCIÓN DE HECHOS DELICTIVOS CONTRA EL PATRIMONIO
	Act:APOYO INTERINSTITUCIONAL
			Q 21.51 M
2019.0
	Prog:PREVENCIÓN DE HECHOS DELICTIVOS CONTRA EL PATRIMONIO
	Act:PROTECCIÓN DE ÁREAS DE VALOR ESTRATÉGICO
			Q 54.49 M
2019.0
	Prog:ATENCIÓN POR DESASTRES NATURALES Y CALAMIDADES PÚBLICAS
	Act:INTERVENCIONES REALIZADAS POR ESTADO DE SITIO
			Q 0.0 M
2020.0
	Prog:PREVENCIÓN DE HECHOS DELICTIVOS CONTRA EL PATRIMONIO
	Act:APOYO INTERINSTITUCIONAL
			Q 19.03 M
2020.0
	Prog:PREVENCIÓN DE HECHOS DELICTIVOS CONTRA EL PATRIMONIO
	Act:PROTECCIÓN DE ÁREAS DE VALOR ESTRATÉGICO
			Q 50.88 M
 

Estimado de gasto por presencia del ejército en las calles según Programa y Actividad del presupuesto

In [639]:
(temp.groupby("Year").Devengado.sum() / 1e6).round(2).plot()
plt.ylabel("Millones de Quetzales")
plt.xlabel("Año")

 

 

Out[639]:
Text(0.5, 0, 'Año')

 

 
In [640]:
defensa["Programa"] = defensa["Programa"].apply(remove_accents)

 

 

 
<ipython-input-640-dc1fd43d416d>:1: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  defensa["Programa"] = defensa["Programa"].apply(remove_accents)
 

Porcentaje de gasto del ejército por programa por año

In [641]:
campo = "Devengado"
grupo = "Programa"
altair.Chart.from_dict(
{
  "$schema": "https://vega.github.io/schema/vega-lite/v4.json",
  "description": "Chart",
  "data": {
      "values":  defensa.groupby(["Year",grupo])[campo].sum().reset_index().to_dict("records")
  },
    "layer":[
        {
          "mark": {"type": "bar", "tooltip": True},
          "encoding": {
            "order":  {"field": campo, "type": "quantitative", "sort":"descending"
            },
            "y": {
              "field": campo,
              "type": "quantitative",
                "stack": "normalize",
                "axis": {"format": "%", "title": campo}
            },
            "x": {"field": "Year", "type": "nominal"},
            "color": {
              "field": grupo,
                "type": "nominal",
              "scale": {"scheme": "category20b"}
            },
            "tooltip": [
              {"field": campo, "type": "quantitative", "title": campo, "format": ".2s"},
              {"field": grupo, "type": "nominal", "title": grupo},
            ],

          }
        }
    ],
  "width": 600
})

 

 

Out[641]:
 

In [ ]: