Created
January 16, 2020 18:35
-
-
Save tgherzog/b05810f61ebc35c305b033b44712cf19 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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