diff --git a/src/mapping/mapping_helpers.py b/src/mapping/mapping_helpers.py index ddd44334c..9c485fae7 100644 --- a/src/mapping/mapping_helpers.py +++ b/src/mapping/mapping_helpers.py @@ -218,3 +218,30 @@ def create_additional_ni_cols(ni_full_responses: pd.DataFrame, config: dict) -> ni_full_responses["itl"] = config["mappers"]["ni_itl"] return ni_full_responses + + +def add_area_columns(df): + """ + Add area columns to the dataframe bassed on ITL121NM column. + + Args: + df (pd.DataFrame): The dataframe to add the area columns to. + + Returns: + pd.DataFrame: The dataframe with the area columns added. + """ + area_dict = {'South East (England)': 'select', + 'East': 'select', + 'London': 'select', + 'West Midlands (England)': 'other', + 'Wales': 'other', + 'North East (England)': 'other', + 'East Midlands (England)': 'other', + 'Yorkshire and The Humber': 'other', + 'Scotland': 'other', + 'South West (England)': 'other', + 'North West (England)': 'other'} + + df['area'] = df['ITL121NM'].map(area_dict) + + return df diff --git a/src/mapping/mapping_main.py b/src/mapping/mapping_main.py index c83a8d75b..c0eb68465 100644 --- a/src/mapping/mapping_main.py +++ b/src/mapping/mapping_main.py @@ -111,6 +111,10 @@ def run_mapping( full_responses, postcode_mapper, itl_mapper, config ) + # add area column if PNP + if config["survey"]["survey_type"] == "PNP": + full_responses = hlp.add_area_columns(full_responses) + # Process the NI full responses if they exist if not ni_full_responses.empty: ni_full_responses = hlp.create_additional_ni_cols(ni_full_responses, config)