diff --git a/coordinator/ProcessorSurveyUtils.py b/coordinator/ProcessorSurveyUtils.py index bfa5a8e5bb7fa71fbd5d983b4f5b613cc35bc9b7..4da2ecc01c4f60c0177def7a2ac6165349b45cd3 100644 --- a/coordinator/ProcessorSurveyUtils.py +++ b/coordinator/ProcessorSurveyUtils.py @@ -74,11 +74,23 @@ def parse_date(series,name_out='date',fmt_in = '%Y-%m-%d',fmt_out= '%b %d, %Y'): return s_out +def parse_cases(series, name_out, cases, dtype = None): + if dtype is None: + dtype = series.dtype + # Converting entries according to a cases dictionary + series_out = series.map(cases).astype(dtype) + + # Renaming series + series_out.rename(name_out,inplace=True) + + return series_out + # dict of functions callable within coln_parser_dict # so they can be obtained with a string in coln_parser_dict func_dict = { 'parse_date' : parse_date, - 'parse_location_kobotoolbox' : parse_location_kobotoolbox + 'parse_location_kobotoolbox' : parse_location_kobotoolbox, + 'parse_cases' : parse_cases } def parse_columns(df_in,coln_parser_dict):