Refactor create_hierarchy_dict function to concisely include additional hierarchy levels
Browse files
isco.py
CHANGED
|
@@ -20,19 +20,11 @@ def create_hierarchy_dict(file: str) -> dict:
|
|
| 20 |
with open(file, newline="") as csvfile:
|
| 21 |
reader = csv.DictReader(csvfile)
|
| 22 |
for row in reader:
|
| 23 |
-
# Extract unit group level code (4 digits)
|
| 24 |
unit_code = row["unit"].zfill(4)
|
| 25 |
-
|
| 26 |
-
# Extract the parent code for the unit group level, which is the minor group level (3 digits)
|
| 27 |
minor_code = unit_code[0:3]
|
| 28 |
-
|
| 29 |
-
# Add the unit code to the hierarchy with its parent code
|
| 30 |
-
isco_hierarchy[unit_code] = {minor_code}
|
| 31 |
-
|
| 32 |
-
# Additionally, we can add the parent's parent codes at the sub-major group level (2 digits) and major group level (1 digit)
|
| 33 |
sub_major_code = unit_code[0:2]
|
| 34 |
major_code = unit_code[0]
|
| 35 |
-
isco_hierarchy[unit_code]
|
| 36 |
|
| 37 |
return isco_hierarchy
|
| 38 |
|
|
|
|
| 20 |
with open(file, newline="") as csvfile:
|
| 21 |
reader = csv.DictReader(csvfile)
|
| 22 |
for row in reader:
|
|
|
|
| 23 |
unit_code = row["unit"].zfill(4)
|
|
|
|
|
|
|
| 24 |
minor_code = unit_code[0:3]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
sub_major_code = unit_code[0:2]
|
| 26 |
major_code = unit_code[0]
|
| 27 |
+
isco_hierarchy[unit_code] = {minor_code, major_code, sub_major_code}
|
| 28 |
|
| 29 |
return isco_hierarchy
|
| 30 |
|