{ "info": { "author": "Mark Hoffmann", "author_email": "markkhoffmann@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 2 - Pre-Alpha", "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5" ], "description": "icd\n===\n\n.. image:: https://img.shields.io/pypi/v/icd.svg\n :target: https://pypi.python.org/pypi/icd\n :alt: Latest PyPI version\n\n.. image:: https://travis-ci.org/mark-hoffmann/icd.png\n :target: https://travis-ci.org/mark-hoffmann/icd\n :alt: Latest Travis CI build status\n\n.. image:: https://codecov.io/gh/mark-hoffmann/icd/branch/master/graph/badge.svg\n :target: https://codecov.io/gh/mark-hoffmann/icd\n :alt: Coverage\n\nTools for working with icd codes and comorbidities. This was inspired by the R package, `icd `_, as a simple python implementation for some of the base functionality. This has been benchmarked to be able to hand large datasets (tens of millions of rows) for various icd code manipulation tasks.\n\nIf you would be interested in helping contribute to this repository, feel free to `send me an email `_.\n\nUsage\n-----\nBasic usage includes two very common tasks while dealing with icd code data. \n\n- Transforming datasets from a long to wide format\n- Processing icd codes for known comorbidity mappings\n\n|\n|\n\n**Transforming from long to wide**\n\n\nData is commonly in a long format that may have a key for an individual such as *person_id* with many claims *claim_id* belonging to it. \n\nFor example:\n\n+------------+------------+-----------+------------+------------+\n| claim_id | person_id | icd_cd_1 | icd_cd_2 | icd_cd_3 |\n+============+============+===========+============+============+\n| 001 | A | code_6 | code_2 | |\n+------------+------------+-----------+------------+------------+\n| 002 | A | code_8 | | |\n+------------+------------+-----------+------------+------------+\n| 003 | A | code_3 | code_2 | code_6 |\n+------------+------------+-----------+------------+------------+\n| 004 | B | code_1 | | |\n+------------+------------+-----------+------------+------------+\n| 005 | B | code_2 | code_3 | |\n+------------+------------+-----------+------------+------------+\n| 006 | C | code_4 | code_2 | code_5 |\n+------------+------------+-----------+------------+------------+\n\nFor easier processing, we must transform the table into a more collapsed version. The number of *icd* columns then becomes the maximum unique codes for any given *person_id*.\n\nSuch as:\n\n+------------+-----------+------------+------------+------------+\n| person_id | icd_cd_1 | icd_cd_2 | icd_cd_3 | icd_cd_4 |\n+============+===========+============+============+============+\n| A | code_6 | code_2 | code_8 | code_3 |\n+------------+-----------+------------+------------+------------+\n| B | code_1 | code_2 | code_3 | |\n+------------+-----------+------------+------------+------------+\n| C | code_4 | code_2 | code_5 | |\n+------------+-----------+------------+------------+------------+\n\nTo accomplish this task, simply use the function *long_to_short_transformation* as such:\n\n.. code-block:: python\n\n import pandas as pd \n import icd\n\n data = {\"person_id\":[1,1,1,2,2,3],\n \"dx_1\":[\"F11\",\"E40\",\"\",\"F32\",\"C77\",\"G10\"],\n \"dx_2\":[\"F1P\",\"E400\",\"\",\"F322\",\"C737\",\"\"]}\n df = pd.DataFrame.from_dict(data)\n icd.long_to_short_transformation(df,\"person_id\",[\"dx_1\",\"dx_2\"])\n\nWhere *df* is your pandas dataframe, *\"person_id\"* is the column you want to roll up on, and *[\"dx_1\",\"dx_2\"]* is the array of columns that contain icd codes.\n\nIt is important to note that even if you only have one icd column, it **must still be an array**. Also, you must **impute NaN values** to be an **empty string** such as \"\".\n\nThe function will return a new dataframe with index of *person_id*, a column of *person_id*, as well as as many unique columns as needed in the following form *icd_0*, *icd_1*, ... , *icd_n*.\n\n|\n|\n\n**Processing icd codes to known comorbidities**\n\nThe second task has to do with actually mapping comorbidities to these icd codes. For this, you can use the function *icd_to_comorbidities*. This can be seen from going from a table of the format:\n\n+------------+-----------+------------+------------+------------+\n| person_id | icd_cd_1 | icd_cd_2 | icd_cd_3 | icd_cd_4 |\n+============+===========+============+============+============+\n| A | code_6 | code_2 | code_8 | code_3 |\n+------------+-----------+------------+------------+------------+\n| B | code_1 | code_2 | code_3 | |\n+------------+-----------+------------+------------+------------+\n| C | code_4 | code_2 | code_5 | |\n+------------+-----------+------------+------------+------------+\n\nTo the format:\n\n+------------+-----------+------------+------------+------------+\n| person_id | comorb_1 | comorb_2 | comorb_3 | comorb_4 |\n+============+===========+============+============+============+\n| A | True | False | True | True |\n+------------+-----------+------------+------------+------------+\n| B | False | True | False | False |\n+------------+-----------+------------+------------+------------+\n| C | False | False | False | False |\n+------------+-----------+------------+------------+------------+\n\nThis comorbidity mapping is pending on the mapping used.\n\n|\n\nAn example of doing is is carried out as such:\n\n.. code-block:: python\n\n import pandas as pd\n import icd\n\n df = pd.DataFrame.from_dict({'icd_0': {1: 'F1P', 2: 'F322', 3: ''},\n\t\t 'icd_1': {1: 'F11', 2: 'C77', 3: 'G10'},\n\t\t\t 'icd_2': {1: '', 2: 'C737', 3: ''},\n\t\t\t 'icd_3': {1: 'E400', 2: 'F32', 3: ''},\n\t\t 'icd_4': {1: 'E40', 2: '', 3: ''},\n\t\t\t 'person_id': {1: 1, 2: 2, 3: 3}})\n icd.icd_to_comorbidities(df, \"person_id\", [\"icd_0\",\"icd_1\",\"icd_2\",\"icd_3\",\"icd_4\"])\n\n|\n\nThe default default mapping is the *quan_elixhauser10*, which is a transcription by Quan of the original Elixhauser icd 9 comorbidities in the `following paper `_.\n\nOptionally, you can provide a *mapping* keyword argument as such:\n\n.. code-block:: python\n\n icd.icd_to_comorbidities(df, \"person_id\", [\"icd_0\",\"icd_1\",\"icd_2\",\"icd_3\",\"icd_4\"], mapping=\"quan_elixhauser10\")\n\nThe currently supported mappings are the default *\"quan_elixhauser10\"* as well as the *\"charlson10\"* mapping as referenced from the same paper above. Additionally, you can find them laid out in SAS code `here `_.\n\n\nIf you want to to create a custom comborbidity mapping, simply pass in a dict for the mapping argument instead of a supported keyword string. The dict must follow the following format as such:\n\n.. code-block:: python\n\n custom_mapping = {\"paraplegia_and_hemiplegia\":['G81','G82','G041','G114','G801','G802','G830','G831','G832','G833','G834','G839'],\n\t\t\t\t \"renal_disease\":['N18','N19','N052','N053','N054','N055','N056','N057','N250','I120','I131','N032','N033','N034','N035','N036','N037','Z490','Z491','Z492','Z940','Z992'],\n\t\t\t\t \"cancer\":['C00','C01','C02','C03','C04','C05','C06','C07','C08','C09','C10','C11','C12','C13','C14','C15','C16','C17','C18','C19','C20','C21','C22','C23','C24','C25','C26','C30','C31','C32','C33','C34','C37','C38','C39','C40','C41','C43','C45','C46','C47','C48','C49','C50','C51','C52','C53','C54','C55','C56','C57','C58','C60','C61','C62','C63','C64','C65','C66','C67','C68','C69','C70','C71','C72','C73','C74','C75','C76','C81','C82','C83','C84','C85','C88','C90','C91','C92','C93','C94','C95','C96','C97'],\n\t\t\t\t \"moderate_or_sever_liver_disease\":['K704','K711','K721','K729','K765','K766','K767','I850','I859','I864','I982'],\n\t\t\t\t \"metastitic_carcinoma\":['C77','C78','C79','C80'],\n\t\t\t\t \"aids_hiv\":['B20','B21','B22','B24']\n\t\t\t\t }\n icd.icd_to_comorbidities(df, \"person_id\", [\"icd_0\",\"icd_1\",\"icd_2\",\"icd_3\",\"icd_4\"], mapping=custom_mapping)\n\nThe above function returns a new DataFrame with the *person_id* values as the index, a column of whatever \"person_id\" string is passed in, along with a column for every comorbidity populated with either **True** or **False**.\n\nInstallation\n------------\n\nicd can easily be downloaded from Pypi package index via the following:\n\n.. code-block:: python\n\n pip install icd\n\n\n\nRequirements\n^^^^^^^^^^^^\n- `pandas `_\n\nCompatibility\n-------------\n\nicd currently supports Python 3.4, 3.5, and 3.6\n\nLicence\n-------\n\n`MIT `_\n\nAuthors\n-------\n\n`icd` was written by `Mark Hoffmann `_.\n\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/mark-hoffmann/icd", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "icd", "package_url": "https://pypi.org/project/icd/", "platform": "", "project_url": "https://pypi.org/project/icd/", "project_urls": { "Homepage": "https://github.com/mark-hoffmann/icd" }, "release_url": "https://pypi.org/project/icd/0.1.2/", "requires_dist": [ "pandas" ], "requires_python": "", "summary": "Tools for working with icd codes and comorbidities", "version": "0.1.2" }, "last_serial": 4249372, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "f3fa5c756279ce074be2d3f083a10e92", "sha256": "f7840a50f7cc3f4531faaecaf92ac5ee288700ca6c4ada3692cd4a7d915afecb" }, "downloads": -1, "filename": "icd-0.1.0-py2-none-any.whl", "has_sig": false, "md5_digest": "f3fa5c756279ce074be2d3f083a10e92", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 7710, "upload_time": "2017-10-14T05:05:39", "url": "https://files.pythonhosted.org/packages/d3/27/bb3bfa1ea5cfe20144026906643fcba1896b32969dfeb55c87fac49c0070/icd-0.1.0-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "c5d33186c4a3978b0c8d33e833491e54", "sha256": "3821e840aeafb3765085638f75eba6a377c0731d33041396baced97e592ec715" }, "downloads": -1, "filename": "icd-0.1.0.tar.gz", "has_sig": false, "md5_digest": "c5d33186c4a3978b0c8d33e833491e54", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5066, "upload_time": "2017-10-14T05:05:41", "url": "https://files.pythonhosted.org/packages/ff/05/ae6636a10997253533769ff15b785d15963b8cceeab04e1ce9703dcc36c3/icd-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "3cb92957d291ae5579558892e09b55a1", "sha256": "0e10f757b2533387920492b9899044b32b0ea30a16841e4e22b64c7456409465" }, "downloads": -1, "filename": "icd-0.1.1-py2-none-any.whl", "has_sig": false, "md5_digest": "3cb92957d291ae5579558892e09b55a1", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 12842, "upload_time": "2017-10-14T19:37:42", "url": "https://files.pythonhosted.org/packages/cd/c2/ffcb8aa2a68436dd3e468f1104522b5d154fb46607ca7dc630a952dc9a43/icd-0.1.1-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "1655ada9ad197228aec046106c8952f5", "sha256": "9f5f7854ba1d64928f34a7eb933143312bca448b5f6c61f21f6c549c2ef6cba3" }, "downloads": -1, "filename": "icd-0.1.1.tar.gz", "has_sig": false, "md5_digest": "1655ada9ad197228aec046106c8952f5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7363, "upload_time": "2017-10-14T19:37:43", "url": "https://files.pythonhosted.org/packages/17/e7/eef8a2cfe8c8d688e4472d967424634a097e22dd21c465fa696c42b5f4c3/icd-0.1.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "4c0a4d91c1efd186fc0c014442194d70", "sha256": "826f9970bee6e0b197db62a04cb391dbdd27a58f3b8a1a4350258d64e7d66cbd" }, "downloads": -1, "filename": "icd-0.1.2-py3-none-any.whl", "has_sig": false, "md5_digest": "4c0a4d91c1efd186fc0c014442194d70", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 12897, "upload_time": "2018-09-07T17:47:15", "url": "https://files.pythonhosted.org/packages/61/1e/6ffbcef1f7930f153cd3e0ecbd70a6b18f3784f9e8ccd23b4ad926cc452c/icd-0.1.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "0237641edc4c4cdd8448a837ae3cd90c", "sha256": "fa1ace3e54858e098bf1e4f90c9cdfe56e0224aa802f7fa36ccda549a6e6fad2" }, "downloads": -1, "filename": "icd-0.1.2.tar.gz", "has_sig": false, "md5_digest": "0237641edc4c4cdd8448a837ae3cd90c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9345, "upload_time": "2018-09-07T17:47:17", "url": "https://files.pythonhosted.org/packages/15/38/6fdae227968b2306561ea6410656bd610da5c49d78250731ae6b689ff813/icd-0.1.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "4c0a4d91c1efd186fc0c014442194d70", "sha256": "826f9970bee6e0b197db62a04cb391dbdd27a58f3b8a1a4350258d64e7d66cbd" }, "downloads": -1, "filename": "icd-0.1.2-py3-none-any.whl", "has_sig": false, "md5_digest": "4c0a4d91c1efd186fc0c014442194d70", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 12897, "upload_time": "2018-09-07T17:47:15", "url": "https://files.pythonhosted.org/packages/61/1e/6ffbcef1f7930f153cd3e0ecbd70a6b18f3784f9e8ccd23b4ad926cc452c/icd-0.1.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "0237641edc4c4cdd8448a837ae3cd90c", "sha256": "fa1ace3e54858e098bf1e4f90c9cdfe56e0224aa802f7fa36ccda549a6e6fad2" }, "downloads": -1, "filename": "icd-0.1.2.tar.gz", "has_sig": false, "md5_digest": "0237641edc4c4cdd8448a837ae3cd90c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9345, "upload_time": "2018-09-07T17:47:17", "url": "https://files.pythonhosted.org/packages/15/38/6fdae227968b2306561ea6410656bd610da5c49d78250731ae6b689ff813/icd-0.1.2.tar.gz" } ] }