-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcuota_genero.py
More file actions
47 lines (37 loc) · 1.19 KB
/
cuota_genero.py
File metadata and controls
47 lines (37 loc) · 1.19 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# -*- coding: utf-8 -*-
import codecs
import glob
import subprocess
'''
Obtiene porcentaje femenino en listas de candidatos.
'''
filename = "hoja.tsv.0"
def make_files():
for line in codecs.open(filename, "r", "utf-8").readlines():
line = line.strip()
line = line.split("\t")
op = "op/" + "op_" + line[5].replace(" ", "_") + ".tsv"
f = codecs.open(op, "a", "utf-8")
if line[11].lower() == "masculino":
f.write(line[5] + "\t" + line[11] + "\n")
if line[11].lower() == "femenino":
f.write(line[5] + "\t" + line[11] + "\n")
f.close()
#make_files()
print "ORG POLITICA\tMASCULINO\tFEMENINO\tCUOTA FEMENINA(%)"
for i in glob.glob("op/*"):
out = ""
op = i.replace("op/op_", "")
op = op.replace(".tsv", "")
cmd = "grep -c 'MASCULINO' " + i
p = subprocess.check_output(cmd, shell=True)
masculino = p.strip()
out += op + "\t" + masculino + "\t"
cmd = "grep -c 'FEMENINO' " + i
p = subprocess.check_output(cmd, shell=True)
femenino = p.strip()
out += femenino
total = int(femenino) + int(masculino)
cuota = float(femenino)*100/float(total)
out += "\t" + str(cuota)
print out