81 lines
1.5 KiB
Python
81 lines
1.5 KiB
Python
#!/usr/bin/env python
|
|
# coding: utf-8
|
|
|
|
# # Imports
|
|
|
|
# In[29]:
|
|
|
|
|
|
import pandas as pd
|
|
import os
|
|
import sys
|
|
|
|
|
|
# In[30]:
|
|
|
|
|
|
module_path = os.path.abspath(os.path.join('..'))
|
|
|
|
# Add to sys.path if not already present
|
|
if module_path not in sys.path:
|
|
sys.path.append(module_path)
|
|
print(module_path)
|
|
|
|
from extraccion import agentes_entidades
|
|
|
|
|
|
# # Variables
|
|
|
|
# In[31]:
|
|
|
|
|
|
INPUT_FOLDER = f"{module_path}/input/Preguntas Categoricas/"
|
|
OUTPUT_FOLDER = f"{module_path}/output/fase1"
|
|
FILES_TO_PROCESS = os.listdir(INPUT_FOLDER)
|
|
DELIMITER = "|^"
|
|
DIC_QUESTIONS = {
|
|
"Encuesta_MediaG01Q02.csv":agentes_entidades.extractor_pre_1
|
|
# COMPLETAR RESTO
|
|
}
|
|
|
|
|
|
# # Functions
|
|
|
|
# In[32]:
|
|
|
|
|
|
def extract_answers(answers):
|
|
answer_formated = ""
|
|
iterator_answers = answers.acciones
|
|
for item in iterator_answers:
|
|
answer_formated+=f"{item.accion}{DELIMITER}"
|
|
return answer_formated
|
|
|
|
|
|
# In[33]:
|
|
|
|
|
|
def format_answer(dataframe,function):
|
|
dataframe["respuestas_formato"] = None
|
|
for index, row in dataframe.iterrows():
|
|
answers = function (row['respuesta'])
|
|
answer_to_insert = extract_answers(answers)
|
|
dataframe.loc[index,'respuestas_formato'] = answer_to_insert
|
|
|
|
|
|
# In[34]:
|
|
|
|
|
|
def format_all_answers(Dic_questions):
|
|
for key,value in Dic_questions.items():
|
|
question_dataframe = pd.read_csv(INPUT_FOLDER+"/"+key)
|
|
format_answer(question_dataframe, value)
|
|
question_dataframe.to_csv(OUTPUT_FOLDER+"/"+key)
|
|
|
|
|
|
# In[35]:
|
|
|
|
|
|
format_all_answers(DIC_QUESTIONS)
|
|
|