-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSetDiagCodes.py
More file actions
52 lines (48 loc) · 1.82 KB
/
SetDiagCodes.py
File metadata and controls
52 lines (48 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
def create_map():
## List of tuples with name and number of repititons.
name_list = [('infections', 139),
('neoplasms', (239 - 139)),
('endocrine', (279 - 239)),
('blood', (289 - 279)),
('mental', (319 - 289)),
('nervous', (359 - 319)),
('sense', (389 - 359)),
('circulatory', (459-389)),
('respiratory', (519-459)),
('digestive', (579 - 519)),
('genitourinary', (629 - 579)),
('pregnancy', (679 - 629)),
('skin', (709 - 679)),
('musculoskeletal', (739 - 709)),
('congenital', (759 - 739)),
('perinatal', (779 - 759)),
('ill-defined', (799 - 779)),
('injury', (999 - 799))]
## Loop over the tuples to create a dictionary to map codes
## to the names.
out_dict = {}
count = 1
for name, num in name_list:
for i in range(num):
out_dict.update({str(count): name})
count += 1
return out_dict
def map_codes(df, codes):
import pandas as pd
col_names = df.columns.tolist()
for col in col_names:
temp = []
for num in df[col]:
if ((num is None) | (num in ['unknown', '?']) | (pd.isnull(num))): temp.append('unknown')
elif(num.upper()[0] == 'V'): temp.append('supplemental')
elif(num.upper()[0] == 'E'): temp.append('injury')
else:
lkup = num.split('.')[0]
temp.append(codes[lkup])
df.loc[:, col] = temp
return df
def azureml_main(df):
col_list = ['diag_1', 'diag_2', 'diag_3']
codes = create_map()
df[col_list] = map_codes(df[col_list], codes)
return df