Skip to content

Instantly share code, notes, and snippets.

@tgherzog
Created January 16, 2020 18:35
Show Gist options
  • Save tgherzog/b05810f61ebc35c305b033b44712cf19 to your computer and use it in GitHub Desktop.
Save tgherzog/b05810f61ebc35c305b033b44712cf19 to your computer and use it in GitHub Desktop.
# Run this in a Jupyter Notebook
import wbgapi as wb
import pandas as pd
from pyquery import PyQuery # JQuery for Python, sort of
pd.options.display.max_rows = 300
# scrape a list of UN member states
member_names = []
doc = PyQuery('https://www.un.org/en/member-states/', verify=False)
for elem in doc('span.member-state-name'):
if len(elem.text):
member_names.append(elem.text)
codes = wb.economy.lookup(member_names)
# and show in a frame
economies = {row['id']: row['value'] for row in wb.economy.list()}
member_codes = [codes[x] for x in member_names]
wbg_names = [economies.get(x) for x in member_codes]
df = pd.DataFrame({'un_member_name': member_names, 'wbg_name': wbg_names, 'iso3': member_codes})
df[df['un_member_name']!= df['wbg_name']]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment