text_plain_output_1.png
import matplotlib.pyplot as plt # plotting

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import seaborn as sns

df = pd.read_csv('../input/BR_eleitorado_2016_municipio.csv', delimiter=';')

df.shape

corr = df.corr()
plt.figure(num=None, dpi=80, facecolor='w', edgecolor='k')
corrMat = plt.matshow(corr, fignum = 1)
plt.xticks(range(len(corr.columns)), corr.columns, rotation=90)
plt.yticks(range(len(corr.columns)), corr.columns)
plt.gca().xaxis.tick_bottom()
plt.colorbar(corrMat)
plt.title('Correlation Matrix')
plt.show()

df = df.drop(columns=['cod_municipio_tse'])

x = sns.PairGrid(df)
x.map(plt.scatter)

uf = pd.DataFrame(df['uf'].value_counts())

eleitores = df[['uf', 'total_eleitores']].sort_values(by='uf')

eleitores_grpd_by_uf = eleitores.groupby(['uf']).sum()

norte = ['AM', 'RR', 'AP', 'PA', 'TO', 'RO', 'AC']
centroeste = ['MT', 'MS', 'GO']
sudeste = ['SP', 'ES', 'MG', 'RJ']
sul = ['PR', 'RS', 'SC']
nordeste = ['MA', 'PI', 'CE', 'RN', 'PE', 'PB', 'SE', 'AL', 'BA']
df_region = eleitores
df_region['regiao'] = ''
for i, r in df_region.iterrows():
    if r['uf'] in norte:
        df_region.at[i, 'regiao'] = 'Norte'
    elif r['uf'] in centroeste:
        df_region.at[i, 'regiao'] = 'Centro-Oeste'
    elif r['uf'] in sudeste:
        df_region.at[i, 'regiao'] = 'Sudeste'
    elif r['uf'] in sul:
        df_region.at[i, 'regiao'] = 'Sul'
    else:
        df_region.at[i, 'regiao'] = 'Nordeste'

df_region.head()