|
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() |