<jupyter_start><jupyter_text>_Lambda School Data Science_ Sequence Your Narrative - AssignmentToday we will create a sequence of visualizations inspired by [<NAME>'s 200 Countries, 200 Years, 4 Minutes](https://www.youtube.com/watch?v=jbkSRLYSojo).Using this [data from Gapminder](https://github.com/open-numbers/ddf--gapminder--systema_globalis/):- [Income Per Person (GDP Per Capital, Inflation Adjusted) by Geo & Time](https://raw.githubusercontent.com/open-numbers/ddf--gapminder--systema_globalis/master/ddf--datapoints--income_per_person_gdppercapita_ppp_inflation_adjusted--by--geo--time.csv)- [Life Expectancy (in Years) by Geo & Time](https://raw.githubusercontent.com/open-numbers/ddf--gapminder--systema_globalis/master/ddf--datapoints--life_expectancy_years--by--geo--time.csv)- [Population Totals, by Geo & Time](https://raw.githubusercontent.com/open-numbers/ddf--gapminder--systema_globalis/master/ddf--datapoints--population_total--by--geo--time.csv)- [Entities](https://raw.githubusercontent.com/open-numbers/ddf--gapminder--systema_globalis/master/ddf--entities--geo--country.csv)- [Concepts](https://raw.githubusercontent.com/open-numbers/ddf--gapminder--systema_globalis/master/ddf--concepts.csv) Objectives- sequence multiple visualizations- combine qualitative anecdotes with quantitative aggregatesLinks- [<NAME>’s TED talks](https://www.ted.com/speakers/hans_rosling)- [Spiralling global temperatures from 1850-2016](https://twitter.com/ed_hawkins/status/729753441459945474)- "[The Pudding](https://pudding.cool/) explains ideas debated in culture with visual essays."- [A Data Point Walks Into a Bar](https://lisacharlotterost.github.io/2016/12/27/datapoint-in-bar/): a thoughtful blog post about emotion and empathy in data storytelling  ASSIGNMENT 1.   Replicate the Lesson Code2.   Take it further by using the same gapminder dataset to create a sequence of visualizations that combined tell a story of your choosing.Get creative! Use text annotations to call out specific countries, maybe: change how the points are colored, change the opacity of the points, change their sized, pick a specific time window. Maybe only work with a subset of countries, change fonts, change background colors, etc. make it your own!<jupyter_code>%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import seaborn as sns

income = pd.read_csv('https://raw.githubusercontent.com/open-numbers/ddf--gapminder--systema_globalis/master/ddf--datapoints--income_per_person_gdppercapita_ppp_inflation_adjusted--by--geo--time.csv')
lifespan = pd.read_csv('https://raw.githubusercontent.com/open-numbers/ddf--gapminder--systema_globalis/master/ddf--datapoints--life_expectancy_years--by--geo--time.csv')
population = pd.read_csv('https://raw.githubusercontent.com/open-numbers/ddf--gapminder--systema_globalis/master/ddf--datapoints--population_total--by--geo--time.csv')
entities = pd.read_csv('https://raw.githubusercontent.com/open-numbers/ddf--gapminder--systema_globalis/master/ddf--entities--geo--country.csv')
concepts = pd.read_csv('https://raw.githubusercontent.com/open-numbers/ddf--gapminder--systema_globalis/master/ddf--concepts.csv')

#This line neatly shows all the shapes of the pd's I imported
print (income.shape, lifespan.shape, population.shape, entities.shape, concepts.shape)

print (income.head(),'\n\n', lifespan.head(),'\n\n', population.head(),'\n\n'
        , entities.head(),'\n\n', concepts.head())
#I need to print the last 2 csv into their own lines to see better
pd.options.display.max_columns = 500
pd.options.display.max_rows = 500
entities.head()
concepts.head()
#I kept an extra 2 columns than the assignment to work on those
df = income
df = pd.merge(income, lifespan)
df = pd.merge(df, population)
df = pd.merge(df, entities[['country', 'name', 'world_4region', 'world_6region',
                            'landlocked', 'main_religion_2008']],left_on='geo', right_on='country')

print(df.shape)
df.head()
#Here I rename the columns to make them more readable and less clunky
df = df.rename(columns = {
    'country': 'country_code',
    'time': 'year', 
    'income_per_person_gdppercapita_ppp_inflation_adjusted': 'income', 
    'life_expectancy_years': 'lifespan',
    'population_total': 'population',
    'name': 'country',
    'world_6region': '6region',
    'world_4region': '4region',
    'main_religion_2008': 'religion'
})

df.head()
df.describe(exclude='number')
#Here I look at the different religions to see what I will be working with.
#There are only 3 unique
df['religion'].unique()
#Here I make the df I will work with. Only keeping the 3 religions.
religion_eastern = df[df.religion == 'eastern_religions']
religion_eastern.head()
religion_christian = df[df.religion == 'christian']
religion_christian.head()
religion_muslim = df[df.religion == 'muslim']
religion_muslim.head()
#I can make this inside the other function if I wanted to.
def choses_years(df_data, years):
  """This function takes in a data frame and filters by the years you choose."""
  df_data = df_data[df_data.year.isin(years)]
  return df_data

#Here I separate the years I will work with
years = [1818, 1868, 1918, 1968, 2018]


muslim_years = choses_years(religion_muslim, years)
christian_years = choses_years(religion_christian, years)
eastern_years = choses_years(religion_eastern, years)
#I wanted to demonstrate if a string would be called correctly
muslim_years.iloc[1]['religion']
def graph_nations_religion_to_lifespan(df_data, years):
  """Takes in df_data and years to print graphs based on 'income', to 'lifespan' for the mean income
  of each region. Enjoy!"""
  for year in years:
    sns.relplot(x='income', y='lifespan', hue='6region', size='population', 
              sizes=(30,400), data=df_data[df_data.year==year])
    plt.xscale('log')
    plt.xlim((150, 150000))
    plt.ylim((0, 90))
    income_mean_year = df_data[df_data.year==year].income.mean()
    plt.title(str(df_data.iloc[1]['religion']) +' mean income for ' +
              str(year)+' is '+str(int(income_mean_year)))
    plt.axvline(x=df_data[df_data.year==year].income.mean(), color='grey')

  pass
graph_nations_religion_to_lifespan(muslim_years, years)
graph_nations_religion_to_lifespan(christian_years, years)
graph_nations_religion_to_lifespan(eastern_years, years)<jupyter_output><empty_output><jupyter_text>STRETCH OPTIONS 1. Animate!- [How to Create Animated Graphs in Python](https://towardsdatascience.com/how-to-create-animated-graphs-in-python-bb619cc2dec1)- Try using [Plotly](https://plot.ly/python/animations/)!- [The Ultimate Day of Chicago Bikeshare](https://chrisluedtke.github.io/divvy-data.html) (Lambda School Data Science student)- [Using Phoebe for animations in Google Colab](https://colab.research.google.com/github/phoebe-project/phoebe2-docs/blob/2.1/tutorials/animations.ipynb) 2. Study for the Sprint Challenge- Concatenate DataFrames- Merge DataFrames- Reshape data with `pivot_table()` and `.melt()`- Be able to reproduce a FiveThirtyEight graph using Matplotlib or Seaborn. 3. Work on anything related to your portfolio site / Data Storytelling Project<jupyter_code># TODO<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup