from datascience import *
import numpy as np
%matplotlib inline
import matplotlib.pyplot as plots
plots.style.use('fivethirtyeight')
2 + 9
11
2 * 9
18
2 / 9
0.2222222222222222
2 + 3 * 9
29
(2 + 3) * 9
45
# two to the power of four: 2 * 2 * 2 * 2
2 ** 4
16
'hello'
'hello'
a = 4
a
4
b = 9
b
9
a * 3
12
total = a + b
total
13
a = 10
total
13
total = a + b
total
19
'total'
'total'
# Option 1
40 * 14.00
560.0
40 * 52 * 14.00
29120.0
# Option 2
ca_hourly_minimum_wage = 14.00
hours_per_week = 40
weeks_per_year = 52
hours_per_year = hours_per_week * weeks_per_year
hours_per_year
2080
weekly_wages = hours_per_week * ca_hourly_minimum_wage
weekly_wages
560.0
yearly_wages = hours_per_year * ca_hourly_minimum_wage
yearly_wages
29120.0
abs(-5)
5
abs(1 - 3)
2
day_temp = 52
night_temp = 47
abs(night_temp - day_temp)
5
min(14, 15)
14
round(123.456)
123
round(123.456, 1)
123.5
round(123.456, ndigits=1)
123.5
cones = Table.read_table('cones.csv')
cones
Flavor | Color | Price | Rating |
---|---|---|---|
strawberry | pink | 3.55 | 1 |
chocolate | light brown | 4.75 | 4 |
chocolate | dark brown | 5.25 | 3 |
strawberry | pink | 5.25 | 2 |
chocolate | dark brown | 5.25 | 5 |
bubblegum | pink | 4.75 | 1 |
cones.show(3)
Flavor | Color | Price | Rating |
---|---|---|---|
strawberry | pink | 3.55 | 1 |
chocolate | light brown | 4.75 | 4 |
chocolate | dark brown | 5.25 | 3 |
... (3 rows omitted)
cones.show()
Flavor | Color | Price | Rating |
---|---|---|---|
strawberry | pink | 3.55 | 1 |
chocolate | light brown | 4.75 | 4 |
chocolate | dark brown | 5.25 | 3 |
strawberry | pink | 5.25 | 2 |
chocolate | dark brown | 5.25 | 5 |
bubblegum | pink | 4.75 | 1 |
cones.select('Flavor')
Flavor |
---|
strawberry |
chocolate |
chocolate |
strawberry |
chocolate |
bubblegum |
cones.select('Flavor', 'Price')
Flavor | Price |
---|---|
strawberry | 3.55 |
chocolate | 4.75 |
chocolate | 5.25 |
strawberry | 5.25 |
chocolate | 5.25 |
bubblegum | 4.75 |
cones.select(Flavor, 'Price')
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In [40], line 1 ----> 1 cones.select(Flavor, 'Price') NameError: name 'Flavor' is not defined
cones.drop('Price')
cones
cones_without_price = cones.drop('Price')
cones_without_price
cones.where('Flavor', 'chocolate')
cones.sort('Price')
cones.sort('Price', descending=True)
cones.sort('Flavor', descending=True)
nba = Table.read_table('nba_salaries.csv').relabeled(3, 'SALARY')
nba
point_guards = nba.where('POSITION', 'PG')
point_guards
point_guards.drop('POSITION')
point_guards
point_guards = point_guards.drop('POSITION')
point_guards.sort('SALARY', descending=True).show()
point_guards.sort('SALARY', descending=True).show(15)
nba.drop('POSITION').where('POSITION', 'PG')