Spaces:
Running
Running
Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -42,16 +42,25 @@ def load_data():
|
|
| 42 |
# Ensure department is integer
|
| 43 |
df['birth_department'] = df['birth_department'].astype(int)
|
| 44 |
|
| 45 |
-
# Parse
|
| 46 |
def parse_list_field(x):
|
|
|
|
|
|
|
| 47 |
if isinstance(x, list):
|
| 48 |
return x
|
| 49 |
if isinstance(x, str):
|
|
|
|
|
|
|
| 50 |
try:
|
| 51 |
-
|
|
|
|
| 52 |
except:
|
| 53 |
return []
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
df['nationalities'] = df['nationalities'].apply(parse_list_field)
|
| 57 |
df['diaspora_countries'] = df['diaspora_countries'].apply(parse_list_field)
|
|
@@ -170,9 +179,10 @@ def main():
|
|
| 170 |
st.metric("Dual Nationals", f"{dual_pct:.1f}%", help="Players with 2+ citizenships recorded in Wikidata.")
|
| 171 |
|
| 172 |
with col3:
|
| 173 |
-
|
|
|
|
| 174 |
african_diaspora_pct = (african_diaspora_count / len(filtered_df) * 100) if len(filtered_df) > 0 else 0
|
| 175 |
-
st.metric("African Diaspora*", f"{african_diaspora_pct:.1f}%", help="
|
| 176 |
|
| 177 |
with col4:
|
| 178 |
if len(filtered_df) > 0:
|
|
|
|
| 42 |
# Ensure department is integer
|
| 43 |
df['birth_department'] = df['birth_department'].astype(int)
|
| 44 |
|
| 45 |
+
# Parse list fields - handle string, list, and numpy array formats
|
| 46 |
def parse_list_field(x):
|
| 47 |
+
if x is None:
|
| 48 |
+
return []
|
| 49 |
if isinstance(x, list):
|
| 50 |
return x
|
| 51 |
if isinstance(x, str):
|
| 52 |
+
if x == '[]' or x == '':
|
| 53 |
+
return []
|
| 54 |
try:
|
| 55 |
+
result = eval(x)
|
| 56 |
+
return result if isinstance(result, list) else []
|
| 57 |
except:
|
| 58 |
return []
|
| 59 |
+
# Handle numpy arrays or other iterables
|
| 60 |
+
try:
|
| 61 |
+
return list(x)
|
| 62 |
+
except:
|
| 63 |
+
return []
|
| 64 |
|
| 65 |
df['nationalities'] = df['nationalities'].apply(parse_list_field)
|
| 66 |
df['diaspora_countries'] = df['diaspora_countries'].apply(parse_list_field)
|
|
|
|
| 179 |
st.metric("Dual Nationals", f"{dual_pct:.1f}%", help="Players with 2+ citizenships recorded in Wikidata.")
|
| 180 |
|
| 181 |
with col3:
|
| 182 |
+
african_regions = ['Sub-Saharan Africa', 'Maghreb', 'Comoros']
|
| 183 |
+
african_diaspora_count = len(filtered_df[filtered_df['diaspora_region'].isin(african_regions)])
|
| 184 |
african_diaspora_pct = (african_diaspora_count / len(filtered_df) * 100) if len(filtered_df) > 0 else 0
|
| 185 |
+
st.metric("African Diaspora*", f"{african_diaspora_pct:.1f}%", help="Includes Sub-Saharan Africa, Maghreb, Comoros. Based on citizenship only.")
|
| 186 |
|
| 187 |
with col4:
|
| 188 |
if len(filtered_df) > 0:
|