Skip to content

Instantly share code, notes, and snippets.

@arshamg
Last active May 17, 2020 04:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arshamg/33fe4283d174d0b8a6202074f042024f to your computer and use it in GitHub Desktop.
Save arshamg/33fe4283d174d0b8a6202074f042024f to your computer and use it in GitHub Desktop.
How to make a choropleth
Afghanistan https://president.gov.af/
Albania http://www.parlament.al/
Algeria http://www.cg.gov.dz/
Andorra https://www.govern.ad/
Angola http://www.governo.gov.ao/
Antigua and Barbuda https://ab.gov.ag/
Argentina https://www.casarosada.gob.ar/
Armenia http://www.gov.am
Australia https://www.gov.au/
Austria https://www.bundeskanzleramt.gv.at/
Azerbaijan https://president.az/
Bahamas http://www.bahamas.gov.bs
Bahrain https://www.bahrain.bh
Bangladesh https://bangladesh.gov.bd
Barbados https://www.gov.bb/
Belarus http://www.president.gov.by/
Belgium https://www.belgium.be
Belize http://www.belize.gov.bz/
Benin https://www.gouv.bj/
Bhutan http://www.bhutan.gov.bt/
Bolivia https://bolivia.gob.bo/
Bosnia and Herzegovina http://www.fbihvlada.gov.ba
Botswana http://www.gov.bw/
Brazil http://www.brasil.gov.br/
Brunei https://www.gov.bn
Bulgaria http://www.gov.bg
Burkina Faso http://www.gouvernement.gov.bf/
Burundi http://burundi.gov.bi/
Cambodia http://information.gov.kh/
Cameroon https://www.prc.cm
Canada https://www.canada.ca
Cape Verde http://www.governo.cv/
Central African Republic https://www.rca-gouv.net/
Chad http://www.gouvernement.td/
Chile https://www.gob.cl
China http://www.gov.cn
Colombia https://presidencia.gov.co
Comoros http://www.beit-salam.km/
Congo (Brazzaville) http://www.presidence.cg
Congo (Kinshasa) http://www.presidentrdc.cd/
Costa Rica https://presidencia.go.cr
Croatia https://vlada.gov.hr
Cuba http://www.minrex.gob.cu
Cyprus http://www.cyprus.gov.cy
Czech Republic https://www.vlada.cz
Denmark https://denmark.dk/
Djibouti https://www.presidence.dj/
Dominica http://dominica.gov.dm/
Dominican Republic https://presidencia.gob.do/
Ecuador https://www.presidencia.gob.ec/
Egypt http://www.egypt.gov.eg
El Salvador http://www.presidencia.gob.sv
Equatorial Guinea https://www.guineaecuatorialpress.com
Eritrea http://www.shabait.com/
Estonia https://www.valitsus.ee
Ethiopia http://www.ethiopia.gov.et/
Fiji http://www.fiji.gov.fj/
Finland https://valtioneuvosto.fi
France https://www.gouvernement.fr
Gabon http://www.gouvernement.ga
Gambia http://assembly.gov.gm/
Georgia http://gov.ge
Germany https://www.bundesregierung.de
Ghana http://www.ghana.gov.gh/
Greece https://www.hellenicparliament.gr
Grenada https://www.gov.gd/
Guatemala https://www.presidencia.gob.gt/
Guinea http://www.presidence.gov.gn/
Guinea-Bissau http://www.guinebissaurepublic.com/
Guyana https://motp.gov.gy/
Haiti http://primature.gouv.ht/
Honduras https://www.presidencia.gob.hn/
Hungary http://www.kormany.hu
Iceland https://www.government.is/
India https://www.india.gov.in/
Indonesia https://indonesia.go.id/
Iran http://www.president.ir/en
Iraq https://gds.gov.iq/
Ireland https://www.gov.ie
Israel https://www.gov.il
Italy http://www.governo.it/
Ivory Coast http://www.gouv.ci/
Jamaica https://www.gov.jm/
Japan https://www.japan.go.jp/
Jordan https://jordan.gov.jo
Kazakhstan http://government.kz
Kenya http://www.parliament.go.ke/
Kiribati http://www.president.gov.ki/
Kosovo http://www.assembly-kosova.org/
Kuwait https://www.e.gov.kw
Kyrgyzstan http://www.gov.kg/
Laos http://www.laogov.gov.la
Latvia https://www.mk.gov.lv
Lebanon https://www.lp.gov.lb/
Lesotho https://www.gov.ls/
Liberia https://www.emansion.gov.lr/
Libya http://www.pm.gov.ly
Liechtenstein https://www.fuerstenhaus.li
Lithuania https://lrv.lt/
Luxembourg https://gouvernement.lu/
Macedonia https://vlada.mk
Madagascar http://www.presidence.gov.mg/
Malawi http://www.malawi.gov.mw/
Malaysia https://www.malaysia.gov.my/
Maldives https://presidency.gov.mv/
Mali http://www.primature.gov.ml
Malta https://www.gov.mt
Marshall Islands https://rmiparliament.org
Mauritania http://www.primature.gov.mr
Mauritius http://www.govmu.org/
Mexico https://www.gob.mx
Micronesia https://www.fsmgov.org/
Moldova https://gov.md/
Monaco http://en.gouv.mc/
Mongolia https://zasag.mn
Montenegro http://www.gov.me
Morocco http://www.maroc.ma
Mozambique http://www.portaldogoverno.gov.mz/
Myanmar http://www.president-office.gov.mm
Namibia https://gov.na/
Nauru http://www.naurugov.nr/
Nepal https://www.nepal.gov.np/
Netherlands https://www.government.nl/
New Zealand https://www.govt.nz/
Nicaragua https://www.asamblea.gob.ni/
Niger https://www.presidence.ne/
Nigeria http://www.nigeria.gov.ng/
North Korea http://www.korea-dpr.com/
Norway https://www.regjeringen.no
Oman https://omanportal.gov.om
Pakistan http://www.pakistan.gov.pk/
Palau https://www.palaugov.pw/
Panama https://www.presidencia.gob.pa
Papua New Guinea http://www.pm.gov.pg/
Paraguay https://www.paraguay.gov.py/
Peru https://www.peru.gob.pe/
Philippines https://www.gov.ph/
Poland https://www.polska.pl/
Portugal https://www.portugal.gov.pt
Qatar https://www.gov.qa/
Romania http://gov.ro
Russia http://government.ru
Rwanda http://www.gov.rw
Saint Kitts and Nevis https://www.gov.kn/
Saint Lucia http://www.govt.lc/
Saint Vincent and the Grenadines http://www.gov.vc/
Samoa http://www.samoagovt.ws/
San Marino http://www.sanmarino.sm
Sao Tome and Principe http://www.presidencia.st/
Saudi Arabia https://www.saudi.gov.sa/
Senegal https://www.sec.gouv.sn/
Serbia https://www.predsednik.rs/
Seychelles http://www.egov.sc/
Sierra Leone https://statehouse.gov.sl/
Singapore https://www.gov.sg/
Slovakia https://www.vlada.gov.sk/
Slovenia http://www.vlada.si
Solomon Islands http://www.parliament.gov.sb/
Somalia https://www.villasomalia.gov.so/
South Africa https://www.gov.za/
South Korea http://www.korea.net
South Sudan http://www.goss-online.org/
Spain http://www.lamoncloa.gob.es
Sri Lanka https://www.gov.lk/
Sudan http://www.presidency.gov.sd
Suriname http://www.gov.sr/
Swaziland http://www.gov.sz/
Sweden https://www.government.se/
Switzerland https://www.admin.ch
Syria http://www.egov.sy
Taiwan https://www.taiwan.gov.tw/
Tajikistan http://www.president.tj
Tanzania https://www.tanzania.go.tz/
Thailand http://www.mfa.go.th
Timor-Leste http://timor-leste.gov.tl
Togo https://www.republicoftogo.com
Tonga http://mic.gov.to/
Trinidad and Tobago http://www.ttconnect.gov.tt
Tunisia http://www.pm.gov.tn
Turkey http://www.mfa.gov.tr
Turkmenistan https://www.mfa.gov.tm
Tuvalu https://tuvalugovernment.tv/
Uganda https://www.gou.go.ug/
Ukraine https://www.kmu.gov.ua
United Arab Emirates https://www.government.ae
United Kingdom https://www.gov.uk/
United States https://www.whitehouse.gov/
Uruguay https://www.gub.uy/
Uzbekistan https://www.gov.uz
Vanuatu https://www.gov.vu
Vatican City http://www.vaticanstate.va
Venezuela http://www.presidencia.gob.ve/
Vietnam http://chinhphu.vn
Yemen http://www.yemen.gov.ye
Zambia http://www.parliament.gov.zm/
Zimbabwe http://www.zim.gov.zw/
import pandas as pd
import plotly.express as px
import pycountry
def plot_chloropleth(csv_path):
data = pd.read_csv(csv_path, names=['country', 'url'])
data['country_iso'] = 'XXX'
data['length'] = 0
data['short_domain'] = 'XXX'
for index, row in data.iterrows():
try:
# Search for three-letter country code
country_search = pycountry.countries.search_fuzzy(row['country'])
data.at[index,'country_iso'] = country_search[0].alpha_3
except:
pass
temp_url = row['url']
if 'http://' in temp_url:
temp_url = temp_url.replace('http://', '')
if 'https://' in temp_url:
temp_url = temp_url.replace('https://', '')
if 'www.' in temp_url:
temp_url = temp_url.replace('www.', '')
if '/' in temp_url:
temp_url = temp_url.replace('/', '')
data.at[index,'length'] = len(temp_url)
data.at[index,'short_domain'] = temp_url
fig = px.choropleth(data, locations="country_iso", # use our three-letter ISO codes as the locations
color="length", # color the map by length
hover_name="country",
hover_data=['length', 'short_domain'], # add the character length and short_url as hover information
labels={'length': 'Characters'}, # change the display name for length to Characters
color_continuous_scale=px.colors.sequential.Brwnyl) # We'll use a brown-yellow colour palette
fig.update_layout(
title_text='Number of characters in government website domain name',
legend_title_text='Characters'
)
fig.show()
plot_chloropleth('country-websites.csv')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment