Spaces:
Sleeping
Sleeping
File size: 874 Bytes
9254d49 a04f491 e96ae5d a04f491 0a53bf5 e96ae5d a04f491 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
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 clean_country_code(code):
# Remove non-alphabetical characters and convert to uppercase.
return ''.join(filter(str.isalpha, code)).upper()
def get_country_name(alpha2_code, region_df):
"""Map ISO country code to country name (case-insensitive)."""
# Clean the code before processing.
code = clean_country_code(alpha2_code)
row = region_df[region_df['alpha-2'] == code]
return row['name'].values[0] if not row.empty else 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 |