antitheft159
commited on
Commit
•
d69cca6
1
Parent(s):
19e8dd8
Upload capita_gdp_of_all_countries.py
Browse files- capita_gdp_of_all_countries.py +212 -0
capita_gdp_of_all_countries.py
ADDED
@@ -0,0 +1,212 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# -*- coding: utf-8 -*-
|
2 |
+
"""Capita GDP of All Countries
|
3 |
+
|
4 |
+
Automatically generated by Colab.
|
5 |
+
|
6 |
+
Original file is located at
|
7 |
+
https://colab.research.google.com/drive/1miKbrdpnHpgvZ8b8vdLzi06jWrcedtbx
|
8 |
+
"""
|
9 |
+
|
10 |
+
import os
|
11 |
+
for dirname, _, filenames in os.walk('/content/Per Capita GDP of All Countries 1970 to 2022.csv'):
|
12 |
+
for filename in filenames:
|
13 |
+
print(os.path.join(dirname, filename))
|
14 |
+
|
15 |
+
import pandas as pd
|
16 |
+
import matplotlib.pyplot as plt
|
17 |
+
import numpy as np
|
18 |
+
import seaborn as sns
|
19 |
+
import plotly.express as px
|
20 |
+
import plotly.graph_objects as go
|
21 |
+
import plotly.offline as pyo
|
22 |
+
import plotly.io as pio
|
23 |
+
|
24 |
+
import warnings
|
25 |
+
warnings.filterwarnings('ignore')
|
26 |
+
|
27 |
+
df = pd.read_csv('/content/Per Capita GDP of All Countries 1970 to 2022.csv')
|
28 |
+
|
29 |
+
print('### first 5 lines ###', '\n')
|
30 |
+
df.head()
|
31 |
+
|
32 |
+
df.drop(["Sr.No"], axis=1, inplace=True)
|
33 |
+
|
34 |
+
rows = df.shape[0]
|
35 |
+
cols = df.shape[1]
|
36 |
+
print("Rows : " + str(rows))
|
37 |
+
print("Columns: " + str(cols))
|
38 |
+
|
39 |
+
print('### Dataframe information ###', '\n')
|
40 |
+
df.info()
|
41 |
+
|
42 |
+
print('### Total Null Data in DataFrame ###', '\n')
|
43 |
+
df.isnull().sum()
|
44 |
+
|
45 |
+
print("Number of duplicates: " + str(df.duplicated().sum()))
|
46 |
+
|
47 |
+
df['Growth_GDP_ 1970_2022_%'] = (((df['2022'] - df['1970'])/df['1970'])*100).round(2)
|
48 |
+
|
49 |
+
df.head()
|
50 |
+
|
51 |
+
df_country = df.dropna()
|
52 |
+
|
53 |
+
char_bar = df_country.groupby(['Country'])[['2022']].sum().reset_index()
|
54 |
+
char_bar = char_bar.sort_values(by=("2022"), ascending=False)
|
55 |
+
|
56 |
+
top = char_bar.head(10)
|
57 |
+
fig = go.Figure()
|
58 |
+
fig.add_trace(go.Bar(x=top['Country'], y=top["2022"]))
|
59 |
+
|
60 |
+
fig.update_layout(title='Highest Countries According to GDP 2022',
|
61 |
+
xaxis_title='Country',
|
62 |
+
yaxis_title= "2022",
|
63 |
+
plot_bgcolor='#F0EEED',
|
64 |
+
paper_bgcolor='#F0EEED',
|
65 |
+
font=dict(color='black'))
|
66 |
+
|
67 |
+
pyo.init_notebook_mode(connected=True)
|
68 |
+
pyo.iplot(fig)
|
69 |
+
|
70 |
+
char_bar = df_country.groupby(['Country'])[['2022']].sum().reset_index()
|
71 |
+
char_bar = char_bar.sort_values(by=("2022"), ascending=True)
|
72 |
+
|
73 |
+
top = char_bar.head(10)
|
74 |
+
fig = go.Figure()
|
75 |
+
fig.add_trace(go.Bar(x=top['Country'], y=top["2022"]))
|
76 |
+
|
77 |
+
fig.update_layout(title='Lowest Countries According to GDP 2022',
|
78 |
+
xaxis_title='Country',
|
79 |
+
yaxis_title= "2022",
|
80 |
+
plot_bgcolor='#F0EEED',
|
81 |
+
paper_bgcolor='#F0EEED',
|
82 |
+
font=dict(color='black'))
|
83 |
+
|
84 |
+
pyo.init_notebook_mode(connected=True)
|
85 |
+
pyo.iplot(fig)
|
86 |
+
|
87 |
+
char_bar = df_country.groupby(['Country'])[['Growth_GDP_ 1970_2022_%']].sum().reset_index()
|
88 |
+
char_bar = char_bar.sort_values(by=("Growth_GDP_ 1970_2022_%"), ascending=False)
|
89 |
+
|
90 |
+
top = char_bar.head(10)
|
91 |
+
fig = go.Figure()
|
92 |
+
fig.add_trace(go.Bar(x=top['Country'], y=top["Growth_GDP_ 1970_2022_%"]))
|
93 |
+
|
94 |
+
fig.update_layout(title='Highest Countries According to Growth_GDP) 1970_2022)%',
|
95 |
+
xaxis_title='Country',
|
96 |
+
yaxis_title='Growth_GDP_ 1970_2022)%',
|
97 |
+
plot_bgcolor='#F0EEED',
|
98 |
+
paper_bgcolor='#F0EEED',
|
99 |
+
font=dict(color='black'))
|
100 |
+
|
101 |
+
pyo.init_notebook_mode(connected=True)
|
102 |
+
pyo.iplot(fig)
|
103 |
+
|
104 |
+
char_bar = df_country.groupby(['Country'])[['Growth_GDP_ 1970_2022_%']].sum().reset_index()
|
105 |
+
char_bar = char_bar.sort_values(by=("Growth_GDP_ 1970_2022_%"), ascending=True)
|
106 |
+
|
107 |
+
top = char_bar.head(10)
|
108 |
+
fig = go.Figure()
|
109 |
+
fig.add_trace(go.Bar(x=top['Country'], y=top["Growth_GDP_ 1970_2022_%"]))
|
110 |
+
|
111 |
+
fig.update_layout(title='Lowest Countries According to Growth_GDP_ 1970_2022%',
|
112 |
+
xaxis_title='Country',
|
113 |
+
yaxis_title= "Growth_GPD_ 1970_2022)%",
|
114 |
+
plot_bgcolor='#F0EEED',
|
115 |
+
paper_bgcolor='#F0EEED',
|
116 |
+
font=dict(color='black'))
|
117 |
+
|
118 |
+
pyo.init_notebook_mode(connected=True)
|
119 |
+
pyo.iplot(fig)
|
120 |
+
|
121 |
+
df_europe = df.loc[df['Country'].isin(['Portugal', 'Spain', 'Italy', 'Germany', 'France'])]
|
122 |
+
|
123 |
+
dfy = df_europe.iloc[:,:-1]
|
124 |
+
dfy = dfy.transpose()
|
125 |
+
cols = dfy.iloc[0].to_list()
|
126 |
+
dfy.columns = cols
|
127 |
+
dfy = dfy.iloc[1:, :]
|
128 |
+
dfy.plot(figsize=(8, 4))
|
129 |
+
plt.title("Evolution of GDP - Europe", fontsize= 12)
|
130 |
+
plt.xlabel('Year', rotation=0, fontsize = 10)
|
131 |
+
plt.ylabel('GPD', rotation=90, fontsize = 10)
|
132 |
+
plt.grid()
|
133 |
+
plt.show();
|
134 |
+
|
135 |
+
df_eastern_euro = df.loc[df['Country'].isin(['Hungary', 'Poland', 'Romania', 'Albania'])]
|
136 |
+
|
137 |
+
dfy = df_eastern_euro.iloc[:,:-1]
|
138 |
+
dfy = dfy.transpose()
|
139 |
+
cols = dfy.iloc[0].to_list()
|
140 |
+
dfy.columns = cols
|
141 |
+
dfy = dfy.iloc[1:, :]
|
142 |
+
dfy.plot(figsize=(8, 4))
|
143 |
+
plt.title("Evolution of GPD - Eastern Europe", fontsize = 12)
|
144 |
+
plt.xlabel('Year', rotation=0, fontsize = 10)
|
145 |
+
plt.ylabel('Growth Rate (%)', rotation=90, fontsize = 10)
|
146 |
+
plt.grid()
|
147 |
+
plt.show();
|
148 |
+
|
149 |
+
df_top5 = df.loc[df['Country'].isin(['United States', 'China', 'Germany', 'Japan', 'India'])]
|
150 |
+
|
151 |
+
dfy = df_top5.iloc[:, :-1]
|
152 |
+
dfy = dfy.transpose()
|
153 |
+
cols = dfy.iloc[0].to_list()
|
154 |
+
dfy.columns = cols
|
155 |
+
dfy = dfy.iloc[1:, :]
|
156 |
+
dfy.plot(figsize=(8, 4))
|
157 |
+
plt.title("Evolution of GDP - Top 5 World Economies", fontsize= 12)
|
158 |
+
plt.xlabel('Year', rotation=0, fontsize = 10)
|
159 |
+
plt.ylabel('Growth Rate (%)', rotation=90, fontsize = 10)
|
160 |
+
plt.grid()
|
161 |
+
plt.show();
|
162 |
+
|
163 |
+
df_brics = df.loc[df['Country'].isin(['Brazil', 'USSR (Former)', 'India', 'China', 'South Africa'])]
|
164 |
+
|
165 |
+
dfy = df_brics.iloc[:, :-1]
|
166 |
+
dfy = dfy.transpose()
|
167 |
+
cols = dfy.iloc[0].to_list()
|
168 |
+
dfy.columns = cols
|
169 |
+
dfy = dfy.iloc[1:, :]
|
170 |
+
dfy.plot(figsize=(8, 4))
|
171 |
+
plt.title("Evolution of GDP - BRICS", fontsize = 12)
|
172 |
+
plt.xlabel('Year', rotation=0, fontsize = 10)
|
173 |
+
plt.ylabel('Growth Rate (%)', rotation=90, fontsize = 10)
|
174 |
+
plt.grid()
|
175 |
+
plt.show();
|
176 |
+
|
177 |
+
df_2_korea = df.loc[df['Country'].isin(['Republic of Korea', 'D.P.R. of Korea'])]
|
178 |
+
|
179 |
+
dfy = df_2_korea.iloc[:, :-1]
|
180 |
+
dfy = dfy.transpose()
|
181 |
+
cols = dfy.iloc[0].to_list()
|
182 |
+
dfy.columns = cols
|
183 |
+
dfy = dfy.iloc[1:, :]
|
184 |
+
dfy.plot(figsize=(8, 4))
|
185 |
+
plt.title("Evolution of the GDP - South Korea vs North Korea",
|
186 |
+
fontsize = 12)
|
187 |
+
plt.xlabel('Year', rotation=0, fontsize = 10)
|
188 |
+
plt.ylabel('Growth Rate (%)', rotation=90, fontsize = 10)
|
189 |
+
plt.grid()
|
190 |
+
plt.show();
|
191 |
+
|
192 |
+
df_70_22 = df[['Country', '1970', '2022']]
|
193 |
+
|
194 |
+
char_bar = df_70_22.groupby(['Country'])[['1970', '2022']].sum().reset_index()
|
195 |
+
char_bar = char_bar.sort_values(by=("2022"), ascending=False)
|
196 |
+
|
197 |
+
top = char_bar.head(20)
|
198 |
+
top.plot(x="Country", y=["1970", "2022"], kind="bar", figsize=(12, 5))
|
199 |
+
plt.title("Comparison between GDP 1970 and 2022 - Top 20 Countries", fontsize = 12)
|
200 |
+
|
201 |
+
plt.show()
|
202 |
+
|
203 |
+
fig = px.choropleth(df,
|
204 |
+
locations='Country', locationmode='country names',
|
205 |
+
color = '2022',hover_name="Country",
|
206 |
+
color_continuous_scale='Viridis_r')
|
207 |
+
fig.update_layout(margin={'r':0,'t':0,'l':0,'b':0}, coloraxis_colorbar=dict(
|
208 |
+
title = 'GDP - 2022',
|
209 |
+
ticks = 'outside',
|
210 |
+
tickvals = [0,50000,100000,150000,200000,250000],
|
211 |
+
dtick = 12))
|
212 |
+
fig.show()
|