-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgdp_analysis_compare_gdp_growth_comparison.py
109 lines (63 loc) · 2.77 KB
/
gdp_analysis_compare_gdp_growth_comparison.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# -*- coding: utf-8 -*-
"""GDP Analysis - Compare GDP Growth Comparison.ipynb
Automatically generated by Colab.
Original file is located at
https://colab.research.google.com/drive/1fTsG7Vb4wCi--8kojZnwCbO_ixgjhtuU
# Compare GDP Growth Comparison
Instead Of Country Code We Can Also Use Country Name
"""
import os
import pandas as pd
import plotly.express as px
import plotly.offline as pyo
df = pd.read_csv('gdp.csv')
final_data = []
for country_name in df['Country Name'].unique():
df_pr = df[df['Country Name'] == country_name]
data = df_pr.values
gdp_change = [0]
for i in range(1,len(data)):
prev = data[i-1][3]
cur = data[i][3]
gdp_change.append(round(((cur - prev) / prev)*100,2))
df_pr = df_pr.assign(GDP_Percent = gdp_change)
final_data.append(df_pr)
df = pd.concat(final_data, axis = 0)
df.head()
def compare_gdp(lst):
dfs = []
for i in lst:
dfs.append(df[df['Country Code'] == i])
df_pr = pd.concat(dfs, axis = 0)
fig = px.line(df_pr, x = 'Year', y = 'GDP_Percent', title = 'GDP Analysis Based - ' + '|'.join(lst), color = 'Country Name')
pyo.plot(fig, filename = '|'.join(lst) + '.html')
compare_gdp(['IND','USA'])
"""## GDP_Percent Growth Comparies Of All The Countries
"""
fig = px.line(df, x = 'Year', y = 'GDP_Percent', title = 'GDP_Percent Growth ALL Countries', color = 'Country Name')
pyo.plot(fig, filename = 'GDP Growth.html')
"""## GDP_Percent Growth Of All The Countries Individual"""
# Taking Country Name Would Be Better
os.mkdir('GDP Growth Individual')
for country_name in df['Country Code'].unique():
df_pr = df[df['Country Code'] == country_name]
fig = px.line(df_pr, x = 'Year', y = 'GDP_Percent', title = country_name)
pyo.plot(fig, filename = 'GDP Growth Individual/' + country_name + '.html', auto_open = False)
"""# IMP Checking For Outlier Missing Data Technq
#### By Running The Below Code We Can See Majority Of Data Lays Between 57 Years By That we can say in many countries we have missing data
"""
# We Have Latest Data Of 2016 we can say 2016 - 57 = 1959 year
for country_name in df['Country Name'].unique():
df_pr = df[df['Country Name'] == country_name]
print(country_name, len(df_pr))
"""# Hence We Can Say GDP Growth btw 1960 - 2016"""
dfs =[]
for country_name in df['Country Name'].unique():
df_pr = df[df['Country Name'] == country_name]
if (len(df_pr) == 57):
dfs.append(df_pr) # Here We Are Getting a list of countries which have 57 years of data.
df_pr = pd.concat(dfs, axis = 0)
df_pr
# Here We Have Generated The Graph Based On 57 year data removeing outlier (missing data).
fig = px.line(df_pr, x = 'Year', y = 'GDP_Percent', title = 'GDP_Percent Growth', color = 'Country Name')
pyo.plot(fig, filename = 'GDP Growth 1960-2016.html', auto_open = False)