-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelecciones.py
26 lines (21 loc) · 880 Bytes
/
elecciones.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import openpyxl
import csv
class Elecciones():
documento = openpyxl.load_workbook('Elecciones.xlsx')
hoja = documento.get_sheet_by_name('Hoja1') # Un doc de excel tiene varias hojas..
def agrupar(self, criterio, paramSearch):
count = 0
for fila in self.hoja.rows:
for columna in fila:
if paramSearch in str(columna.value):
count += 1
with open('{}.csv'.format(criterio), 'w') as csvfile:
filewriter = csv.writer(csvfile, delimiter=',')
filewriter.writerow([criterio, 'Count'])
filewriter.writerow([paramSearch, count])
elecciones = Elecciones()
elecciones.agrupar('Candidato', 'Juan Perez')
elecciones.agrupar('Partido', 'liberal')
elecciones.agrupar('Puesto', '2')
elecciones.agrupar('Municipio', 'Cali')
elecciones.agrupar('Departamento', 'Antioquia')