-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotter_3.py
More file actions
35 lines (25 loc) · 786 Bytes
/
plotter_3.py
File metadata and controls
35 lines (25 loc) · 786 Bytes
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
27
28
29
30
31
32
33
34
35
import pandas as pd
import plotly.express as px
import pycountry
df = pd.read_csv("preprocessed_full.csv")
df_grouped = df.groupby('country').size().reset_index(name='count')
def alpha2_to_alpha3(code):
try:
return pycountry.countries.get(alpha_2=code).alpha_3
except:
return None
df_grouped['country_list'] = df_grouped['country'].apply(alpha2_to_alpha3)
print(df_grouped)
df_grouped = df_grouped.dropna(subset=['country_list'])
# Plot using Alpha-3 codes
fig = px.choropleth(
df_grouped,
locations="country_list",
color="count",
hover_name="country",
color_continuous_scale="Reds",
title="Location-wise Heatmap of Activity"
)
fig.write_image("countries_with_risk.jpeg", scale=2)
fig.update_geos(showcountries=True)
fig.show()