World statistics

Data visualisations made by Janhavi Pimplikar

A student at Pimpri Chinchwad College of Engineering

In [3]:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
In [4]:
import seaborn as sns
import plotly as py
import cufflinks as cf
In [5]:
import plotly.express as px
from plotly.offline import iplot
cf.go_offline()
py.offline.init_notebook_mode(connected=True)

Importing the dataset

In [6]:
world=pd.read_csv('Stats.csv')
In [7]:
world['Population (2019)']=world['Population (2020)']-world['Net Change']
In [8]:
world
Out[8]:
Country (or dependency) Population (2020) Yearly Change % Net Change Density (P/Km²) Land Area (Km²) Migrants (net) Fert. Rate Med. Age Urban Pop % World Share % Population (2019)
0 China 1439323776 0.39 5540090 153.0 9388211.0 -348399.0 1.7 38.0 61.0 18.47 1433783686
1 India 1380004385 0.99 13586631 464.0 2973190.0 -532687.0 2.2 28.0 35.0 17.70 1366417754
2 United States 331002651 0.59 1937734 36.0 9147420.0 954806.0 1.8 38.0 83.0 4.25 329064917
3 Indonesia 273523615 1.07 2898047 151.0 1811570.0 -98955.0 2.3 30.0 56.0 3.51 270625568
4 Pakistan 220892340 2.00 4327022 287.0 770880.0 -233379.0 3.6 23.0 35.0 2.83 216565318
... ... ... ... ... ... ... ... ... ... ... ... ...
230 Montserrat 4992 0.06 3 50.0 100.0 NaN NaN NaN 10.0 0.00 4989
231 Falkland Islands 3480 3.05 103 0.0 12170.0 NaN NaN NaN 66.0 0.00 3377
232 Niue 1626 0.68 11 6.0 260.0 NaN NaN NaN 46.0 0.00 1615
233 Tokelau 1357 1.27 17 136.0 10.0 NaN NaN NaN 0.0 0.00 1340
234 Holy See 801 0.25 2 2003.0 0.0 NaN NaN NaN NaN 0.00 799

235 rows × 12 columns

In [ ]:
 

Population stats for 2019 and 2020

In [9]:
fig=px.choropleth(world,locations='Country (or dependency)',locationmode='country names', color=np.log(world['Population (2020)']),hover_name='Population (2019)',color_continuous_scale=px.colors.sequential.Magma,title='World Population distribution (2019)')
fig.update(layout_coloraxis_showscale=True)
fig.show()
In [10]:
fig=px.choropleth(world,locations='Country (or dependency)',locationmode='country names', color=np.log(world['Population (2020)']),hover_name='Population (2020)',color_continuous_scale=px.colors.sequential.Viridis,title='World Population distribution (2020)')
fig.update(layout_coloraxis_showscale=True)
fig.show()
In [11]:
top_10=world.head(10)
In [12]:
top_10.iplot(x='Country (or dependency)',y=['Population (2019)','Population (2020)'],kind='bar',xTitle='Country',yTitle='Population',title='Most populous countries in 2019 and 2020',legend=True, color=['pink','green'])
In [13]:
bottom_10=world.tail(10)
In [14]:
bottom_10.iplot(x='Country (or dependency)',y=['Population (2019)','Population (2020)'],kind='bar',xTitle='Country',yTitle='Population',title='Least populous countries in 2019 and 2020',legend=True, color=['blue','orange'])
In [15]:
fig=px.choropleth(world,locations='Country (or dependency)',locationmode='country names', color=np.log(world['Population (2020)']),hover_name='Population (2020)',color_continuous_scale=px.colors.sequential.Inferno,title='World Population density distribution')
fig.update(layout_coloraxis_showscale=True)
fig.show()
In [16]:
top_10.iplot(x='Country (or dependency)',y='Density (P/Km²)',kind='bar',xTitle='Country',yTitle='Population density',title='Most densely populated countries',legend=True, color='green')
In [17]:
bottom_10.iplot(x='Country (or dependency)',y='Density (P/Km²)',kind='bar',xTitle='Country',yTitle='Population',title='Least densely populated countries',legend=True, color='orange')
In [ ]:
 

Urban population

In [18]:
urban=world[['Country (or dependency)','Urban Pop %']].sort_values('Urban Pop %',ascending=False)
In [19]:
urban=urban.head(25)
In [20]:
fig,ax=plt.subplots(figsize=(15,15))
lab=urban['Country (or dependency)']
urban.plot.pie(y='Urban Pop %',ax=ax,legend=False,labels=lab,colors=sns.color_palette('Accent'),autopct="%1.2f%%",fontsize=10,shadow=True)
plt.title('25 countries having the highest urban population',size=20)
c=plt.Circle((0,0),0.3,color='white')
plt.gca().add_artist(c)
fig.show()
C:\Users\apimplikar\Desktop\Anaconda\lib\site-packages\ipykernel_launcher.py:7: UserWarning:

Matplotlib is currently using module://ipykernel.pylab.backend_inline, which is a non-GUI backend, so cannot show the figure.

In [21]:
land=world[['Country (or dependency)','Land Area (Km²)']].sort_values('Land Area (Km²)',ascending=False)
In [22]:
land=land.head(25)
In [23]:
fig,ax=plt.subplots(figsize=(15,15))
lab=land['Country (or dependency)']
land.plot.pie(y='Land Area (Km²)',ax=ax,legend=False,labels=lab,colors=sns.color_palette('Set2'),autopct="%1.2f%%",fontsize=10,shadow=True)
plt.title('25 countries having the largest land area',size=20)
c=plt.Circle((0,0),0.3,color='white')
plt.gca().add_artist(c)
fig.show()
C:\Users\apimplikar\Desktop\Anaconda\lib\site-packages\ipykernel_launcher.py:7: UserWarning:

Matplotlib is currently using module://ipykernel.pylab.backend_inline, which is a non-GUI backend, so cannot show the figure.

In [ ]:
 

dataset: imported from https://www.kaggle.com/kisoibo/countries-databasesqlite

attributes: Websites such as stackoverflow.com, matplotlib.com etc.