-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_insert_result.py
More file actions
40 lines (27 loc) · 824 Bytes
/
Copy pathcreate_insert_result.py
File metadata and controls
40 lines (27 loc) · 824 Bytes
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
import pandas as pd
INSERT_RESULT = """
INSERT INTO RESULTADO (descricaoResultado) VALUES ('{}');
"""
def create_insert_string(situacao):
insert_sql = INSERT_RESULT.format(situacao)
return insert_sql
def add_lines_to_file(lines):
f = open('./sql_scripts/popula_resultado.sql', 'w+')
f.write('USE eleicoes;\n')
for line in lines:
f.write(line)
f.close()
if __name__ == '__main__':
filename = 'new_candidates.csv'
data = pd.read_csv(filename, parse_dates=['dtNascimento'])
counter = 0
results = []
for row in data.itertuples():
results.append(row[14])
lines = []
for result in set(results):
line = create_insert_string(result)
lines.append(line)
counter += 1
print('tamanho = ', counter)
add_lines_to_file(lines)