{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"import numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport matplotlib.pyplot as plt\nimport os\nimport re\nimport matplotlib.pyplot as plt\nimport pydicom\nimport glob","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"traindt = pd.read_csv('../input/osic-pulmonary-fibrosis-progression/train.csv')\ntraindt.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"import seaborn as sns\ndef MinMaxFVC(feature):\n    plt.figure(dpi=100)\n    sns.distplot(traindt[feature],color='red')\n    print(\"{}Max value of {} is: {} {:.2f} \\n{}Min value of {} is: {} {:.2f}\\n{}Mean of {} is: {}{:.2f}\\n{}Standard Deviation of {} is:{}{:.2f}\"\\\n      .format('',feature,'',traindt[feature].max(),'',feature,'',traindt[feature].min(),'',feature,'',traindt[feature].mean(),'',feature,'',traindt[feature].std()))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"MinMaxFVC(\"FVC\")\nprint(\"There are {} unique patients in Train Data.\".format(len(traindt[\"Patient\"].unique())), \"\\n\")\ndataMinentry = traindt.groupby(by=\"Patient\")[\"Weeks\"].count().reset_index(drop=False)\ndataMinentry = dataMinentry.sort_values(['Weeks']).reset_index(drop=True)\nprint(\"The Min Week : {}\".format(traindt['Weeks'].min()), \"\\n\" +\n      \"The Max Week :{}\".format(traindt['Weeks'].max()))\nprint(\"Minimum number of entries are: {}\".format(dataMinentry[\"Weeks\"].min()), \"\\n\" +\n      \"Maximum number of entries are: {}\".format(dataMinentry[\"Weeks\"].max()))\nprint(f\"The Max week of the patient {max(traindt['Weeks'])}\")\nprint(f\"The Min week of the patient {min(traindt['Weeks'])}\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"traindt.corr()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"\ndef TrainDCM(dt, size=(4,4)):\n    plt.figure(figsize=size)\n    plt.imshow(dt.pixel_array, cmap=plt.cm.bone)\n    plt.show()\ndef numberfrom(svalue, pvalue, ret=0):\n    search = pvalue.search(svalue)\n    if search:\n        return int(search.groups()[0])\n    else:\n        return ret     \nfilepath = []\nID = \"ID00007637202177411956430\"\n\nfor file in glob.glob(\"../input/osic-pulmonary-fibrosis-progression/train/\"+ ID +\"/*.dcm\"):\n    filepath.append(file)\n   \npvalue = re.compile(ID +\"/\"+\"(\\d+)\")\nfilepath = sorted(filepath, key=lambda svalue: numberfrom(svalue, pvalue, float('inf'))) \nfor i in range(5):\n    plt.subplot(3, 6, i+1)\n    file_path = filepath[i]\n    dataset = pydicom.dcmread(file_path)\n    plt.imshow(dataset.pixel_array, cmap=plt.cm.bone)\n    plt.title(file_path[77:])\n    plt.tick_params(labelbottom=False,\n                    labelleft=False,\n                    labelright=False,\n                    labeltop=False)\ntestdt.loc[testdt.Patient == ID]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# Create base director for Train .dcm files\ndirector = \"../input/osic-pulmonary-fibrosis-progression/train\"\n\n# Create path column with the path to each patient's CT\ntraindt[\"Path\"] = director + \"/\" + traindt[\"Patient\"]\n\n# Create variable that shows how many CT scans each patient has\ntraindt[\"CT_number\"] = 0\n\nfor k, path in enumerate(traindt[\"Path\"]):\n    traindt[\"CT_number\"][k] = len(os.listdir(path))\n\n\n\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"traindt.head(50)\n","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat":4,"nbformat_minor":4}