# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

import pandas as pd
# This allows us to be able to import and use data from csv files


from matplotlib import pyplot as plt
# This allows us to make charts

# +
x = [1, 2, 3]
y = [1, 4, 9]
z = [10, 5, 0]
plt.plot(x, y)
plt.plot(x, z)
plt.title("x against y and z")
plt.xlabel("X")
plt.ylabel("Y and Z")
plt.legend(["this is y", "this is z"])
# Legend function takes a list as an argument


plt.show



# -

sample_data = pd.read_csv('sample_data.csv')
# The sample_data is loaded and assigned to the variable name sample_data

sample_data
# We run this to display the data indexed

type(sample_data)
# This Dataframe type is defined by pandas module; it contains a table-like piece of information 

sample_data.column_c

type(sample_data.column_c)
# This is a series type that's defined by pandas module that stores a series of values 

sample_data.column_c
# Retrieving a specific column in index form

sample_data.column_c.iloc[3]
# Retrieving a specific value in a chosen column


plt.plot(sample_data.column_a, sample_data.column_b, 'o')
# 'o' allows a dotted plot
plt.plot(sample_data.column_a, sample_data.column_c, 'o')
plt.title('Sample data')
plt.xlabel('column_a')
plt.ylabel('column_b and column_c')
plt.legend(['This is column_b', 'This is column_c'])
plt.show()

# +
# Onto the countries dataset
# -

countries_data = pd.read_csv('countries.csv')

countries_data

# +
# Compare population growth for US and China
# -

countries_data.country == 'United States'
# This outputs True where United states is in the row else, False

countries_data[countries_data.country == 'United States']
# This outputs a portion of the data with united states 

us = countries_data[countries_data.country == 'United States']
# Isolating data for us by assigning it to the us variable so as to output only united states data

us

china = countries_data[countries_data.country == 'China']
# Isolating data for china by assigning it to the china variable so as to output china data

china

plt.plot(us.year, us.population/ 10**6)
plt.plot(china.year, china.population/ 10** 6)
# You can still use the same x, as x is independent; in this case exactly the same set of years
plt.legend(['United States', 'China'])
plt.xlabel('Year')
plt.ylabel('Population')
plt.show()

us.population

# This is going to return the population of the first year of US; assuming the column is in ascending order
us.population.iloc[0]

# +
# We divide the entire population by the first year's population and * by 100 to get the % growth
us.population/ us.population.iloc[0] * 100


# -

# We wanna compare % relative growth from the first year to it's current population
plt.plot(us.year, us.population/us.population.iloc[0] * 100)
plt.plot(china.year, china.population/china.population.iloc[0] * 100)
plt.legend(['United States', 'China'])
plt.xlabel('Year')
plt.ylabel('Relative Population Growth (FirstYear = 100)')
plt.show()

# +
# Hope you guys liked this
# Source Tutorial: CSDojo

StarcoderdataJupyterScriptsDedupFiltered