ADJUDICACIONES MECO (Análisis descriptivo de datos)¶

GENERAL (adjudicaciones en general)

En el 2020 hubo un aumento significativo de adjudicaciones

In [ ]:
import pandas as pd 
import numpy as np 
import matplotlib.pyplot as plt 
import seaborn as sns
from fbprophet import Prophet
In [ ]:
# dataframes creation for both training and testing datasets 

adjudicaciones_df = pd.read_excel("adjudicaciones_meco_limpio.xlsx")
In [ ]:
adjudicaciones_df.head()
Out[ ]:
procedimiento institucion partida descripcion monto adjudicacion Unnamed: 6 anio
0 2021CD-000061-0022200208 Municipalidad de Poás 1 Adquisición de lastre para relleno de muro 1940000.00 01/06/2021 NaN 2021
1 2021CD-000020-0015900001 MUNICIPALIDAD DE SAN RAMON 2 COMPRA DE AGREGADOS 6299.98 10/06/2021 NaN 2021
2 2021CD-000020-0015900001 MUNICIPALIDAD DE SAN RAMON 7 COMPRA DE AGREGADOS 9499.97 10/06/2021 NaN 2021
3 2021PI-000100-0006500001 COMISION NACIONAL DE PREVENCION DE RIESGOS Y A... 1 Alquiler de maquinaria pesada para atender eme... 17345500.00 28/05/2021 NaN 2021
4 2021CD-000036-0032000702 Municipalidad de Pococí 1 Mejoramiento Red Vial Asfaltada, Colocación de... 31967682.05 16/06/2021 NaN 2021
In [ ]:
adjudicaciones_df = adjudicaciones_df.sort_values("adjudicacion")
In [ ]:
plt.figure(figsize=(10,10))
plt.plot(adjudicaciones_df['adjudicacion'], adjudicaciones_df['monto'])
INFO:matplotlib.category:Using categorical units to plot a list of strings that are all parsable as floats or dates. If these strings should be plotted as numbers, cast to the appropriate data type before plotting.
INFO:matplotlib.category:Using categorical units to plot a list of strings that are all parsable as floats or dates. If these strings should be plotted as numbers, cast to the appropriate data type before plotting.
Out[ ]:
[<matplotlib.lines.Line2D at 0x7fd1e3ab8550>]
In [ ]:
plt.figure(figsize=[25,12])
sns.countplot(x = 'institucion', data = adjudicaciones_df)
plt.xticks(rotation = 90)
Out[ ]:
(array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16,
        17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
        34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50]),
 <a list of 51 Text major ticklabel objects>)
In [ ]:
plt.figure(figsize=[25,12])
sns.countplot(x = 'anio', data = adjudicaciones_df)
plt.xticks(rotation = 45)
Out[ ]:
(array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10]),
 <a list of 11 Text major ticklabel objects>)
In [ ]:
adjudicaciones_prophet_df = adjudicaciones_df[['adjudicacion', 'monto']]
In [ ]:
adjudicaciones_prophet_df = adjudicaciones_prophet_df.rename(columns={'adjudicacion':'ds', 'monto':'y'})
In [ ]:
adjudicaciones_prophet_df
Out[ ]:
ds y
306 01/02/2016 4.983300e+06
26 01/02/2021 1.499789e+08
0 01/06/2021 1.940000e+06
8 01/06/2021 1.360000e+04
344 01/08/2013 9.655537e+07
... ... ...
114 30/04/2020 3.540260e+05
115 30/07/2020 1.683563e+08
217 30/11/2018 2.139795e+07
291 31/10/2017 6.377835e+08
222 31/10/2018 2.905975e+07

355 rows × 2 columns

In [ ]:
m = Prophet()
m.fit(adjudicaciones_prophet_df)
INFO:fbprophet:Disabling daily seasonality. Run prophet with daily_seasonality=True to override this.
Out[ ]:
<fbprophet.forecaster.Prophet at 0x7fd1e397c090>
In [ ]:
future = m.make_future_dataframe(periods=365)
forecast = m.predict(future)
In [ ]:
forecast
Out[ ]:
ds trend yhat_lower yhat_upper trend_lower trend_upper additive_terms additive_terms_lower additive_terms_upper weekly weekly_lower weekly_upper yearly yearly_lower yearly_upper multiplicative_terms multiplicative_terms_lower multiplicative_terms_upper yhat
0 2011-08-17 2.394295e+07 -5.530689e+08 5.330339e+08 2.394295e+07 2.394295e+07 -4.747581e+07 -4.747581e+07 -4.747581e+07 -2.100193e+07 -2.100193e+07 -2.100193e+07 -2.647388e+07 -2.647388e+07 -2.647388e+07 0.0 0.0 0.0 -2.353286e+07
1 2012-03-20 3.511698e+07 -5.522530e+08 4.747002e+08 3.511698e+07 3.511698e+07 -4.783039e+07 -4.783039e+07 -4.783039e+07 3.068841e+07 3.068841e+07 3.068841e+07 -7.851880e+07 -7.851880e+07 -7.851880e+07 0.0 0.0 0.0 -1.271341e+07
2 2012-06-09 3.930725e+07 -4.516176e+08 6.513424e+08 3.930725e+07 3.930725e+07 6.126394e+07 6.126394e+07 6.126394e+07 -3.725452e+07 -3.725452e+07 -3.725452e+07 9.851846e+07 9.851846e+07 9.851846e+07 0.0 0.0 0.0 1.005712e+08
3 2012-07-19 4.137651e+07 -2.525145e+08 8.003239e+08 4.137651e+07 4.137651e+07 2.230944e+08 2.230944e+08 2.230944e+08 8.408596e+06 8.408596e+06 8.408596e+06 2.146858e+08 2.146858e+08 2.146858e+08 0.0 0.0 0.0 2.644709e+08
4 2012-10-09 4.561851e+07 -5.836115e+08 4.974932e+08 4.561851e+07 4.561851e+07 -8.383000e+07 -8.383000e+07 -8.383000e+07 3.068841e+07 3.068841e+07 3.068841e+07 -1.145184e+08 -1.145184e+08 -1.145184e+08 0.0 0.0 0.0 -3.821149e+07
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
613 2022-12-01 2.372516e+08 -3.803552e+08 6.785709e+08 2.372513e+08 2.372519e+08 -9.965049e+07 -9.965049e+07 -9.965049e+07 8.408596e+06 8.408596e+06 8.408596e+06 -1.080591e+08 -1.080591e+08 -1.080591e+08 0.0 0.0 0.0 1.376011e+08
614 2022-12-02 2.373033e+08 -4.346907e+08 6.796258e+08 2.373030e+08 2.373036e+08 -1.371357e+08 -1.371357e+08 -1.371357e+08 -3.427511e+07 -3.427511e+07 -3.427511e+07 -1.028606e+08 -1.028606e+08 -1.028606e+08 0.0 0.0 0.0 1.001676e+08
615 2022-12-03 2.373550e+08 -4.162714e+08 6.812517e+08 2.373547e+08 2.373554e+08 -1.343184e+08 -1.343184e+08 -1.343184e+08 -3.725452e+07 -3.725452e+07 -3.725452e+07 -9.706389e+07 -9.706389e+07 -9.706389e+07 0.0 0.0 0.0 1.030366e+08
616 2022-12-04 2.374067e+08 -4.225254e+08 6.499276e+08 2.374064e+08 2.374071e+08 -1.280939e+08 -1.280939e+08 -1.280939e+08 -3.713675e+07 -3.713675e+07 -3.713675e+07 -9.095711e+07 -9.095711e+07 -9.095711e+07 0.0 0.0 0.0 1.093129e+08
617 2022-12-05 2.374585e+08 -2.730131e+08 7.775324e+08 2.374581e+08 2.374588e+08 5.729541e+06 5.729541e+06 5.729541e+06 9.057130e+07 9.057130e+07 9.057130e+07 -8.484176e+07 -8.484176e+07 -8.484176e+07 0.0 0.0 0.0 2.431880e+08

618 rows × 19 columns

In [ ]:
figure = m.plot(forecast, xlabel='año', ylabel='adjudicación')

Municipalidades

In [ ]:
adjudicaciones_munis_df=adjudicaciones_df
adjudicaciones_munis_df['institucion'] = adjudicaciones_munis_df['institucion'].str.lower()
adjudicaciones_munis_df = adjudicaciones_df[adjudicaciones_df['institucion'].str.contains("municipalidad")]
In [ ]:
adjudicaciones_munis_df
Out[ ]:
procedimiento institucion partida descripcion monto adjudicacion Unnamed: 6 anio
306 2015LA-000012-0005500001 municipalidad de atenas 1 COLOCACION DE ASFALTO EN LAS INSTALACIONES DEL... 4.983300e+06 01/02/2016 NaN 2016
26 2021LA-000001-0032000702 municipalidad de pococí 1 Compra de mezcla asfáltica 1.499789e+08 01/02/2021 NaN 2021
0 2021CD-000061-0022200208 municipalidad de poás 1 Adquisición de lastre para relleno de muro 1.940000e+06 01/06/2021 NaN 2021
8 2021LA-000010-0000500001 municipalidad de alajuela 1 adquisición de agregados granulares 1.360000e+04 01/06/2021 NaN 2021
344 2013LA-000006-0000700001 municipalidad de grecia 1 MEJORAS EN INFRAESTRUCTURA VIAL CALLE LOMAS 9.655537e+07 01/08/2013 NaN 2013
... ... ... ... ... ... ... ... ...
77 2020LA-000003-0028202161 municipalidad de río cuarto 1 CONTRATACIÓN DE ENTREGA SEGÚN DEMANDA PARA OBR... 2.186157e+06 29/09/2020 NaN 2020
78 2020LA-000002-0028202161 municipalidad de río cuarto 1 CONTRATACIÓN DE ENTREGA SEGÚN DEMANDA PARA OBR... 2.184191e+06 29/09/2020 NaN 2020
79 2020LA-000001-0028202161 municipalidad de río cuarto 1 CONTRATACIÓN DE ENTREGA SEGÚN DEMANDA PARA OBR... 2.183212e+06 29/09/2020 NaN 2020
115 2020LA-000005-0002900001 municipalidad de tarrazú 1 Mejoramiento superficie de ruedo Rodeo-Cedral ... 1.683563e+08 30/07/2020 NaN 2020
217 2018CD-000259-0000500001 municipalidad de alajuela 1 Ampliación y Asfaltado de Calle San Juan, San ... 2.139795e+07 30/11/2018 NaN 2018

223 rows × 8 columns

In [ ]:
adjudicaciones_munis_df = adjudicaciones_munis_df.sort_values("adjudicacion")
In [ ]:
plt.figure(figsize=(10,10))
plt.plot(adjudicaciones_munis_df['adjudicacion'], adjudicaciones_munis_df['monto'])
INFO:matplotlib.category:Using categorical units to plot a list of strings that are all parsable as floats or dates. If these strings should be plotted as numbers, cast to the appropriate data type before plotting.
INFO:matplotlib.category:Using categorical units to plot a list of strings that are all parsable as floats or dates. If these strings should be plotted as numbers, cast to the appropriate data type before plotting.
Out[ ]:
[<matplotlib.lines.Line2D at 0x7fd1e5686e90>]
In [ ]:
plt.figure(figsize=[25,12])
sns.countplot(x = 'institucion', data = adjudicaciones_munis_df)
plt.xticks(rotation = 90)
Out[ ]:
(array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16,
        17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
        34, 35, 36, 37, 38, 39]), <a list of 40 Text major ticklabel objects>)

Participación de adjudicaciones por institución

In [ ]:
plt.figure(figsize=[25,12])
sns.countplot(x = 'anio', data = adjudicaciones_munis_df)
plt.xticks(rotation = 45)
Out[ ]:
(array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10]),
 <a list of 11 Text major ticklabel objects>)
In [ ]:
adjudicaciones_prophet_df = adjudicaciones_munis_df[['adjudicacion', 'monto']]
In [ ]:
adjudicaciones_prophet_df = adjudicaciones_prophet_df.rename(columns={'adjudicacion':'ds', 'monto':'y'})
In [ ]:
m = Prophet()
m.fit(adjudicaciones_prophet_df)
INFO:fbprophet:Disabling daily seasonality. Run prophet with daily_seasonality=True to override this.
Out[ ]:
<fbprophet.forecaster.Prophet at 0x7fd1e335e490>
In [ ]:
future = m.make_future_dataframe(periods=365)
forecast = m.predict(future)
In [ ]:
figure = m.plot(forecast, xlabel='año', ylabel='adjudicación')

Basado en series de tiempo, a grandes rasgos se ubica comportamientos atípicos en el 2020

In [ ]:
figure3 = m.plot_components(forecast)

Municipalidad de Tarrazú

In [ ]:
adjudicaciones_tarrazu_df=adjudicaciones_df
adjudicaciones_tarrazu_df['institucion'] = adjudicaciones_tarrazu_df['institucion'].str.lower()
adjudicaciones_tarrazu_df = adjudicaciones_df[adjudicaciones_df['institucion'].str.contains("tarra")]
In [ ]:
adjudicaciones_tarrazu_df = adjudicaciones_tarrazu_df.sort_values("adjudicacion")
In [ ]:
plt.figure(figsize=(10,10))
plt.plot(adjudicaciones_tarrazu_df['adjudicacion'], adjudicaciones_tarrazu_df['monto'])
INFO:matplotlib.category:Using categorical units to plot a list of strings that are all parsable as floats or dates. If these strings should be plotted as numbers, cast to the appropriate data type before plotting.
INFO:matplotlib.category:Using categorical units to plot a list of strings that are all parsable as floats or dates. If these strings should be plotted as numbers, cast to the appropriate data type before plotting.
Out[ ]:
[<matplotlib.lines.Line2D at 0x7fd1e2f2b450>]
In [ ]:
plt.figure(figsize=[25,12])
sns.countplot(x = 'anio', data = adjudicaciones_tarrazu_df)
plt.xticks(rotation = 90)
Out[ ]:
(array([0, 1, 2, 3, 4]), <a list of 5 Text major ticklabel objects>)
In [ ]:
adjudicaciones_prophet_df = adjudicaciones_tarrazu_df[['adjudicacion', 'monto']]
In [ ]:
adjudicaciones_prophet_df = adjudicaciones_prophet_df.rename(columns={'adjudicacion':'ds', 'monto':'y'})