Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,20 @@ import streamlit as st
|
|
2 |
import pandas as pd
|
3 |
import plotly.express as px
|
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
country_mapping = {
|
6 |
'United States': 'USA',
|
7 |
'United Kingdom': 'GBR',
|
@@ -143,13 +157,17 @@ def create_country_map(df, title):
|
|
143 |
# Map country names to ISO codes
|
144 |
country_counts['country'] = country_counts['country'].map(country_mapping)
|
145 |
|
|
|
|
|
|
|
146 |
fig = px.choropleth(country_counts,
|
147 |
locations="country",
|
148 |
-
color="
|
149 |
hover_name="country",
|
150 |
title=title,
|
151 |
-
projection="natural earth"
|
152 |
-
|
|
|
153 |
return fig
|
154 |
|
155 |
# Streamlit app
|
|
|
2 |
import pandas as pd
|
3 |
import plotly.express as px
|
4 |
|
5 |
+
def assign_color(count):
|
6 |
+
if count <= 10:
|
7 |
+
return '1-10'
|
8 |
+
elif count <= 50:
|
9 |
+
return '10-50'
|
10 |
+
elif count <= 100:
|
11 |
+
return '50-100'
|
12 |
+
elif count <= 500:
|
13 |
+
return '100-500'
|
14 |
+
elif count <= 1000:
|
15 |
+
return '500-1000'
|
16 |
+
else:
|
17 |
+
return '>1000'
|
18 |
+
|
19 |
country_mapping = {
|
20 |
'United States': 'USA',
|
21 |
'United Kingdom': 'GBR',
|
|
|
157 |
# Map country names to ISO codes
|
158 |
country_counts['country'] = country_counts['country'].map(country_mapping)
|
159 |
|
160 |
+
# Assign color ranges based on counts
|
161 |
+
country_counts['color'] = country_counts['count'].apply(assign_color)
|
162 |
+
|
163 |
fig = px.choropleth(country_counts,
|
164 |
locations="country",
|
165 |
+
color="color",
|
166 |
hover_name="country",
|
167 |
title=title,
|
168 |
+
projection="natural earth",
|
169 |
+
color_discrete_sequence=['#7FFF00', '#FFD700', '#FFA500', '#FF4500', '#DC143C', '#8B0000'],
|
170 |
+
category_orders={"color": ['1-10', '10-50', '50-100', '100-500', '500-1000', '>1000']})
|
171 |
return fig
|
172 |
|
173 |
# Streamlit app
|