Last active
September 29, 2020 21:34
-
-
Save gfelitti/fd30daf4beb097ef41d80a78f6cd7eb3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pandas as pd | |
| pd.set_option('display.max_rows', None) | |
| import zipfile | |
| import geopandas as gpd | |
| import matplotlib.pyplot as plt | |
| %matplotlib inline | |
| #abrir shapefile | |
| shape=gpd.read_file('path/shapfile/UFs_Brasil') | |
| #abrir arquivo de candidaturas sem deszipar | |
| zf = zipfile.ZipFile('path/para/consulta_cand_2020.zip') | |
| df = pd.read_csv(zf.open('consulta_cand_2020_BRASIL.csv'), encoding='latin1', sep=';') | |
| def plotar_grafico(df,nome, cor='Greens'): | |
| fig, ax = plt.subplots(1,1, figsize=(20,10)) | |
| ax.set_title(f'Candidatos/as com "{nome}" no nome - Eleição 2020', fontsize=20) | |
| return shape[['sigla','geometry']].merge(df.groupby('SG_UF')['DS_COR_RACA'].count().reset_index(), right_on='SG_UF', left_on='sigla', how='outer').fillna(0)\ | |
| .plot(column='DS_COR_RACA', ax=ax, legend=True, cmap=cor) | |
| candidato=df[df['NM_URNA_CANDIDATO'].str.contains(TERMO_A_BUSCAR, na=False,case=False)][['NM_URNA_CANDIDATO','DS_COMPOSICAO_COLIGACAO','SG_UF','DS_COR_RACA']] | |
| #OPÇÕES DE CMAP -> https://matplotlib.org/tutorials/colors/colormaps.html | |
| plotar_grafico(candidato, "Nome do/a candidato/a", cor=ALGUM_CMAP) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment