Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

Estimativa de efetivo para PMMT nas eleições de 2018

Project: Pesquisa
Views: 2364
Kernel: Python 3 (Ubuntu Linux)
import pandas as pd from sklearn.cluster import KMeans import numpy as np
locais = pd.read_excel('Planilha para distribuicao do efetivo.xlsx', sheet_name='dados') locais[:5]
longitude latitude cod_localidade_tse nom_localidade nom_bairro num_local nom_local des_endereco codigo lqtd_secoes lqtd_aptos indigenas grupos efetivo crimes_eleitorais boca_de_urna roubo furto desacato desobediencia
0 -56.124416 -15.280069 90670 CUIABÁ AGUAÇU 2470 ESCOLA MUNICIPAL UDENEY GONÇALVES DE AMORIM RUA PRINCIPAL, SN 1906702470 3 925 0 3 1.0 0 0 0 2 1 1
1 -56.019846 -15.544380 90670 CUIABÁ ALTOS DA GLÓRIA 1210 ESCOLA MUNICIPAL PROFESSORA GRACILDES MELO DANTAS RUA QUINZE QUADRA 60 S/N 51906701210 5 1945 0 0 2.0 0 0 4 17 0 1
2 -56.024079 -15.579122 90670 CUIABÁ ALTOS DA SERRA 2100 E. M. CELINA FIALHO BEZERRA RUA PRINCESA DAYANE, S/N 39906702100 9 3513 0 0 2.0 0 0 16 29 1 1
3 -56.024712 -15.635798 90670 CUIABÁ ALTOS DO COXIPÓ 1473 CCI - CENTRO DE CONVIVÊNCIA DO IDOSO JOÃO GUER... RUA 01, S/N 55906701473 2 611 0 0 0.6 0 0 0 0 0 0
4 -56.081131 -15.579708 90670 CUIABÁ ALVORADA 2488 ESCOLA MUNICIPAL CÂNDIDO MARIANO DA SILVA RONDON RUA PIRATININGA, 101 1906702488 12 4571 0 0 2.0 0 0 34 64 2 3
# Crimes eleitorais obteve muito baixa distribuicao, com valores iguais a 0 (maioria), 1 (14), 2 (2) e 3 (1)
aux = 'c_boca_de_urna' aux1 = 'boca_de_urna' kmeans = KMeans(n_clusters=5, random_state=0).fit(locais[aux1].values.reshape(-1,1)) locais[aux] = kmeans.labels_ locais[[aux, aux1]].groupby([aux]).describe()
boca_de_urna
count mean std min 25% 50% 75% max
c_boca_de_urna
0 1362.0 0.0 0.000000 0.0 0.00 0.0 0.00 0.0
1 28.0 2.0 0.000000 2.0 2.00 2.0 2.00 2.0
2 80.0 1.0 0.000000 1.0 1.00 1.0 1.00 1.0
3 2.0 4.5 0.707107 4.0 4.25 4.5 4.75 5.0
4 6.0 3.0 0.000000 3.0 3.00 3.0 3.00 3.0
locais[aux1].hist()
<matplotlib.axes._subplots.AxesSubplot at 0x7f4072872ba8>
Image in a Jupyter notebook
aux = 'c_indigenas' aux1 = 'indigenas' kmeans = KMeans(n_clusters=5, random_state=0).fit(locais[aux1].values.reshape(-1,1)) locais[aux] = kmeans.labels_ locais[[aux, aux1]].groupby([aux]).describe()
indigenas
count mean std min 25% 50% 75% max
c_indigenas
0 1443.0 0.167706 3.191030 0.0 0.00 0.0 0.0 71.0
1 12.0 355.500000 64.281342 267.0 306.25 363.0 392.0 479.0
2 17.0 167.470588 48.687932 95.0 122.00 158.0 215.0 242.0
3 5.0 603.600000 56.906063 544.0 586.00 591.0 599.0 698.0
4 1.0 921.000000 NaN 921.0 921.00 921.0 921.0 921.0
locais[aux1].hist()
<matplotlib.axes._subplots.AxesSubplot at 0x7f4072b00c50>
Image in a Jupyter notebook
aux = 'c_lqtd_aptos' aux1 = 'lqtd_aptos' kmeans = KMeans(n_clusters=5, random_state=0).fit(locais[aux1].values.reshape(-1,1)) locais[aux] = kmeans.labels_ locais[[aux, aux1]].groupby([aux]).describe()
lqtd_aptos
count mean std min 25% 50% 75% max
c_lqtd_aptos
0 570.0 360.615789 195.368108 3.0 200.25 335.0 503.75 784.0
1 91.0 4829.219780 755.592862 4073.0 4316.00 4569.0 5106.50 8300.0
2 272.0 2120.143382 291.995333 1665.0 1876.75 2074.0 2362.25 2687.0
3 211.0 3259.241706 376.906081 2700.0 2930.50 3197.0 3547.00 4004.0
4 334.0 1210.173653 244.468695 794.0 997.25 1201.0 1402.50 1654.0
locais[aux1].hist()
<matplotlib.axes._subplots.AxesSubplot at 0x7f40729e64e0>
Image in a Jupyter notebook
aux = 'c_roubo' aux1 = 'roubo' kmeans = KMeans(n_clusters=5, random_state=0).fit(locais[aux1].values.reshape(-1,1)) locais[aux] = kmeans.labels_ locais[[aux, aux1]].groupby([aux]).describe()
roubo
count mean std min 25% 50% 75% max
c_roubo
0 1304.0 0.643405 1.363707 0.0 0.0 0.0 1.0 6.0
1 2.0 181.000000 14.142136 171.0 176.0 181.0 186.0 191.0
2 39.0 35.282051 8.404099 24.0 29.0 33.0 42.5 52.0
3 9.0 73.444444 12.238373 58.0 65.0 71.0 82.0 96.0
4 124.0 12.177419 4.433884 7.0 8.0 11.0 15.0 23.0
locais[aux1].hist()
<matplotlib.axes._subplots.AxesSubplot at 0x7f40727c1cf8>
Image in a Jupyter notebook
aux = 'c_furto' aux1 = 'furto' kmeans = KMeans(n_clusters=5, random_state=0).fit(locais[aux1].values.reshape(-1,1)) locais[aux] = kmeans.labels_ locais[[aux, aux1]].groupby([aux]).describe()
furto
count mean std min 25% 50% 75% max
c_furto
0 1200.0 1.187500 2.081495 0.0 0.00 0.0 2.00 8.0
1 13.0 119.461538 30.269939 88.0 94.00 112.0 127.00 187.0
2 56.0 44.892857 12.132119 31.0 35.75 42.5 50.25 80.0
3 2.0 308.500000 16.263456 297.0 302.75 308.5 314.25 320.0
4 207.0 15.821256 6.127444 9.0 11.00 14.0 20.50 29.0
locais[aux1].hist()
<matplotlib.axes._subplots.AxesSubplot at 0x7f40727559b0>
Image in a Jupyter notebook
aux = 'c_desacato' aux1 = 'desacato' kmeans = KMeans(n_clusters=5, random_state=0).fit(locais[aux1].values.reshape(-1,1)) locais[aux] = kmeans.labels_ locais[[aux, aux1]].groupby([aux]).describe()
desacato
count mean std min 25% 50% 75% max
c_desacato
0 1232.0 0.000000 0.000000 0.0 0.0 0.0 0.0 0.0
1 36.0 3.361111 0.487136 3.0 3.0 3.0 4.0 4.0
2 126.0 1.000000 0.000000 1.0 1.0 1.0 1.0 1.0
3 12.0 6.000000 1.414214 5.0 5.0 6.0 6.0 10.0
4 72.0 2.000000 0.000000 2.0 2.0 2.0 2.0 2.0
locais[aux1].hist()
<matplotlib.axes._subplots.AxesSubplot at 0x7f40727c19b0>
Image in a Jupyter notebook
aux = 'c_desobediencia' aux1 = 'desobediencia' kmeans = KMeans(n_clusters=5, random_state=0).fit(locais[aux1].values.reshape(-1,1)) locais[aux] = kmeans.labels_ locais[[aux, aux1]].groupby([aux]).describe()
desobediencia
count mean std min 25% 50% 75% max
c_desobediencia
0 186.0 1.263441 0.441688 1.0 1.0 1.0 2.0 2.0
1 1227.0 0.000000 0.000000 0.0 0.0 0.0 0.0 0.0
2 2.0 22.000000 4.242641 19.0 20.5 22.0 23.5 25.0
3 17.0 6.000000 1.322876 5.0 5.0 5.0 7.0 9.0
4 46.0 3.239130 0.431266 3.0 3.0 3.0 3.0 4.0
locais[aux1].hist()
<matplotlib.axes._subplots.AxesSubplot at 0x7f40729e64e0>
Image in a Jupyter notebook