starting Drugs for Pathologies

This commit is contained in:
Frank Knoll
2024-07-26 23:42:07 +02:00
parent be77ed5e33
commit 09aa9c2c6b
2 changed files with 129 additions and 2 deletions

View File

@@ -608,9 +608,136 @@
},
{
"cell_type": "markdown",
"id": "439c055f",
"id": "be72f509",
"metadata": {},
"source": []
"source": [
"# Drugs for Pathologies"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c8190125",
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import os"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a416e3b7",
"metadata": {},
"outputs": [],
"source": [
"drugs4Pathologies = pd.read_excel(\n",
" io = 'data/1000-pathologies.xlsx',\n",
" converters = {\n",
" 'PATHOLOGY': lambda text: text.strip(),\n",
" 'DRUG': lambda text: text.strip() })\n",
"drugs4Pathologies"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "492230af",
"metadata": {},
"outputs": [],
"source": [
"def drugsTable2drugDescr(drugsTable):\n",
" drugDescr = drugsTable.to_dict('list')\n",
" del drugDescr['PATHOLOGY']\n",
" return drugDescr"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1c0166e6",
"metadata": {},
"outputs": [],
"source": [
"drugDescrByPathology = drugs4Pathologies.groupby('PATHOLOGY').apply(drugsTable2drugDescr)\n",
"drugDescrByPathology"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f7e83e81",
"metadata": {},
"outputs": [],
"source": [
"drugDescrByPathology['bone cancer']"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0d0b6909",
"metadata": {},
"outputs": [],
"source": [
"drugs4Pathologies[drugs4Pathologies['PATHOLOGY'] == 'bone cancer']"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4444d234",
"metadata": {},
"outputs": [],
"source": [
"import shutil\n",
"from IOUtils import IOUtils\n",
"\n",
"def saveDrugDescriptionsForPathologies(drugDescrByPathology, directory):\n",
" shutil.rmtree(directory, ignore_errors = True)\n",
" filenameByPathology = {}\n",
" i = 0\n",
" for pathology, drugDescr in drugDescrByPathology.items():\n",
" i += 1\n",
" filenameByPathology[pathology] = f'{i}'\n",
" drugDescr['PATHOLOGY'] = pathology\n",
" IOUtils.saveDictAsJson(drugDescr, f'{directory}/{i}.json')\n",
" return filenameByPathology \n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5bd7d025",
"metadata": {},
"outputs": [],
"source": [
"webAppBaseDir = os.path.normpath(os.getcwd() + '/../docs/DrugsForPathologies')\n",
"webAppBaseDir"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7652a551",
"metadata": {},
"outputs": [],
"source": [
"filenameByPathology = saveDrugDescriptionsForPathologies(\n",
" drugDescrByPathology = drugDescrByPathology,\n",
" directory = os.path.normpath(webAppBaseDir + '/data/DrugDescriptionsForPathologies'))\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "013ffd05",
"metadata": {},
"outputs": [],
"source": [
"filenameByPathology"
]
}
],
"metadata": {

Binary file not shown.