Primera fase lista: Output CSV
This commit is contained in:
168
action_flow/fase1_extract.ipynb
Normal file
168
action_flow/fase1_extract.ipynb
Normal file
@@ -0,0 +1,168 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "0106c35d-8bd3-46e5-ae63-8bdcc7f3c57e",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Imports"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 29,
|
||||
"id": "07f1b7f9-e990-4f49-81ec-5e7b85533ce6",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import pandas as pd\n",
|
||||
"import os \n",
|
||||
"import sys"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 30,
|
||||
"id": "2c0608fc-aaf0-4050-9802-132a3f57e264",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"module_path = os.path.abspath(os.path.join('..'))\n",
|
||||
"\n",
|
||||
"# Add to sys.path if not already present\n",
|
||||
"if module_path not in sys.path:\n",
|
||||
" sys.path.append(module_path)\n",
|
||||
" print(module_path)\n",
|
||||
"\n",
|
||||
"from extraccion import agentes_entidades"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "e9945d03-5f4d-46f4-bf05-9effca5fbc30",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Variables"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 31,
|
||||
"id": "d9af271a-03f9-41c7-acf9-7497c5463cc8",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"INPUT_FOLDER = f\"{module_path}/input/Preguntas Categoricas/\"\n",
|
||||
"OUTPUT_FOLDER = f\"{module_path}/output/fase1\"\n",
|
||||
"FILES_TO_PROCESS = os.listdir(INPUT_FOLDER)\n",
|
||||
"DELIMITER = \"|^\"\n",
|
||||
"DIC_QUESTIONS = {\n",
|
||||
" \"Encuesta_MediaG01Q02.csv\":agentes_entidades.extractor_pre_1\n",
|
||||
" # COMPLETAR RESTO\n",
|
||||
"}"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "eb564083-f884-4bb4-8e4b-191d3bbd887e",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Functions"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 32,
|
||||
"id": "ec64ee5e-1d45-4d1e-805c-45a608eea33a",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def extract_answers(answers):\n",
|
||||
" answer_formated = \"\"\n",
|
||||
" iterator_answers = answers.acciones\n",
|
||||
" for item in iterator_answers:\n",
|
||||
" answer_formated+=f\"{item.accion}{DELIMITER}\"\n",
|
||||
" return answer_formated"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 33,
|
||||
"id": "886d7f02-0f5a-4a1f-8bd2-cb18c0a86360",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def format_answer(dataframe,function):\n",
|
||||
" dataframe[\"respuestas_formato\"] = None\n",
|
||||
" for index, row in dataframe.iterrows():\n",
|
||||
" answers = function (row['respuesta'])\n",
|
||||
" answer_to_insert = extract_answers(answers)\n",
|
||||
" dataframe.loc[index,'respuestas_formato'] = answer_to_insert"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 34,
|
||||
"id": "16d3fb54-7385-401e-8a0a-b594d08ae181",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def format_all_answers(Dic_questions):\n",
|
||||
" for key,value in Dic_questions.items():\n",
|
||||
" question_dataframe = pd.read_csv(INPUT_FOLDER+\"/\"+key)\n",
|
||||
" format_answer(question_dataframe, value)\n",
|
||||
" question_dataframe.to_csv(OUTPUT_FOLDER+\"/\"+key)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 35,
|
||||
"id": "93c06255-a231-4aee-899d-803d9fb0b342",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"----------------------------------------------------------------------------------------------------\n",
|
||||
"Realiza promoción por radio para informar a la comunidad sobre el acceso a educación media.\n",
|
||||
"----------------------------------------------------------------------------------------------------\n",
|
||||
"----------------------------------------------------------------------------------------------------\n",
|
||||
"Difunde mensajes informativos en la portería del establecimiento educativo.\n",
|
||||
"----------------------------------------------------------------------------------------------------\n",
|
||||
"----------------------------------------------------------------------------------------------------\n",
|
||||
"Utiliza carteleras del plantel para comunicar información sobre acceso a educación media.\n",
|
||||
"----------------------------------------------------------------------------------------------------\n",
|
||||
"----------------------------------------------------------------------------------------------------\n",
|
||||
"Implementa estrategia de comunicación de voz a voz con la comunidad educativa para promover el acceso a educación media.\n",
|
||||
"----------------------------------------------------------------------------------------------------\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"format_all_answers(DIC_QUESTIONS)"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.13.7"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
80
action_flow/fase1_extract.py
Normal file
80
action_flow/fase1_extract.py
Normal file
@@ -0,0 +1,80 @@
|
||||
#!/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)
|
||||
|
||||
Reference in New Issue
Block a user