Last active
May 5, 2017 03:11
-
-
Save fmasanori/da0520a5a4a74d9f8dd06773dedc60f1 to your computer and use it in GitHub Desktop.
Acessa o Banco Mundial via api wb_data, plota o gráfico comparando três países segundo o GNI
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
#baseado em https://blogs.worldbank.org/opendata/accessing-world-bank-data-apis-python-r-ruby-stata | |
import wbdata | |
import matplotlib.pyplot as plt | |
#set up the countries I want | |
countries = ["CL","UY","BR"] | |
#set up the indicator I want (just build up the dict if you want more than one) | |
indicators = {'NY.GNP.PCAP.CD':'GNI per Capita'} | |
#grab indicators above for countires above and load into data frame | |
df = wbdata.get_dataframe(indicators, country=countries, convert_date=False) | |
#df is "pivoted", pandas' unstack fucntion helps reshape it into something plottable | |
dfu = df.unstack(level=0) | |
# a simple matplotlib plot with legend, labels and a title | |
dfu.plot() | |
plt.legend(loc='best') | |
plt.title("GNI Per Capita ($USD, Atlas Method)") | |
plt.xlabel('Date') | |
plt.ylabel('GNI Per Capita ($USD, Atlas Method') | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment