-
Notifications
You must be signed in to change notification settings - Fork 4
/
world_labor_force.py
52 lines (44 loc) · 1.33 KB
/
world_labor_force.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
# Author: Bojan G. Kalicanin
# Date: 27-Dec-2016
# World Labor Force analysis.
import csv
from country_codes import get_country_code
from pygal.maps.world import World
from pygal.style import RotateStyle, LightColorizedStyle
with open('labor_force.csv', 'r') as f_obj:
reader = csv.reader(f_obj)
for i in range(5):
header_row = next(reader)
lf_data = {}
for row in reader:
try:
country_name = row[0]
#country_code = row[1]
lf_value = int(row[54])
except ValueError:
print(country_name + ': missing_data')
else:
lf_data[country_name] = lf_value
cc_lf = {}
for country, value in lf_data.items():
code = get_country_code(country)
if code:
cc_lf[code] = value
else:
print('ERROR - ' + country_name)
cc_lf_1, cc_lf_2, cc_lf_3 = {}, {}, {}
for key, value in cc_lf.items():
if value < 5000000:
cc_lf_1[key] = value
elif value < 50000000:
cc_lf_2[key] = value
else:
cc_lf_3[key] = value
print(len(cc_lf_1), len(cc_lf_2), len(cc_lf_3))
wm_style = RotateStyle('#556677', base_style=LightColorizedStyle)
wm = World(style=wm_style)
wm.title = 'Labor force by Country (year: 2010)'
wm.add('0-5m', cc_lf_1)
wm.add('5m-50m', cc_lf_2)
wm.add('>50m', cc_lf_3)
wm.render_to_file('world_labor_force.svg')