{"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_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"### NOTE\n# Before running this notebook, run read-dicom-info to generate train_df_dicom_data.csv. \n\nimport numpy as np \nimport pandas as pd \nimport os\nimport seaborn as sns\nsns.set(rc={\"figure.figsize\":(12, 8)})\n","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2021-07-01T20:19:37.686690Z","iopub.execute_input":"2021-07-01T20:19:37.686995Z","iopub.status.idle":"2021-07-01T20:19:37.692188Z","shell.execute_reply.started":"2021-07-01T20:19:37.686959Z","shell.execute_reply":"2021-07-01T20:19:37.691255Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Inspect data files","metadata":{}},{"cell_type":"code","source":"train_folder = '/kaggle/input/siim-covid19-detection/train'\ntest_folder = '/kaggle/input/siim-covid19-detection/test'\ntrain_image_level = '/kaggle/input/siim-covid19-detection/train_image_level.csv'\ntrain_study_level = '/kaggle/input/siim-covid19-detection/train_study_level.csv'\nsample_submission = '/kaggle/input/siim-covid19-detection/sample_submission.csv'","metadata":{"execution":{"iopub.status.busy":"2021-07-01T20:19:37.693662Z","iopub.execute_input":"2021-07-01T20:19:37.693908Z","iopub.status.idle":"2021-07-01T20:19:37.706657Z","shell.execute_reply.started":"2021-07-01T20:19:37.693885Z","shell.execute_reply":"2021-07-01T20:19:37.705855Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train_image = pd.read_csv(train_image_level)\ndf_train_study = pd.read_csv(train_study_level)","metadata":{"execution":{"iopub.status.busy":"2021-07-01T20:19:37.708096Z","iopub.execute_input":"2021-07-01T20:19:37.708548Z","iopub.status.idle":"2021-07-01T20:19:37.751765Z","shell.execute_reply.started":"2021-07-01T20:19:37.708519Z","shell.execute_reply":"2021-07-01T20:19:37.750939Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train_image.head(1)","metadata":{"execution":{"iopub.status.busy":"2021-07-01T20:19:37.752992Z","iopub.execute_input":"2021-07-01T20:19:37.753227Z","iopub.status.idle":"2021-07-01T20:19:37.762509Z","shell.execute_reply.started":"2021-07-01T20:19:37.753204Z","shell.execute_reply":"2021-07-01T20:19:37.761561Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train_study.head(1)","metadata":{"execution":{"iopub.status.busy":"2021-07-01T20:19:37.763630Z","iopub.execute_input":"2021-07-01T20:19:37.763886Z","iopub.status.idle":"2021-07-01T20:19:37.777730Z","shell.execute_reply.started":"2021-07-01T20:19:37.763864Z","shell.execute_reply":"2021-07-01T20:19:37.776746Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#rename id with StudyInstanceUID to merge two dataframes\ndf_train_study.rename(columns={'id':'StudyInstanceUID'},inplace=True)\ndf_train_study.head(1)","metadata":{"execution":{"iopub.status.busy":"2021-07-01T20:19:37.778873Z","iopub.execute_input":"2021-07-01T20:19:37.779293Z","iopub.status.idle":"2021-07-01T20:19:37.792947Z","shell.execute_reply.started":"2021-07-01T20:19:37.779267Z","shell.execute_reply":"2021-07-01T20:19:37.792025Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# get rid of _image and _study\ndf_train_image['id'] = df_train_image['id'].apply(lambda x: x[0:-6])\ndf_train_study['StudyInstanceUID'] = df_train_study['StudyInstanceUID'].apply(lambda x: x[0:-6])","metadata":{"execution":{"iopub.status.busy":"2021-07-01T20:19:37.795091Z","iopub.execute_input":"2021-07-01T20:19:37.795461Z","iopub.status.idle":"2021-07-01T20:19:37.811983Z","shell.execute_reply.started":"2021-07-01T20:19:37.795426Z","shell.execute_reply":"2021-07-01T20:19:37.811093Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train_merge = pd.merge(df_train_image,df_train_study,on='StudyInstanceUID')","metadata":{"execution":{"iopub.status.busy":"2021-07-01T20:19:37.813177Z","iopub.execute_input":"2021-07-01T20:19:37.813492Z","iopub.status.idle":"2021-07-01T20:19:37.829293Z","shell.execute_reply.started":"2021-07-01T20:19:37.813467Z","shell.execute_reply":"2021-07-01T20:19:37.828545Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train_merge.head(5)","metadata":{"execution":{"iopub.status.busy":"2021-07-01T20:19:37.830487Z","iopub.execute_input":"2021-07-01T20:19:37.830768Z","iopub.status.idle":"2021-07-01T20:19:37.847578Z","shell.execute_reply.started":"2021-07-01T20:19:37.830743Z","shell.execute_reply":"2021-07-01T20:19:37.846366Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#unify class columns\ndf_train_merge.loc[df_train_merge['Negative for Pneumonia']==1,'class']='negative'\ndf_train_merge.loc[df_train_merge['Typical Appearance']==1,'class']='typical'\ndf_train_merge.loc[df_train_merge['Indeterminate Appearance']==1,'class']='indeterminate'\ndf_train_merge.loc[df_train_merge['Atypical Appearance']==1,'class']='atypical'\ndf_train_merge.drop(['Negative for Pneumonia','Typical Appearance',\n                     'Indeterminate Appearance','Atypical Appearance'],axis=1,inplace=True)\ndf_train_merge.head()","metadata":{"execution":{"iopub.status.busy":"2021-07-01T20:19:37.848593Z","iopub.execute_input":"2021-07-01T20:19:37.848942Z","iopub.status.idle":"2021-07-01T20:19:37.867021Z","shell.execute_reply.started":"2021-07-01T20:19:37.848908Z","shell.execute_reply":"2021-07-01T20:19:37.866248Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train_merge.loc[4560,'label']","metadata":{"execution":{"iopub.status.busy":"2021-07-01T20:19:37.868254Z","iopub.execute_input":"2021-07-01T20:19:37.868597Z","iopub.status.idle":"2021-07-01T20:19:37.873189Z","shell.execute_reply.started":"2021-07-01T20:19:37.868572Z","shell.execute_reply":"2021-07-01T20:19:37.872433Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#get boxes and opacity values\nfor c in ['bbox','confidence','label_op']:\n    df_train_merge[c] = np.nan\n    df_train_merge[c] = df_train_merge[c].astype('object')\nfor r in df_train_merge.index:\n    val_len = len(df_train_merge['label'][r].split(' '))\n    val = df_train_merge['label'][r].split(' ')\n    nbox = int(val_len/6)\n    boxes,cc=[],[]\n    for i in range(0,nbox):\n        cc.append(val[(1+i*6)])\n        box = val[(2+i*6):(6+i*6)]\n        boxes.append(box)\n    df_train_merge.at[r,'label_op'] = val[0]\n    df_train_merge.at[r,'confidence'] = cc\n    df_train_merge.at[r,'bbox'] = boxes\n    if val[0] =='none':\n        df_train_merge.at[r,'num_box'] = 0\n    else:\n        df_train_merge.at[r,'num_box'] = len(boxes)\n            \n    ","metadata":{"execution":{"iopub.status.busy":"2021-07-01T20:19:37.874349Z","iopub.execute_input":"2021-07-01T20:19:37.874701Z","iopub.status.idle":"2021-07-01T20:19:38.308152Z","shell.execute_reply.started":"2021-07-01T20:19:37.874676Z","shell.execute_reply":"2021-07-01T20:19:38.307519Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train_merge","metadata":{"execution":{"iopub.status.busy":"2021-07-01T20:19:38.308989Z","iopub.execute_input":"2021-07-01T20:19:38.309337Z","iopub.status.idle":"2021-07-01T20:19:38.338260Z","shell.execute_reply.started":"2021-07-01T20:19:38.309311Z","shell.execute_reply":"2021-07-01T20:19:38.337709Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#check whether images contain mixed confidence values\ndf_train_merge['confidence'].apply(lambda x: len(list(set(x)))).unique()","metadata":{"execution":{"iopub.status.busy":"2021-07-01T20:19:38.339078Z","iopub.execute_input":"2021-07-01T20:19:38.339412Z","iopub.status.idle":"2021-07-01T20:19:38.356618Z","shell.execute_reply.started":"2021-07-01T20:19:38.339376Z","shell.execute_reply":"2021-07-01T20:19:38.355894Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"In training dataset, confidence value for opacity is always 1.","metadata":{"execution":{"iopub.status.busy":"2021-07-01T18:49:58.854713Z","iopub.execute_input":"2021-07-01T18:49:58.855024Z","iopub.status.idle":"2021-07-01T18:49:58.858816Z","shell.execute_reply.started":"2021-07-01T18:49:58.854998Z","shell.execute_reply":"2021-07-01T18:49:58.85822Z"}}},{"cell_type":"code","source":"df_train_merge.shape","metadata":{"execution":{"iopub.status.busy":"2021-07-01T20:19:38.359145Z","iopub.execute_input":"2021-07-01T20:19:38.359529Z","iopub.status.idle":"2021-07-01T20:19:38.366571Z","shell.execute_reply.started":"2021-07-01T20:19:38.359492Z","shell.execute_reply":"2021-07-01T20:19:38.365644Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Class distribution in training set is not uniform.","metadata":{"execution":{"iopub.status.busy":"2021-06-28T21:21:04.537026Z","iopub.execute_input":"2021-06-28T21:21:04.53743Z","iopub.status.idle":"2021-06-28T21:21:04.541792Z","shell.execute_reply.started":"2021-06-28T21:21:04.537392Z","shell.execute_reply":"2021-06-28T21:21:04.540708Z"}}},{"cell_type":"code","source":"df_train_merge.groupby('class').count()['label'].plot(kind='bar',\n                                                      title='class size');","metadata":{"execution":{"iopub.status.busy":"2021-07-01T20:19:38.367988Z","iopub.execute_input":"2021-07-01T20:19:38.368516Z","iopub.status.idle":"2021-07-01T20:19:38.546478Z","shell.execute_reply.started":"2021-07-01T20:19:38.368476Z","shell.execute_reply":"2021-07-01T20:19:38.545537Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Observations on boxes and opacity values\n* Images may have 0 to 8 number of boxes. \n* In training dataset confidence value for opacity is 1.\n* Only class 'negative' does not have any boxes.\n* For all other classes, they may or may not have boxes.\n* Number of boxes in each class is different (see the plot below). For example class 'typical' mostly have 2 boxes.","metadata":{}},{"cell_type":"code","source":"#existence of boxes in each class\ndf_train_merge.groupby(['class','label_op']) \\\n              .count()['id'] \\\n              .unstack() \\\n              .plot(kind='bar',title='Images that contain any number of boxes in each class');","metadata":{"execution":{"iopub.status.busy":"2021-07-01T20:19:38.547985Z","iopub.execute_input":"2021-07-01T20:19:38.548417Z","iopub.status.idle":"2021-07-01T20:19:38.755414Z","shell.execute_reply.started":"2021-07-01T20:19:38.548364Z","shell.execute_reply":"2021-07-01T20:19:38.754528Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Plot number of boxes in each class","metadata":{}},{"cell_type":"code","source":"df=df_train_merge.groupby(['class','label_op','num_box']).count().id.reset_index()\ndf","metadata":{"execution":{"iopub.status.busy":"2021-07-01T20:19:38.759279Z","iopub.execute_input":"2021-07-01T20:19:38.759704Z","iopub.status.idle":"2021-07-01T20:19:38.786110Z","shell.execute_reply.started":"2021-07-01T20:19:38.759663Z","shell.execute_reply":"2021-07-01T20:19:38.785246Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ax=sns.barplot(x=\"class\", y=\"id\", hue=\"num_box\", data=df)\nax.set_ylabel('Count')\nax.set_title('Number of boxes in each class');","metadata":{"execution":{"iopub.status.busy":"2021-07-01T20:19:38.788506Z","iopub.execute_input":"2021-07-01T20:19:38.788870Z","iopub.status.idle":"2021-07-01T20:19:39.112463Z","shell.execute_reply.started":"2021-07-01T20:19:38.788833Z","shell.execute_reply":"2021-07-01T20:19:39.111430Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Import DICOM paths","metadata":{}},{"cell_type":"code","source":"# Get paths to DICOM files\n#It looks like this:\n#set/study/series/image.dcm\n!ls /kaggle/input/siim-covid19-detection/train/00086460a852/9e8302230c91","metadata":{"execution":{"iopub.status.busy":"2021-07-01T20:19:39.113575Z","iopub.execute_input":"2021-07-01T20:19:39.113838Z","iopub.status.idle":"2021-07-01T20:19:39.808902Z","shell.execute_reply.started":"2021-07-01T20:19:39.113812Z","shell.execute_reply":"2021-07-01T20:19:39.807834Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def read_dcm_paths():\n    #this function is taken from https://www.kaggle.com/farhanhaikhan/object-detection-starter-rescale-image-bbox\n    IMG_FORMAT = \".dcm\"\n    IMG_PATHS = []\n    IMAGE_IDS = []\n    IMAGE_NAMES = []\n    SETS = []\n    SERIES = []\n    STUDIES = []\n\n    for dirname, _, filenames in os.walk('/kaggle/input/siim-covid19-detection'):\n        for filename in filenames:\n            if filename.endswith(IMG_FORMAT):\n                img_path = os.path.join(dirname, filename)\n                Splitted = img_path.split('/')\n                # print(Splitted)\n                img_name = Splitted[-1]\n                img_id = img_name[:-4]\n                series_name = Splitted[-2]\n                study_name = Splitted[-3]\n                set_name = Splitted[-4]\n                IMG_PATHS.append(img_path)\n                IMAGE_NAMES.append(img_name)\n                IMAGE_IDS.append(img_id)\n                SETS.append(set_name)\n                SERIES.append(series_name)\n                STUDIES.append(study_name)\n    df_dcm = pd.DataFrame.from_dict({\n                                 \"id\":IMAGE_IDS,\n                                 \"Image_Path\":IMG_PATHS,\n                                 \"Image_Name\":IMAGE_NAMES,\n                                 \"id_set\": SETS,\n                                 \"id_series\":SERIES,\n                                 \"StudyInstanceUID\":STUDIES})\n    return df_dcm","metadata":{"execution":{"iopub.status.busy":"2021-07-01T20:19:39.810538Z","iopub.execute_input":"2021-07-01T20:19:39.810848Z","iopub.status.idle":"2021-07-01T20:19:39.819975Z","shell.execute_reply.started":"2021-07-01T20:19:39.810816Z","shell.execute_reply":"2021-07-01T20:19:39.819067Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_dcm_path = read_dcm_paths()","metadata":{"execution":{"iopub.status.busy":"2021-07-01T20:19:39.821125Z","iopub.execute_input":"2021-07-01T20:19:39.821590Z","iopub.status.idle":"2021-07-01T20:19:49.700289Z","shell.execute_reply.started":"2021-07-01T20:19:39.821557Z","shell.execute_reply":"2021-07-01T20:19:49.699567Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#sanity check\n!ls /kaggle/input/siim-covid19-detection/train/9d514ce429a7/22897cd1daa0\ndf_dcm_path[df_dcm_path['Image_Name']=='0012ff7358bc.dcm']\ndf_dcm_path[df_dcm_path['id']=='0012ff7358bc']\n","metadata":{"execution":{"iopub.status.busy":"2021-07-01T20:19:49.701186Z","iopub.execute_input":"2021-07-01T20:19:49.701583Z","iopub.status.idle":"2021-07-01T20:19:50.399326Z","shell.execute_reply.started":"2021-07-01T20:19:49.701555Z","shell.execute_reply":"2021-07-01T20:19:50.398278Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_dcm_path.head()","metadata":{"execution":{"iopub.status.busy":"2021-07-01T20:19:50.400949Z","iopub.execute_input":"2021-07-01T20:19:50.401327Z","iopub.status.idle":"2021-07-01T20:19:50.414297Z","shell.execute_reply.started":"2021-07-01T20:19:50.401268Z","shell.execute_reply":"2021-07-01T20:19:50.413357Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train_merge.head(5)","metadata":{"execution":{"iopub.status.busy":"2021-07-01T20:19:50.415666Z","iopub.execute_input":"2021-07-01T20:19:50.416011Z","iopub.status.idle":"2021-07-01T20:19:50.440297Z","shell.execute_reply.started":"2021-07-01T20:19:50.415975Z","shell.execute_reply":"2021-07-01T20:19:50.439153Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#fill to 12 characters\ndf_dcm_path['id'] = df_dcm_path['id'].apply(lambda x: (12-len(x))*'0'+x)","metadata":{"execution":{"iopub.status.busy":"2021-07-01T20:19:50.441923Z","iopub.execute_input":"2021-07-01T20:19:50.442303Z","iopub.status.idle":"2021-07-01T20:19:50.453209Z","shell.execute_reply.started":"2021-07-01T20:19:50.442263Z","shell.execute_reply":"2021-07-01T20:19:50.452347Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Merge dicom paths with image information","metadata":{"execution":{"iopub.status.busy":"2021-06-29T22:15:13.942056Z","iopub.execute_input":"2021-06-29T22:15:13.942559Z","iopub.status.idle":"2021-06-29T22:15:13.946614Z","shell.execute_reply.started":"2021-06-29T22:15:13.942516Z","shell.execute_reply":"2021-06-29T22:15:13.945875Z"}}},{"cell_type":"code","source":"df_train_merge_dcm = pd.merge(df_train_merge,df_dcm_path[['id','Image_Path']],on='id',how='left')","metadata":{"execution":{"iopub.status.busy":"2021-07-01T20:19:50.454546Z","iopub.execute_input":"2021-07-01T20:19:50.454889Z","iopub.status.idle":"2021-07-01T20:19:50.474893Z","shell.execute_reply.started":"2021-07-01T20:19:50.454856Z","shell.execute_reply":"2021-07-01T20:19:50.474137Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train_merge_dcm.head()","metadata":{"execution":{"iopub.status.busy":"2021-07-01T20:19:50.476335Z","iopub.execute_input":"2021-07-01T20:19:50.476747Z","iopub.status.idle":"2021-07-01T20:19:50.499483Z","shell.execute_reply.started":"2021-07-01T20:19:50.476708Z","shell.execute_reply":"2021-07-01T20:19:50.498524Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train_merge.shape","metadata":{"execution":{"iopub.status.busy":"2021-07-01T20:19:50.500900Z","iopub.execute_input":"2021-07-01T20:19:50.501259Z","iopub.status.idle":"2021-07-01T20:19:50.509565Z","shell.execute_reply.started":"2021-07-01T20:19:50.501221Z","shell.execute_reply":"2021-07-01T20:19:50.508601Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(df_train_merge['id'].unique())","metadata":{"execution":{"iopub.status.busy":"2021-07-01T20:19:50.510982Z","iopub.execute_input":"2021-07-01T20:19:50.511377Z","iopub.status.idle":"2021-07-01T20:19:50.522194Z","shell.execute_reply.started":"2021-07-01T20:19:50.511338Z","shell.execute_reply":"2021-07-01T20:19:50.521215Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(df_dcm_path['id'].unique())","metadata":{"execution":{"iopub.status.busy":"2021-07-01T20:19:50.523734Z","iopub.execute_input":"2021-07-01T20:19:50.524045Z","iopub.status.idle":"2021-07-01T20:19:50.533293Z","shell.execute_reply.started":"2021-07-01T20:19:50.524016Z","shell.execute_reply":"2021-07-01T20:19:50.532420Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train_merge_dcm.shape","metadata":{"execution":{"iopub.status.busy":"2021-07-01T20:19:50.534439Z","iopub.execute_input":"2021-07-01T20:19:50.534831Z","iopub.status.idle":"2021-07-01T20:19:50.544696Z","shell.execute_reply.started":"2021-07-01T20:19:50.534801Z","shell.execute_reply":"2021-07-01T20:19:50.543785Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Load DICOM fields","metadata":{}},{"cell_type":"code","source":"# this is precalculated\ndf_dicom_data = pd.read_csv('/kaggle/input/read-dicom-info/train_df_dicom_data.csv')","metadata":{"execution":{"iopub.status.busy":"2021-07-01T20:19:50.545905Z","iopub.execute_input":"2021-07-01T20:19:50.546176Z","iopub.status.idle":"2021-07-01T20:19:50.585850Z","shell.execute_reply.started":"2021-07-01T20:19:50.546151Z","shell.execute_reply":"2021-07-01T20:19:50.585230Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_dicom_data.head(5)","metadata":{"execution":{"iopub.status.busy":"2021-07-01T20:19:50.586687Z","iopub.execute_input":"2021-07-01T20:19:50.587010Z","iopub.status.idle":"2021-07-01T20:19:50.605237Z","shell.execute_reply.started":"2021-07-01T20:19:50.586986Z","shell.execute_reply":"2021-07-01T20:19:50.604444Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train_merge_dcm.columns","metadata":{"execution":{"iopub.status.busy":"2021-07-01T20:19:50.606193Z","iopub.execute_input":"2021-07-01T20:19:50.606461Z","iopub.status.idle":"2021-07-01T20:19:50.618261Z","shell.execute_reply.started":"2021-07-01T20:19:50.606432Z","shell.execute_reply":"2021-07-01T20:19:50.617315Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train_merge_dcm.shape","metadata":{"execution":{"iopub.status.busy":"2021-07-01T20:19:50.619223Z","iopub.execute_input":"2021-07-01T20:19:50.619498Z","iopub.status.idle":"2021-07-01T20:19:50.627701Z","shell.execute_reply.started":"2021-07-01T20:19:50.619474Z","shell.execute_reply":"2021-07-01T20:19:50.627116Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train_dcm=pd.merge(df_train_merge_dcm,df_dicom_data[['id', 'Rows', 'Columns', 'PatientID', 'PatientName',\n                                           'PhotometricInterpretation', 'SamplesPerPixel',\n                                           'BitsAllocated', 'BitsStored', 'HighBit', 'PixelRepresentation',\n                                           'ImagerPixelSpacing_X', 'ImagerPixelSpacing_Y', 'ImageType', 'Modality',\n                                           'PatientSex', 'BodyPartExamined']],\n         how='left',on='id')","metadata":{"execution":{"iopub.status.busy":"2021-07-01T20:19:50.628547Z","iopub.execute_input":"2021-07-01T20:19:50.628889Z","iopub.status.idle":"2021-07-01T20:19:50.650701Z","shell.execute_reply.started":"2021-07-01T20:19:50.628864Z","shell.execute_reply":"2021-07-01T20:19:50.649945Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train_dcm.shape","metadata":{"execution":{"iopub.status.busy":"2021-07-01T20:19:50.651827Z","iopub.execute_input":"2021-07-01T20:19:50.652126Z","iopub.status.idle":"2021-07-01T20:19:50.656395Z","shell.execute_reply.started":"2021-07-01T20:19:50.652102Z","shell.execute_reply":"2021-07-01T20:19:50.655665Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train_dcm.head(5)","metadata":{"execution":{"iopub.status.busy":"2021-07-01T20:19:50.659117Z","iopub.execute_input":"2021-07-01T20:19:50.659345Z","iopub.status.idle":"2021-07-01T20:19:50.692129Z","shell.execute_reply.started":"2021-07-01T20:19:50.659323Z","shell.execute_reply":"2021-07-01T20:19:50.691271Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"## Save dataframes\ndf_train_dcm.to_csv('train_df_dcm_merged.csv')","metadata":{"execution":{"iopub.status.busy":"2021-07-01T20:20:09.024540Z","iopub.execute_input":"2021-07-01T20:20:09.025078Z","iopub.status.idle":"2021-07-01T20:20:09.219936Z","shell.execute_reply.started":"2021-07-01T20:20:09.025036Z","shell.execute_reply":"2021-07-01T20:20:09.219210Z"},"trusted":true},"execution_count":null,"outputs":[]}]}