GIZ-Project-Search / appStore /region_utils.py
annikwag's picture
Update appStore/region_utils.py
0a53bf5 verified
raw
history blame
720 Bytes
import streamlit as st
import pandas as pd
# Load the region.csv once when the app starts
@st.cache_data
def load_region_data(file_path):
return pd.read_csv(file_path)
def get_country_name(alpha2_code, region_df):
"""Map ISO country code to country name (case-insensitive)."""
alpha2_code = alpha2_code.upper() # Ensure the code is in uppercase
row = region_df[region_df['alpha-2'] == alpha2_code]
return row['name'].values[0] if not row.empty else alpha2_code
def get_regions(region_df):
"""Get unique regions and sub-regions."""
regions = region_df['region'].dropna().unique().tolist()
sub_regions = region_df['sub-region'].dropna().unique().tolist()
return regions, sub_regions