Three Countries: Korea vs Japan vs China

The following codes would generate the charts in python.

import wbdata
import pandas
import matplotlib.pyplot as plt

#set up the countries I want
countries = [“CN”,”KR”,”JP”]

#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’);

 

#set up the countries I want
countries = [“CN”,”KR”,”JP”]

#set up the indicator I want (just build up the dict if you want more than one)
indicators = {‘NY.GDP.MKTP.CD’:’GDP in current US dollars’}

#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(“GDP in current US dollars ($USD)”);
plt.xlabel(‘Date’); plt.ylabel(‘GDP in current US dollars’);

 

import matplotlib.pyplot as plt

pct=dfu[:].pct_change(periods=1)*100
pct.plot()
plt.legend(loc=’best’);
plt.title(“Annual Changes in Current GDP ($USD)”);
plt.xlabel(‘Date’); plt.ylabel(‘Annual Changes’);

Source: https://data.worldbank.org/

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s