{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Indicator Harmonizer" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The goal of this code is to provide a recommendation of indicators and detect cases where we migh need to create new" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1 Load required packages" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Functions loaded\n", "Functions loaded\n" ] }, { "data": { "text/plain": [ "" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import pandas as pd\n", "import re\n", "import numpy as np\n", "import importlib\n", "import importlib\n", "from seatable_api import Base, context\n", "from pandas import json_normalize\n", "import importlib\n", "import functions as f\n", "importlib.reload(f)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 2. Load the required data" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Load the request data including the generic indicator requests" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "table1 = pd.read_excel('/Users/alanfortunysicart/Downloads/Indicators_Indicators_Frameworks_Default View(1).xlsx')\n", "table2 = pd.read_excel('/Users/alanfortunysicart/Downloads/Indicators_Indicators_Default view(14).xlsx')\n", "# columns to use for embeddings on table 1\n", "\n", "columns_embeddings_col1 = ['Indicator Name']\n", "\n", "# columns to use for embeddings on table 2\n", "columns_embeddings_col2 = ['Indicator name (leonardo)']\n", "\n", "harmonization=True" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "if 'Indicator ID' in table1.columns:\n", " table1['ID'] = table1['Indicator ID'].astype(str)\n", "else:\n", " table1['ID'] = table1['ID'].astype(str)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create a column concatenating the column's content to be used for the embeddings" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "table1 = f.concatenate_columns(table1, columns=f.columns_embeddings_col1)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Concatenate topic and indicator request name to help the indicator search" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "table2 = f.concatenate_columns(table2,columns=f.columns_embeddings_col2)\n", "\n", "if 'Indicator ID' in table2.columns:\n", " table2['ID'] = table2['Indicator ID'].astype(str)\n", "else:\n", " table2['ID'] = table2['ID'].astype(str)\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 3. Compute the similarity between leonardo. indicator and the requested names" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "result_final = f.process_similarity_results(table1, table2, harmonization=True,columns_embeddings_col1=f.columns_embeddings_col1,columns_embeddings_col2=f.columns_embeddings_col2)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 4. Export the results and submit" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "result_final.to_csv('Indicator_Framework_Harmonizer_Definition_new_order.csv')" ] } ], "metadata": { "kernelspec": { "display_name": "seatableToKobo", "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.10.13" } }, "nbformat": 4, "nbformat_minor": 2 }