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 (Anaconda 5)
import os import folium import pandas as pd print(folium.__version__)
0.6.0
df = pd.read_excel('res2.xlsx', sheet_name='dados')
df.head()
longitude latitude COD_LOCALIDADE_TSE NOM_LOCALIDADE_1 NOM_BAIRRO NUM_LOCAL NOM_LOCAL DES_ENDERECO CODIGO LQTD_SECOES LQTD_APTOS INDIGENAS CV GRUPOS EFETIVO
0 -56.104889 -15.589418 90670 CUIABÁ QUILOMBO 2593 COLÉGIO MAXI RUA ESTEVÃO DE MENDONÇA, 1000 1906702593 16 6309 0 0 0 2.0
1 -56.098308 -15.592559 90670 CUIABÁ CENTRO 1015 INSTITUTO FEDERAL DE EDUCAÇÃO, CIÊNCIA E TECNO... RUA ZULMIRA CANAVARROS, 95 1906701015 24 4916 0 0 0 2.0
2 -56.081131 -15.579708 90670 CUIABÁ ALVORADA 2488 ESCOLA MUNICIPAL CÂNDIDO MARIANO DA SILVA RONDON RUA PIRATININGA, 101 1906702488 12 4571 0 100 1 2.0
3 -56.113951 -15.613200 90670 CUIABÁ PORTO 2844 ESCOLA ESTADUAL JOSÉ BARNABÉ DE MESQUITA RUA BARÃO DE MELGACO, 945 1906702844 13 4471 0 100 2 2.0
4 -56.128743 -15.618736 90670 CUIABÁ COOPHAMIL 2810 ESCOLA MUNICIPAL DE EDUCAÇÃO BÁSICA PROFESSOR ... RUA JOÃO PAULO DOS SANTOS, S/N 1906702810 12 4308 0 0 3 2.0
grupos = df.groupby('GRUPOS')['latitude', 'longitude'].mean()
grupos.head()
latitude longitude
GRUPOS
0 -15.600311 -56.098059
1 -15.588466 -56.082202
2 -15.613143 -56.114460
3 -15.614556 -56.131003
4 -15.595474 -56.118742
grupos2 = df.groupby('GRUPOS')['EFETIVO'].sum()
grupos2.head()
GRUPOS 0 38.653002 1 12.000000 2 3.000000 3 6.000000 4 2.000000 Name: EFETIVO, dtype: float64
grupos = pd.concat([grupos, grupos2], axis=1) grupos.head()
latitude longitude EFETIVO
GRUPOS
0 -15.600311 -56.098059 38.653002
1 -15.588466 -56.082202 12.000000
2 -15.613143 -56.114460 3.000000
3 -15.614556 -56.131003 6.000000
4 -15.595474 -56.118742 2.000000
grupos = grupos.reset_index() grupos.head()
GRUPOS latitude longitude EFETIVO
0 0 -15.600311 -56.098059 38.653002
1 1 -15.588466 -56.082202 12.000000
2 2 -15.613143 -56.114460 3.000000
3 3 -15.614556 -56.131003 6.000000
4 4 -15.595474 -56.118742 2.000000
from folium.plugins import MarkerCluster m = folium.Map(location=[-15.6, -56.1], zoom_start=7)
def cor(efetivo): if efetivo < 10: return('lightgray') elif efetivo < 25: return('orange') else: return('red')
grupos.index[1]
1
print("{:03.0f}, Efetivo: {:05.1f}".format(grupos.index[0], grupos.EFETIVO[0]))
000, Efetivo: 038.7
marker_cluster = MarkerCluster().add_to(m) def ad_local(coord): # print(coord) folium.Marker(location=coord[['latitude', 'longitude', 'EFETIVO']], popup="Grupo: {:03.0f}, Efetivo: {:05.1f}".format(coord.GRUPOS, coord.EFETIVO), icon=folium.Icon(color=cor(coord.EFETIVO)), ).add_to(marker_cluster)
grupos.apply(ad_local, axis = 1)
0 None 1 None 2 None 3 None 4 None 5 None 6 None 7 None 8 None 9 None 10 None 11 None 12 None 13 None 14 None 15 None 16 None 17 None 18 None 19 None 20 None 21 None 22 None 23 None 24 None 25 None 26 None 27 None 28 None 29 None ... 670 None 671 None 672 None 673 None 674 None 675 None 676 None 677 None 678 None 679 None 680 None 681 None 682 None 683 None 684 None 685 None 686 None 687 None 688 None 689 None 690 None 691 None 692 None 693 None 694 None 695 None 696 None 697 None 698 None 699 None Length: 700, dtype: object
heat_data = [[row['latitude'],row['longitude'], row['EFETIVO']] for index, row in grupos.iterrows()]
grupos['EFETIVO'].max()
38.653002126533636
from folium.plugins import HeatMap # https://python-visualization.github.io/folium/plugins.html HeatMap(heat_data, min_opacity=0.2, max_val=grupos['EFETIVO'].max(), max_zoom=1, radius=30, blur=15, gradient={0: 'grey', 1: 'red'}).add_to(m)
<folium.plugins.heat_map.HeatMap at 0x7f455b3846d8>
m.save('Mapa_de_zona_quente.html')