Skip to content

World Population Data

This dataset has the total population numbers for every country from 1960 to 2020. Additionally, there is a table that contains country information, including region, income group, and any special notes.

import pandas as pd 
pop = pd.read_csv('world_pop_data.csv')
metadata = pd.read_csv('metadata_country.csv')

# Merge the above two datasets 
full = pop.merge(metadata,on = "Country Code")
# Writing a function to draw a plot from the data
import matplotlib.pyplot as plt
def draw_plot(country,plt):
    plt.figure(figsize=(10,8))
    plt.xticks(rotation=90)
    plt.xlabel('years')
    plt.ylabel('Population in Millions')
    plt.title('Population Comparision report')
    plt.gca().xaxis.set_major_locator(plt.MultipleLocator(5))
    for ctry in country :
        data = full[full['TableName']== ctry].drop(['Country Code','Indicator Name','Indicator Code','Region','IncomeGroup','SpecialNotes','TableName'],axis=1)
        x = data.columns
        y = data.T.iloc[:,0]/1000000
        plt.plot(x,y)
    plt.legend(country)
    return plt
#Showcase of Draw plot function
draw_plot(['India','Canada','China','United States'],plt)
plt.show()