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/

 

Python -import pandas as pd

import pandas as pd
import numpy as np
%matplotlib inline

pd.core.common.is_list_like=pd.api.types.is_list_like

import pandas_datareader as web
import datetime
start=datetime.datetime(2000,1,1)
end=datetime.datetime(2018,8,30)
gdp=web.DataReader(‘A191RL1Q225SBEA’, ‘fred’, start, end)
inflation = web.DataReader([‘CPIAUCSL’, ‘CPILFESL’], ‘fred’, start, end)

In [148]:

df =inflation[“CPIAUCSL”].pct_change(periods=12)*100

df.plot.line()

Out[148]:

In [134]:

df.plot.hist(alpha=0.5)

Out[134]:

In [136]:

df.plot.box()

Out[136]:

In [140]:

df=df.cumsum()
df.plot()

Out[140]:

In [64]:

import matplotlib.pyplot as plt
import seaborn as sns
import plotly.plotly as py

Pct_Annual=inflation[“CPIAUCSL”].pct_change(periods=12)*100

y=Pct_Annual
N=len(y)
x=range(N)
width=1/1.5
plt.bar(x,y, width, color=”blue”)

Out[64]:

In [150]:

gdp.plot()
df.plot(secondary_y=True, style=’g’)

Out[150]:

In [159]:

plt.figure()
df.plot()

Out[159]:

In [57]:

import pandas as pd
import numpy as np
%matplotlib inline

pd.core.common.is_list_like=pd.api.types.is_list_like

import pandas_datareader as web
import datetime
start=datetime.datetime(2000,1,1)
end=datetime.datetime(2018,8,30)
gdp=web.DataReader(‘A191RL1Q225SBEA’, ‘fred’, start, end)
inflation = web.DataReader([‘CPIAUCSL’, ‘CPILFESL’], ‘fred’, start, end)

gdp.head()
gdp.tail()
inflation.plot()
gdp.plot()

Out[57]: