{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "51f734f8-1015-4aa6-bcb5-2bd42799397c", "metadata": {}, "outputs": [], "source": [ "import os\n", "import zipfile\n", "import tempfile\n", "import xml.etree.ElementTree as ET\n", "import pandas as pd\n", "from tqdm import tqdm\n", "from HCFA_XML_to_DF import *" ] }, { "cell_type": "code", "execution_count": 2, "id": "60af5430-15ed-406a-a928-a310d31cfb1d", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import gc\n", "gc.collect()" ] }, { "cell_type": "code", "execution_count": 3, "id": "d23238ca-c231-4480-9be3-0c9497b957a9", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Key_Name
0MissApp
1Box19B_Provider
2Box19B_NPI
\n", "
" ], "text/plain": [ " Key_Name\n", "0 MissApp\n", "1 Box19B_Provider\n", "2 Box19B_NPI" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Hcfa_key_list = pd.read_excel(\"/Data/XELP_Experiments/Notebooks/HCFA_Keys.xlsx\")\n", "Hcfa_key_list.head(3)" ] }, { "cell_type": "code", "execution_count": 4, "id": "2600d374-0b7c-4669-9af9-833eba2363fc", "metadata": {}, "outputs": [], "source": [ "key_list = Hcfa_key_list['Key_Name'].unique()\n" ] }, { "cell_type": "code", "execution_count": 5, "id": "baa74ee8-3b6f-4cf0-a16b-548e9afd76dc", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "15000\n" ] } ], "source": [ "Trans_dir = '/Data/XELP_Experiments/Training_Data/HCFA/Extracted_EV_GRPBX/TRANS/'\n", "trans_files_list = os.listdir(Trans_dir)\n", "print(len(trans_files_list))" ] }, { "cell_type": "code", "execution_count": 6, "id": "7204c322-1a44-4c75-b18a-0903e482c317", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "977" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "gc.collect()" ] }, { "cell_type": "code", "execution_count": 7, "id": "7abd84bc-5151-4a61-b67e-18dec23e4407", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "100%|███████████████████████████████████| 15000/15000 [3:09:45<00:00, 1.32it/s]\n" ] } ], "source": [ "data = pd.DataFrame()\n", "i = 0\n", "for each_trans_file in tqdm(trans_files_list):\n", " each_trans_path = os.path.join(Trans_dir, each_trans_file)\n", " #print(each_trans_path)\n", " df, im_names = OCR_XML_to_DataFrame(each_trans_path, key_list)\n", " #print(df.shape)\n", " \n", " i += 1\n", " df[\"Trans_file_name\"] = each_trans_file\n", " #print(im_names)\n", " df[\"img_details\"] = [im_names] * len(df)\n", " data = pd.concat([data, df], ignore_index=True)\n", "\n", " if i%200 == 0:\n", " gc.collect()\n" ] }, { "cell_type": "code", "execution_count": 57, "id": "e1007e02-7aa9-4a3a-b446-6023f445fce3", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Index(['Data', 'TRANS_Value', 'Group_name', 'Image_width', 'Image_height',\n", " 'Field_Name', 'x1', 'x2', 'y1', 'y2', 'Page', 'OCR_OMNI', 'OCR_IGEAR',\n", " 'OCR_AT', 'OCR_Optimizer', 'Comments', 'Trans_file_name',\n", " 'img_details'],\n", " dtype='object')" ] }, "execution_count": 57, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data.columns" ] }, { "cell_type": "code", "execution_count": 58, "id": "7e213b50-1c76-4cc3-93ca-3aa6d5ae8880", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(4371082, 18)" ] }, "execution_count": 58, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data.shape" ] }, { "cell_type": "code", "execution_count": 59, "id": "bc16057b-bc8e-45b6-841a-9198030b7b18", "metadata": {}, "outputs": [], "source": [ "pd.set_option(\"display.max_rows\", None)" ] }, { "cell_type": "code", "execution_count": 52, "id": "43aec1a2-2be3-4254-aa1c-c56bb322023d", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3553 [1378N430MC010_002.tiff, 1378N430MC010_003.tif...\n", "3554 [1378N430MC010_002.tiff, 1378N430MC010_003.tif...\n", "3555 [1378N430MC010_002.tiff, 1378N430MC010_003.tif...\n", "3556 [1378N430MC010_002.tiff, 1378N430MC010_003.tif...\n", "Name: img_details, dtype: object" ] }, "execution_count": 52, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data[3553:3557]['img_details']" ] }, { "cell_type": "code", "execution_count": 66, "id": "ef6766a8-0f84-4d5c-b050-0cdb6398fefd", "metadata": {}, "outputs": [], "source": [ "#data.to_excel(\"/Data/XELP_Experiments/Training_Data/HCFA/EDA_Analysis/EV_GRPBMX.xlsx\", index=False)" ] }, { "cell_type": "code", "execution_count": null, "id": "065d09bb-9af4-4496-8e70-cabc18068af3", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 82, "id": "044bfc7e-c358-4071-8c36-aa0437d27700", "metadata": {}, "outputs": [], "source": [ "data.to_parquet(\"/Data/XELP_Experiments/Training_Data/HCFA/EDA_Analysis/EV_GRPBX.parquet\", index=False)" ] }, { "cell_type": "code", "execution_count": null, "id": "f5416a40-0d73-4903-b420-a8d3170c193e", "metadata": {}, "outputs": [], "source": [] } ], "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.11.7" } }, "nbformat": 4, "nbformat_minor": 5 }