-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathMaddison_data_input.py
70 lines (59 loc) · 1.85 KB
/
Maddison_data_input.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
"""
Maddison project
Long histories of GDP per person
Links
http://www.ggdc.net/maddison/maddison-project/home.htm
http://www.ggdc.net/maddison/maddison-project/data.htm
Prepared for Data Bootcamp course at NYU
* https://github.com/NYUDataBootcamp/Materials
* https://github.com/NYUDataBootcamp/Materials/Code/Lab
Written by Dave Backus, January 2016
Created with Python 3.5
"""
"""
import packages, check versions
"""
import sys
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
#import matplotlib.pyplot as plt
print('\nPython version: ', sys.version)
print('Pandas version: ', pd.__version__, '\n')
"""
read data from internet source
"""
url = 'http://www.ggdc.net/maddison/maddison-project/data/mpd_2013-01.xlsx'
mpd = pd.read_excel(url, skiprows=2, index_col=0, na_values=[' '])
# strip trailing blanks in country names
# use comprehension instead? string methods?
mpd.columns = map(str.rstrip, mpd.columns)
print('Dataframe dimensions:', mpd.shape)
#%%
# select countries
countries = ['England/GB/UK', 'USA', 'Japan', 'China', 'India', 'Argentina']
mpd = mpd[countries]
mpd = mpd.rename(columns={'England/GB/UK': 'UK'})
mpd = np.log(mpd)/np.log(2)
#%%
"""
log base-2 plot
"""
subset = mpd.dropna().copy()
fig, ax = plt.subplots()
subset.plot(lw=2, ax=ax)
ax.set_title('GDP per person', fontsize=14, loc='left')
ax.set_ylabel('GDP Per Capita (1990 USD, log2 scale)')
# legend parameters: http://matplotlib.org/users/customizing.html
ax.legend(loc='upper left', fontsize=10, handlelength=2, labelspacing=0.15)
#fig.savefig('Maddison-GDP-1870-on.pdf', bbox_inches='tight')
#%%
"""
UK plot
"""
fig, ax = plt.subplots()
mpd['UK'].dropna().plot(lw=2, ax=ax)
ax.set_title('GDP per person in the UK', fontsize=14, loc='left')
ax.set_ylabel('GDP Per Capita (1990 USD, log2 scale)')
fig = ax.get_figure()
#fig.savefig('Maddison-GDP-1870-on.pdf', bbox_inches='tight')