In [24]:
%matplotlib inline
In [25]:
import datetime
In [26]:
import pandas as pd
In [ ]:
In [27]:
councilman = pd.read_csv('../data/sequential_id.csv')
secreataries = pd.read_csv('../data/secretary-councilman.csv')
# sequencial dos vereadores de são paulo
sequencial = councilman.sequential_id.tolist()
sequencial.extend(secreataries.sequential_id.tolist())
In [ ]:
In [28]:
df = pd.read_csv(
'/home/flavio/Downloads/votacao_candidato_munzona_2016/votacao_candidato_munzona_2016_SP.txt',
encoding='iso-8859-1', sep=';', decimal=',', thousands='.',
dtype={'NOME_MUNICIPIO': str, 'NOME_PARTIDO': str},
names=['DATA_GERACAO', 'HORA_GERACAO', 'ANO_ELEICAO', 'NUM_TURNO','DESCRICAO_ELEICAO',
'SIGLA_UF', 'SIGLA_UE', 'CODIGO_MUNICIPIO', 'NOME_MUNICIPIO', 'NUMERO_ZONA',
'CODIGO_CARGO', 'NUMERO_CAND', 'sequential_id', 'NOME_CANDIDATO',
'NOME_URNA_CANDIDATO', 'DESCRICAO_CARGO', 'COD_SIT_CAND_SUPERIOR',
'DESC_SIT_CAND_SUPERIOR', 'CODIGO_SIT_CANDIDATO', 'DESC_SIT_CANDIDATO',
'COD_SIT_CAND_TOT', 'DESC_SIT_CAND_TOT', 'NUMERO_PARTIDO', 'SIGLA_PARTIDO', 'NOME_PARTIDO',
'SEQUENCIAL_LEGENDA', 'NOME_COLIGACAO', 'COMPOSICAO_LEGENDA', 'TOTAL_VOTOS', 'TRANSITO'],
usecols=['CODIGO_MUNICIPIO', 'NOME_CANDIDATO', 'sequential_id',
'DESCRICAO_CARGO', 'DESC_SIT_CAND_TOT', 'TOTAL_VOTOS']
)
In [29]:
df = df[df['sequential_id'].isin(sequencial)]
In [30]:
votes = df.groupby('sequential_id')['TOTAL_VOTOS'].sum().reset_index()
votes = votes.sort_values(by="TOTAL_VOTOS", ascending=False)
votes.columns
Out[30]:
In [31]:
votes = votes.rename(columns={'TOTAL_VOTOS': 'votes'})
In [33]:
votes['election_year'] = 2016
In [ ]:
In [34]:
today = datetime.date.today()
votes.to_csv(f"../data/{today}-votes.csv", index=False)
In [ ]: