In [3]:
from IPython.display import Javascript
Javascript("""window.load_remote_theme = false; var theme_url = "https://drostehk.github.io/ipynb-theme/"; var asset_url = 'https://raw.githubusercontent.com/tijptjik/DS_assets/master/'; window.load_local_theme = function(){ var hostname = document.location.hostname; return ((hostname == "localhost" || hostname == '127.0.0.1') && !load_remote_theme)}; var url = load_local_theme() ? document.location.origin + "/files/theme/custom.js" : theme_url + 'custom.js'
$.getScript(url)""")


Out[3]:

Intro to Python for Data Analysis

The joy of coding Python should be in seeing short, concise, readable classes that express a lot of action in a small amount of clear code -- not in reams of trivial code that bores the reader to death.

Guido van Rossum (creator of Python)

Your journey starts with a little leg work

Python comes with a rich ecosystem of 'modules' that extend the core functionality provided by the language itself. Python Anaconda is a collection of the most popular modules used for scientific computing. By installing Anaconda, you will install python and setup all the libraries used in this class.

Please follow the online install documentation for instructions.

What is programming anyway?

Why would I trust a snake to be of any use?

  • Easy
  • Dynamic and interpreted
  • Expressive
  • Ecosystem

Now it's your turn to play with Python

IPython Notebook

launch the IPython Notebook by opening up a terminal and typing in the following command before pressing ENTER.

ipython notebook

Cells are either 'code' or 'text' - try to switch between them with the 'cell' menu on top. Text in cells is styled with a syntax known as MarkDown

Mac users need to run this in the terminal

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8

REPL

  1. Read
  2. Evaluate
  3. Print
  4. Loop

In [ ]:

Arithmetic


In [ ]:

Inline Graphics


In [7]:
import seaborn as sns

%matplotlib inline

sns.set()

flights_long = sns.load_dataset("flights")
flights = flights_long.pivot("month", "year", "passengers")
flights = flights.reindex(flights_long.iloc[:12].month)

sns.heatmap(flights, annot=True, fmt="d");


So, what are these 'programming components' you speak of?

Variables // First, to learn, we have to remember


In [12]:
# assignement

In [ ]:
# reassignement

In [ ]:
# name error

In [13]:
# multiple assignment

In [14]:
# variable swap

Operations // Second, we have to put two and two togther


In [15]:
# + addition
# - subtraction
# * multiplication
# / division

In [ ]:
# ** exponent

In [ ]:
# % remainder

In [16]:
# division

Datatypes // Third, we have to know what we're dealing with

int / float


In [ ]:
# numbers : int, float

str


In [ ]:
# letters ++ : str

In [ ]:
# replace

In [ ]:
# split

In [17]:
# capitalize

list


In [ ]:
# accessing a value

In [18]:
# updating a value

In [19]:
# appending a value

In [20]:
# deleting a value

In [ ]:
# length

In [ ]:
# concatenation

In [ ]:
# repetition

In [ ]:
# iteration

In [ ]:
# reverse

In [ ]:
#  sort

In [21]:
# membership

bool


In [ ]:
# True

In [ ]:
# False

Conditionals // Fourth, we need to know right from wrong


In [ ]:
# == equal to
# != not equal to
# < less than
# > greater than
# <= less than or equal to
# >= greater than or equal to

Functions // Lastly, we stop sweating the small stuff

How do we build on top of the basics?


In [22]:
# How do we build on top of the basics