forked from HoloClean/holoclean
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.py
More file actions
28 lines (22 loc) · 694 Bytes
/
Copy pathutils.py
File metadata and controls
28 lines (22 loc) · 694 Bytes
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
# Some constants.
# How we represent nulls in holoclean.
NULL_REPR = '_nan_'
# A feature value to represent co-occurrence with NULLs, which is not applicable.
NA_COOCCUR_FV = 0
def dictify_df(frame):
"""
dictify_df converts a frame with columns
col1 | col2 | .... | coln | value
...
to a dictionary that maps values valX from colX
{ val1 -> { val2 -> { ... { valn -> value } } } }
"""
ret = {}
for row in frame.values:
cur_level = ret
for elem in row[:-2]:
if elem not in cur_level:
cur_level[elem] = {}
cur_level = cur_level[elem]
cur_level[row[-2]] = row[-1]
return ret