diff --git a/apps/wizard/app_pages/fasttrack/process.py b/apps/wizard/app_pages/fasttrack/process.py index b634e12ed6f..8f78ac1f5ac 100644 --- a/apps/wizard/app_pages/fasttrack/process.py +++ b/apps/wizard/app_pages/fasttrack/process.py @@ -44,11 +44,13 @@ def processing_part_1(import_method, dataset_uris, infer_metadata, is_private, _ else: raise ValueError(f"Unknown import method: {import_method}") - # PROCES + # PROCESS if infer_metadata: st.write("Inferring metadata...") data, variables_meta_dict = _infer_metadata(data, variables_meta_dict) + data = _convert_percentages(data, variables_meta_dict) + # VALIDATION st.write("Validating data and metadata...") success = _validate_data(data, variables_meta_dict) @@ -145,6 +147,14 @@ def processing_part_2(data, dataset_meta, variables_meta_dict, origin, dataset_u return fast_import +def _convert_percentages(data: pd.DataFrame, variables_meta_dict: Dict[str, VariableMeta]) -> pd.DataFrame: + """Convert percentages to numbers.""" + for col in data.columns: + if getattr(variables_meta_dict.get(col, {}), "unit", "") == "%": + data[col] = data[col].str.replace("%", "").astype(float) + return data + + def _validate_data(df: pd.DataFrame, variables_meta_dict: Dict[str, VariableMeta]) -> bool: errors = []