Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions scripts/us_nces/common/prop_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
While preprocessing files column names are changed to SV names as used in
DC import
"""
import pandas as pd

# TMCF template for Demographics data. It changes based on import name.
TMCF_TEMPLATE = (
"Node: E:us_nces_demographics_{import_name}->E0\n"
Expand Down Expand Up @@ -123,17 +125,25 @@
"School Administrative Support Staff": "Faculty",
"Student Support Services Staff": "Faculty",
"School Psychologist": "Faculty",
"Other Support Services Staff": "Faculty"
"Other Support Services Staff": "Faculty",
"Total Staff": "Faculty"
Comment thread
smarthg-gi marked this conversation as resolved.
}
# One specific column comes under school grade property.
_SCHOOL_GRADE_PROP = {"Ungraded Students": "NCESUngradedClasses"}
# melting the columns based on sv_name column.
MELT_VAR_COL = "sv_name"


def _PV_FORMAT(pv):
"""Formats property-value pairs for MCF nodes; modified based on column."""
t = tuple(pv)
val = str(t[1]).strip() if not pd.isna(t[1]) else ""
if not val or val in ('None', 'nan', '<NA>'):
return ""
return f'"{t[0]}": "dcs:{val}"'


# pylint:disable=unnecessary-lambda-assignment
# Creating property pattern and the pattern is modified if required based on column.
_PV_FORMAT = lambda prop_val: f'"{prop_val[0]}": "dcs:{prop_val[1]}"' \
if 'None' not in prop_val[1] else ""
_UPDATE_MEASUREMENT_DENO = lambda prop: _DENOMINATOR_PROP.get(prop, prop)
_UPDATE_POPULATION_TYPE = lambda prop: _POPULATION_PROP.get(prop, "Student")
_UPDATE_GRADE_LEVEL = lambda prop: _SCHOOL_GRADE_PROP.get(prop, prop)
Expand Down Expand Up @@ -167,7 +177,7 @@
r")")

_SCHOOL_GRADE_PATTERN = (r"("
r"Grade \d{,2}"
r"Grade \d{1,2}"
r"|"
r"Prekindergarten and Kindergarten"
r"|"
Expand Down Expand Up @@ -236,6 +246,8 @@
r"School Psychologist"
r"|"
r"Other Support Services Staff"
r"|"
r"Total Staff"
r")")

_GENDER_PATTERN = (r"("
Expand Down
3 changes: 2 additions & 1 deletion scripts/us_nces/common/replacement_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@
"Phone Number": "PhoneNumber"
}

_GENDER = {"female": "Female", "male": "Male"}
_GENDER = {r"\bfemale\b": "Female", r"\bmale\b": "Male"}

_LOCALE = {
'13-City: Small': "NCES_CitySmall",
Expand Down Expand Up @@ -501,6 +501,7 @@ def replace_values(data_df: pd.DataFrame,
"Agency_Name": _NAN,
"School_Level_17": _SCHOOL_LEVEL,
"School_Level_16": _SCHOOL_LEVEL,
"School_Level": _SCHOOL_LEVEL,
"State_Agency_ID": _NAN,
"State_School_ID": _NAN,
"State_Name": _STATE_NAME
Expand Down
Loading
Loading