Skip to content
Snippets Groups Projects
Commit ce287e94 authored by Jomaro Rodrigues's avatar Jomaro Rodrigues
Browse files

metade da correção do problema das colunas

parent 40d4683a
Branches
No related tags found
No related merge requests found
...@@ -6,6 +6,8 @@ import sys ...@@ -6,6 +6,8 @@ import sys
import pandas as pd import pandas as pd
import numpy as np import numpy as np
import os import os
import shutil
import re
...@@ -36,7 +38,39 @@ $ %s -d relatorio.csv ...@@ -36,7 +38,39 @@ $ %s -d relatorio.csv
def crypt(name): def crypt(name):
data = pd.read_csv(name) notify_empty_lines = False
notify_comma_decimal_separator = False
if not os.path.exists('.'+name):
shutil.copyfile(name, '.'+name)
else:
print('arquivo .%s ja existe, abortando' % name)
sys.exit(1)
comma_separator = re.compile(ur',33333333|,66666666')
orig = open(name, 'r')
rep = open('.'+name, 'w+')
for line in orig:
if len(line) == 0:
notify_empty_lines = True
elif comma_separator.search(line):
notify_comma_decimal_separator = True
#l = line.decode('utf8').replace(r',33333333', r'.33333333').replace(r',66666666', r'.66666666').encode('utf8')
l = line.replace(r',33333333', r'.33333333').replace(r',66666666', r'.66666666')
rep.write(l)
else:
rep.write(line)
orig.close()
rep.close()
#sys.exit(5)
data = pd.read_csv('.'+name)
if os.path.exists(TABLE_FILE): if os.path.exists(TABLE_FILE):
table = pd.read_csv(TABLE_FILE) table = pd.read_csv(TABLE_FILE)
...@@ -46,7 +80,7 @@ def crypt(name): ...@@ -46,7 +80,7 @@ def crypt(name):
if not os.path.exists(dirname): if not os.path.exists(dirname):
os.makedirs(dirname) os.makedirs(dirname)
table = pd.DataFrame(columns=["ID", "MATR_ALUNO", "NOME_ALUNO"]) table = pd.DataFrame(columns=["ID", "MATR_ALUNO", "NOME_PESSOA"])
table.to_csv(TABLE_FILE, index=False) table.to_csv(TABLE_FILE, index=False)
...@@ -63,15 +97,18 @@ def crypt(name): ...@@ -63,15 +97,18 @@ def crypt(name):
# #
if "NOME_ALUNO" in data.columns: if "NOME_ALUNO" in data.columns:
data.rename(columns={'NOME_ALUNO': 'NOME_PESSOA'}, inplace=True)
table_append = pd.merge(table_append, data[["MATR_ALUNO", "NOME_ALUNO"]], how="left", on="MATR_ALUNO") if "NOME_PESSOA" in data.columns:
table_append = pd.merge(table_append, data[["MATR_ALUNO", "NOME_PESSOA"]], how="left", on="MATR_ALUNO")
UTF8toupper = lambda s: s.decode("utf8").upper().encode("utf8") UTF8toupper = lambda s: s.decode("utf8").upper().encode("utf8")
table_append["NOME_ALUNO"] = table_append.NOME_ALUNO.apply(UTF8toupper) table_append["NOME_PESSOA"] = table_append.NOME_PESSOA.apply(UTF8toupper)
else: else:
table_append["NOME_ALUNO"] = "" table_append["NOME_PESSOA"] = ""
# pega todos os registros que ainda não existem no table # pega todos os registros que ainda não existem no table
...@@ -106,8 +143,8 @@ def crypt(name): ...@@ -106,8 +143,8 @@ def crypt(name):
del data["MATR_ALUNO"] del data["MATR_ALUNO"]
if "NOME_ALUNO" in data.columns: if "NOME_PESSOA" in data.columns:
del data["NOME_ALUNO"] del data["NOME_PESSOA"]
data.rename(columns={"ID": "MATR_ALUNO"}, inplace=True) data.rename(columns={"ID": "MATR_ALUNO"}, inplace=True)
...@@ -130,6 +167,17 @@ def crypt(name): ...@@ -130,6 +167,17 @@ def crypt(name):
# #
data.to_csv(".".join(split_name), index=False) data.to_csv(".".join(split_name), index=False)
os.remove('.'+name)
if notify_empty_lines or notify_comma_decimal_separator:
print "Warnings:"
if notify_empty_lines:
print "Linha em branco presente no arquivo"
if notify_comma_decimal_separator:
print "virgula foi usada como separador de campo decimal"
return data return data
......
check.py 100644 → 100755
#!/usr/bin/env python
# coding: utf-8
import pandas as pd import pandas as pd
import os import os
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment