In [ ]:
# HIDDEN
# Credit:  Data8.org

from datascience import *
import numpy as np
%matplotlib inline
import matplotlib.pyplot as plots
plots.style.use('fivethirtyeight')



## Words of Caution¶

• Remember to run the cell above. It's for setting up the environment so you can have access to what's needed for this lecture.
• Data science is not just about code, so please don't go over this notebook by itself. Have the relevant textbook sections or lecture notes at hand so that you can go over the discussion along with the code. Thank you!

## Python¶

In [ ]:
2 + 3

In [ ]:
2 - 3

In [ ]:
2 * 3

In [ ]:
2 / 3

In [ ]:
# 2 * 2 * 2

2 ** 3


## Names¶

In [ ]:
a = 10

In [ ]:
a

In [ ]:
b = 6

In [ ]:
total = a + b

In [ ]:
total

In [ ]:
b = 7

In [ ]:
total

In [ ]:
total = a + b

In [ ]:
total

In [ ]:
hours_per_week = 40
weeks_per_year = 52

In [ ]:
total_hours = hours_per_week * weeks_per_year

In [ ]:
total_hours

In [ ]:
ca_hourly_minimum_wage = 10.50

In [ ]:
total_wages = total_hours * ca_hourly_minimum_wage

total_wages


## Functions¶

In [ ]:
abs(-5)

In [ ]:
a

In [ ]:
b

In [ ]:
abs(b - a)

In [ ]:
min(8, 3)

In [ ]:
round(123.56789)

In [ ]:
round(123.56789, 2)


## Tables¶

In [ ]:
# Each row represents one ice-cream cone

cones

In [ ]:
cones.show(2)

In [ ]:
cones.select('Flavor')

In [ ]:
cones

In [ ]:
cones.select('Flavor', 'Price')

In [ ]:
cones

In [ ]:
cones.drop('Color')

In [ ]:
cones

In [ ]:
no_color = cones.drop('Color')

In [ ]:
no_color

In [ ]:
cones.sort('Price')

In [ ]:
cones.sort('Price', descending=True)

In [ ]:
cones.where('Flavor', 'chocolate')

In [ ]:
cones.where('Flavor', 'Chocolate')

In [ ]:
cones.drop('Color').sort('Price', descending=True)


## Example¶

In [ ]:
# This table can be found online:
# https://www.statcrunch.com/app/index.php?dataid=1843341

# NBA players, 2015-2016 season

nba

In [ ]:
nba.where('PLAYER', 'Stephen Curry')

In [ ]:
warriors = nba.where('TEAM', 'Golden State Warriors')

In [ ]:
warriors.show()

In [ ]: