{{ message }}

Instantly share code, notes, and snippets.

# bsmith89/gapminder-analysis.ipynb

Last active Dec 21, 2016
Example analysis notebook and (*very*) rudimentary notes for a customized python-novice-gapminder. http://blog.byronjsmith.com/python-lesson-balance.html
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

## Introduction

• Demonstrate "complex" analysis notebook.

## Pandas/Matplotlib

• Talk about the optional parameter `index_col=`
• Walk through the gapminder_all data.
• Plot 1957 life-expectancy against GDP/pop
• Note the column-as-attribute syntax
• Note outlier
• data.gdpPercap_1957.argmax()
• data.drop(...)
• Plot Africa data alone
• Use data[data.continent == 'Africa'] syntax
• Plot with a color
• CHALLENGE: Select the subset of the data from the continent which contains the country with the maximum life-expectancy in 1967

## For loops

• Talk about wanting to repeat something for each continent.

• For loop syntax

Fill in the blanks in the program below so that it prints “nit” (the reverse of the original character string “tin”).

```original = "tin"
result = ____
for char in original:
result = ____
print(result)```
• Plot only a subset of the continents (africa, asia, europe)

## If statements

• Talk about wanting to do something different depending on which continent we're considering.
• If statement syntax (notice the 'block' syntax)
• if
• if, else
• if, elif, else
• Plot a different color for several of the continents.

## Plot Aesthetics

• Size the points by np.sqrt(population) (so that the area is proportional)
• Add a legend (dummy plotting)
• Note the uglyness of the numbers

## Defining Functions

• Celsius to fahrenheit conversion
• Kelvin to C conversion
• What are the benefits of using functions?
• Let's write a function to convert large numbers into scientific notation
• Add an optional argument to set the precision
• Add some documentation and show how help(scientific_notation) works

## Defensive programming

• How do we know if it's working? (unit testing, assert)

## Statsmodels

• Line of best fit
• Statsmodels
• formula
• fitting the model and viewing the summary
• Getting the coefficients out and using them
• Plotting the line
• CHALLENGE: extend this analysis and share with your neighbors