Spaces:
Sleeping
Sleeping
File size: 4,553 Bytes
2f4f4ef 266bd2c 2f4f4ef b49bc9c 2f4f4ef 266bd2c 2f4f4ef 266bd2c 2f4f4ef ccada5d 266bd2c 2f4f4ef 266bd2c 2f4f4ef 266bd2c 2f4f4ef 266bd2c 2f4f4ef b49bc9c 2f4f4ef b49bc9c 2f4f4ef 649875f 2f4f4ef b49bc9c 2f4f4ef | 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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | {
"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": [
"<module 'functions' from '/Users/alanfortunysicart/Documents/GitHub/IndicatorHarmonizer/functions.py'>"
]
},
"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
}
|