def get_indicators_df(area_level, id_len=7): path = pf.get_indic(area_level) if not os.path.isfile(path): return None else: df = pd.read_csv(path, encoding="utf-8") df = replace_index(df, id_len) return df
def add_indicator(area_level, indic_name, indicator): indicators = get_or_create_indicators_df(area_level) if type(indicator) == pd.core.series.Series: indicators[indic_name] = indicator elif type(indicator) == dict: indicators[indic_name] = indicators[IDS_GCBA[area_level]].map(indicator) else: raise Exception("Indicator must be dict or ") indicators.to_csv(pf.get_indic(area_level), encoding="utf-8") return indicators
def add_indicator(area_level, indic_name, indicator): indicators = get_or_create_indicators_df(area_level) if type(indicator) == pd.core.series.Series: indicators[indic_name] = indicator elif type(indicator) == dict: indicators[indic_name] = indicators[ IDS_GCBA[area_level]].map(indicator) else: raise Exception("Indicator must be dict or ") indicators.to_csv(pf.get_indic(area_level), encoding="utf-8") return indicators
def add_dbf_indicator_by_id(area_level, context_shp_name, context_id_field, context_indic_field): indicators = get_or_create_indicators_df(area_level) if context_indic_field in indicators.columns: indicators.drop(context_indic_field, 1, inplace=True) dbf = Dbf5(get_context_shp_path(context_shp_name) + ".dbf") context_df = dbf.to_dataframe() context_df.drop_duplicates(context_id_field, inplace=True) context_df.set_index(context_id_field, inplace=True) indicators = indicators.join(context_df[context_indic_field]) indicators.to_csv(pf.get_indic(area_level), encoding="utf-8") return indicators
def add_dbf_indicator_by_id(area_level, context_shp_name, context_id_field, context_indic_field): indicators = get_or_create_indicators_df(area_level) indicators.drop(context_indic_field, 1, inplace=True) dbf = Dbf5(get_context_shp_path(context_shp_name) + ".dbf") context_df = dbf.to_dataframe() context_df.drop_duplicates(context_id_field, inplace=True) context_df.set_index(context_id_field, inplace=True) indicators = indicators.join(context_df[context_indic_field]) indicators.to_csv(pf.get_indic(area_level), encoding="utf-8") return indicators