File size: 6,484 Bytes
d69cca6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
import os
for dirname, _, filenames in os.walk('/content/Per Capita GDP of All Countries 1970 to 2022.csv'):
  for filename in filenames:
    print(os.path.join(dirname, filename))

import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
import plotly.express as px
import plotly.graph_objects as go
import plotly.offline as pyo
import plotly.io as pio

import warnings
warnings.filterwarnings('ignore')

df = pd.read_csv('/content/Per Capita GDP of All Countries 1970 to 2022.csv')

print('### first 5 lines ###', '\n')
df.head()

df.drop(["Sr.No"], axis=1, inplace=True)

rows = df.shape[0]
cols = df.shape[1]
print("Rows : " + str(rows))
print("Columns: " + str(cols))

print('### Dataframe information ###', '\n')
df.info()

print('### Total Null Data in DataFrame ###', '\n')
df.isnull().sum()

print("Number of duplicates: " + str(df.duplicated().sum()))

df['Growth_GDP_ 1970_2022_%'] = (((df['2022'] - df['1970'])/df['1970'])*100).round(2)

df.head()

df_country = df.dropna()

char_bar = df_country.groupby(['Country'])[['2022']].sum().reset_index()
char_bar = char_bar.sort_values(by=("2022"), ascending=False)

top = char_bar.head(10)
fig = go.Figure()
fig.add_trace(go.Bar(x=top['Country'], y=top["2022"]))

fig.update_layout(title='Highest Countries According to GDP 2022',
                          xaxis_title='Country',
                          yaxis_title= "2022",
                          plot_bgcolor='#F0EEED',
                          paper_bgcolor='#F0EEED',
                          font=dict(color='black'))

pyo.init_notebook_mode(connected=True)
pyo.iplot(fig)

char_bar = df_country.groupby(['Country'])[['2022']].sum().reset_index()
char_bar = char_bar.sort_values(by=("2022"), ascending=True)

top = char_bar.head(10)
fig = go.Figure()
fig.add_trace(go.Bar(x=top['Country'], y=top["2022"]))

fig.update_layout(title='Lowest Countries According to GDP 2022',
                          xaxis_title='Country',
                          yaxis_title= "2022",
                          plot_bgcolor='#F0EEED',
                          paper_bgcolor='#F0EEED',
                          font=dict(color='black'))

pyo.init_notebook_mode(connected=True)
pyo.iplot(fig)

char_bar = df_country.groupby(['Country'])[['Growth_GDP_ 1970_2022_%']].sum().reset_index()
char_bar = char_bar.sort_values(by=("Growth_GDP_ 1970_2022_%"), ascending=False)

top = char_bar.head(10)
fig = go.Figure()
fig.add_trace(go.Bar(x=top['Country'], y=top["Growth_GDP_ 1970_2022_%"]))

fig.update_layout(title='Highest Countries According to Growth_GDP) 1970_2022)%',
                  xaxis_title='Country',
                  yaxis_title='Growth_GDP_ 1970_2022)%',
                  plot_bgcolor='#F0EEED',
                  paper_bgcolor='#F0EEED',
                  font=dict(color='black'))

pyo.init_notebook_mode(connected=True)
pyo.iplot(fig)

char_bar = df_country.groupby(['Country'])[['Growth_GDP_ 1970_2022_%']].sum().reset_index()
char_bar = char_bar.sort_values(by=("Growth_GDP_ 1970_2022_%"), ascending=True)

top = char_bar.head(10)
fig = go.Figure()
fig.add_trace(go.Bar(x=top['Country'], y=top["Growth_GDP_ 1970_2022_%"]))

fig.update_layout(title='Lowest Countries According to Growth_GDP_ 1970_2022%',
                  xaxis_title='Country',
                  yaxis_title= "Growth_GPD_ 1970_2022)%",
                  plot_bgcolor='#F0EEED',
                  paper_bgcolor='#F0EEED',
                  font=dict(color='black'))

pyo.init_notebook_mode(connected=True)
pyo.iplot(fig)

df_europe = df.loc[df['Country'].isin(['Portugal', 'Spain', 'Italy', 'Germany', 'France'])]

dfy = df_europe.iloc[:,:-1]
dfy = dfy.transpose()
cols = dfy.iloc[0].to_list()
dfy.columns = cols
dfy = dfy.iloc[1:, :]
dfy.plot(figsize=(8, 4))
plt.title("Evolution of GDP - Europe", fontsize= 12)
plt.xlabel('Year', rotation=0, fontsize = 10)
plt.ylabel('GPD', rotation=90, fontsize = 10)
plt.grid()
plt.show();

df_eastern_euro = df.loc[df['Country'].isin(['Hungary', 'Poland', 'Romania', 'Albania'])]

dfy = df_eastern_euro.iloc[:,:-1]
dfy = dfy.transpose()
cols = dfy.iloc[0].to_list()
dfy.columns = cols
dfy = dfy.iloc[1:, :]
dfy.plot(figsize=(8, 4))
plt.title("Evolution of GPD - Eastern Europe", fontsize = 12)
plt.xlabel('Year', rotation=0, fontsize = 10)
plt.ylabel('Growth Rate (%)', rotation=90, fontsize = 10)
plt.grid()
plt.show();

df_top5 = df.loc[df['Country'].isin(['United States', 'China', 'Germany', 'Japan', 'India'])]

dfy = df_top5.iloc[:, :-1]
dfy = dfy.transpose()
cols = dfy.iloc[0].to_list()
dfy.columns = cols
dfy = dfy.iloc[1:, :]
dfy.plot(figsize=(8, 4))
plt.title("Evolution of GDP - Top 5 World Economies", fontsize= 12)
plt.xlabel('Year', rotation=0, fontsize = 10)
plt.ylabel('Growth Rate (%)', rotation=90, fontsize = 10)
plt.grid()
plt.show();

df_brics = df.loc[df['Country'].isin(['Brazil', 'USSR (Former)', 'India', 'China', 'South Africa'])]

dfy = df_brics.iloc[:, :-1]
dfy = dfy.transpose()
cols = dfy.iloc[0].to_list()
dfy.columns = cols
dfy = dfy.iloc[1:, :]
dfy.plot(figsize=(8, 4))
plt.title("Evolution of GDP - BRICS", fontsize = 12)
plt.xlabel('Year', rotation=0, fontsize = 10)
plt.ylabel('Growth Rate (%)', rotation=90, fontsize = 10)
plt.grid()
plt.show();

df_2_korea = df.loc[df['Country'].isin(['Republic of Korea', 'D.P.R. of Korea'])]

dfy = df_2_korea.iloc[:, :-1]
dfy = dfy.transpose()
cols = dfy.iloc[0].to_list()
dfy.columns = cols
dfy = dfy.iloc[1:, :]
dfy.plot(figsize=(8, 4))
plt.title("Evolution of the GDP - South Korea vs North Korea",
          fontsize = 12)
plt.xlabel('Year', rotation=0, fontsize = 10)
plt.ylabel('Growth Rate (%)', rotation=90, fontsize = 10)
plt.grid()
plt.show();

df_70_22 = df[['Country', '1970', '2022']]

char_bar = df_70_22.groupby(['Country'])[['1970', '2022']].sum().reset_index()
char_bar = char_bar.sort_values(by=("2022"), ascending=False)

top = char_bar.head(20)
top.plot(x="Country", y=["1970", "2022"], kind="bar", figsize=(12, 5))
plt.title("Comparison between GDP 1970 and 2022 - Top 20 Countries", fontsize = 12)

plt.show()

fig = px.choropleth(df,
                    locations='Country', locationmode='country names',
                    color = '2022',hover_name="Country",
                    color_continuous_scale='Viridis_r')
fig.update_layout(margin={'r':0,'t':0,'l':0,'b':0}, coloraxis_colorbar=dict(
    title = 'GDP - 2022',
    ticks = 'outside',
    tickvals = [0,50000,100000,150000,200000,250000],
    dtick = 12))
fig.show()