본문 바로가기

Python Programming/Projects

국가 및 연도 별 총생산량(GDP)과 1인당 GDP에 대한 비교분석(1)

 

 

I. 데이터분석 목적

1) 목적

연도별 각 국가의 GDP 및 1인당 GDP 데이터를 통해,

크게 아래의 세 가지를 주제로 비교분석할 것이다. 

* 특정 시점의 1인당 GDP에 대한 국가 간 횡단면 비교

* 한 국가의 성장을 나타내는 1인당 GDP의 시계열 분석

* 총생산량과 1인당 GDP 규모 간의 연관성 유무 분석

2) 얻고자 하는 Value

* 1970년과 2019년의 국가 별 1인당 GDP 차이, 성장 수준 비교

* 각 대륙 별 대표 국가의 1인당 GDP 변화 비교

* 각 대륙 별 대표 국가의 총생산량 변화 비교

 

총생산량이 높은 국가가 1인당 GDP도 높을까?

1인당 GDP가 높은 대륙/국가? 총생산량이 높은 대륙/국가?

 

II. 입력 데이터

한국은행에서 제공하는 경제통계 시스템을 활용하여 각 나라의 연도 별 GDP에 대한 정보를 불러왔다. GDP 외에도 물가, 금리, 통화량 등 정말 많은 지표들이 데이터로 공개되어 있어서 우리나라 경제와 관련된 분석을 할 때 여러 가지 상황에서 유용하게 활용할 수 있을 것 같다. 

 

* 한국은행 경제통계시스템

 

* 1970년 ~ 2019년 국가별 1인당 GDP

 

* 1970년 ~ 2019년 국가별 총생산량

 

 

III. 데이터 가시화를 위해 선택한 그래프

1) Scatter Plot with Different Sized Dots

1970년에서 2019년까지 각 나라의 성장 수준을 비교하고자 하므로, 각 나라의 1인당 GDP 규모를 비교할 것이다. 

1970년과 2019년의 1인당 GDP 변화를 국가 별로 비교하고 각 변화의 크기를 비교하고자 하므로, 점의 크기를 달리 조절한 Scatter Plot을 선택하였다. (구글에 검색해 보니 "scatter plot with different sized dots" 라고 많이들 표현하는 것 같다. )

Scatter Plot을 사용한다면, 점의 위치를 통해 각 나라의 1인당 GDP 규모도 한 눈에 대략적으로 비교할 수 있을 것이다. 

2) Line Graph

2019년을 기준으로 각 대륙 별 1인당 GDP가 가장 높은 2개 국가의 시계열 데이터를 모두 추출하여 비교할 것이다. 

여러 나라의 오랜 시간에 걸친 총생산량과 1인당 GDP 변화를 보여주고자 하므로 같은 scale 내에서 비교 가능하며 시계열 분석에 적절한 꺾은선 그래프(Line Graph) 선택하였다. 

 

IV. 주요 구현 코드

이 분석에서는 Hadoop의 Pigstorage 시스템과 Python의 Matplotlib을 동시에 활용하였다. Pigstorage 을 활용하여 CLI 환경에서 엑셀데이터를 정제한 후, 해당 파일을 주피터로 불러왔다. SQL 언어는 처음 사용해 보았는데, 문법과 단어가 정말 직관적이고 복잡하지 않아서 앞으로 익숙해지기만 한다면 유용하게 활용할 수 있을 것 같다. 

 

1) Hadoop (Sandbox)

 

Hadoop 환경

 

Hadoop 환경

 

2) Matplotlib 구현 코드

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
import csv
import matplotlib.pyplot as plt
import math
 
= open('C:\빅데이터컴퓨팅\part-m-00000', encoding = 'utf-8')
data = csv.reader(f)
next(data)
gdp_2009 = [] 
gdp_2019 = []
country = []
size = [] #size of bubble
color = [] #color of bubble
 
for row in data:
    if (row[1!= ''& (row [2!= ''):
        development = (float(row[2]) - float(row[1]))/10 
                #divided by 10 in order to control the size of circle on graph
        country.append(row[0]) 
                #name of the countries
        gdp_2009.append(float(row[1])) 
                #gdp per capita of 2009
        gdp_2019.append(float(row[2])) 
                #gdp per capita of 2019
        size.append(abs(development)) 
                #absolute value of the difference of gdp per capita within 10 years
        if development > 0:
            color.append('skyblue'
                #increased GDP per capita compared to 2019
        else:
            color.append('lightpink'
                #decreased GDP per capita compared to 2009
 
 
plt.style.use('ggplot')
plt.rc('font', family = 'Malgun Gothic')
plt.rcParams['figure.figsize'= (15,13)
plt.plot([0,0],[100000,100000])
plt.scatter(gdp_2009, gdp_2019, s = size, c = color)
 
for (i, x, y) in zip(country, gdp_2009, gdp_2019):
    plt.annotate(i, (x, y),
                fontsize = 10,
                textcoords = 'offset points'#how to position the texts
                xytext = (05), #distance from texts to points
                )
    
plt.tight_layout(rect = [00.0310.95])   #weaken point overlapping 
 
plt.title('GDP per capita in 2009 and 2019 by country', fontsize = 30, fontweight = 'bold')
plt.xlabel('GDP per capita by country in 2009', fontsize = 20, fontweight = 'bold')
plt.ylabel('GDP per capita by country in 2019', fontsize = 20, fontweight = 'bold')
plt.show()
cs

 

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
import csv
import matplotlib.pyplot as plt
import math
 
= open('C:\빅데이터컴퓨팅\part-r-00000', encoding = 'utf-8')
data = csv.reader(f)
next(data)
continent = []
country = []
gdp = []
gdp_total = []
color = []
for i in range(11):
    gdp.append([])
for i in range(11):
    gdp_total.append([])
num = 0
for row in data:
    continent.append(row[0])
    country.append(row[1])
    
    for i in range(251):  #store gdp of 1970 ~ 2019 in each list
        if row[i] == '':
            row[i] = 'nan' #put nan for empty datas
        if row[i+53== '':
            row[i+53= 'nan'
        gdp[num].append(float(row[i])) #change each string to float
        gdp_total[num].append(float(row[i+53])) 
        
    num += 1
    
    if row[0=='유럽':
        color.append('green')   #line color green for European countries
    elif row[0== '아시아':
        color.append('pink')    #line color pink for Asian countries
    elif row[0== '오세아니아':
        color.append('blue')    #line color blue for Oceanian countries
    elif row[0== '남아메리카':
        color.append('red')    #line color red for South American countries
    elif row[0== '북아메리카':
        color.append('purple')    #line color purple for North American countries
    elif row[0== '아프리카':
        color.append('skyblue')     #line color skyblue for African countries
 
plt.style.use('fivethirtyeight')
plt.rcParams['figure.figsize'= (108)
plt.rc('font', family = 'Malgun Gothic')
plt.title('Changes in GDP per capita from 1970 to 2019 of representative countries by continent'
          fontsize = 20, fontweight = 'bold')
plt.xlabel('year', fontsize = 15, fontweight = 'bold')
plt.ylabel('GDP per capita(unit: million dollars)', fontsize =15, fontweight = 'bold')
plt.xticks(range(1970,2020,5))
plt.plot(list(range(1970,2019)), gdp[0], label = country[0], color = color[0])
plt.plot(list(range(1970,2019)), gdp[1], label = country[1], color = color[1])
plt.plot(list(range(1970,2019)), gdp[2], label = country[2], color = color[2])
plt.plot(list(range(1970,2019)), gdp[3], label = country[3], color = color[3])
plt.plot(list(range(1970,2019)), gdp[4], label = country[4], color = color[4])
plt.plot(list(range(1970,2019)), gdp[5], label = country[5], color = color[5])
plt.plot(list(range(1970,2019)), gdp[6], label = country[6], color = color[6])
plt.plot(list(range(1970,2019)), gdp[7], label = country[7], color = color[7])
plt.plot(list(range(1970,2019)), gdp[8], label = country[8], color = color[8])
plt.plot(list(range(1970,2019)), gdp[9], label = country[9], color = color[9])
plt.plot(list(range(1970,2019)), gdp[10], label = country[10], color = color[10])
plt.legend()
plt.show()
cs