Skip to content

Commit

Permalink
Update to be consistent with other books
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanbraun committed Sep 19, 2022
1 parent 5e04e00 commit 87b5a6e
Show file tree
Hide file tree
Showing 22 changed files with 21 additions and 40 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ If I were using Windows, it might look like this:
Set these aside for now and we'll pick them up in chapter 2.

## Changelog
### v0.10.1 (2021-09-19)
Fixed the solution for exercise 5.1 so it's no longer cut off (thanks Graydon!)

### v0.10.0 (2021-09-19)
Misc edits and Anki card updates.

### v0.9.1 (2021-06-16)
Added a note explaning *granularity* in the main text, before asking any end of
chapter exercises on it (thanks Jay!)
Expand Down
Binary file modified anki/02_python.apkg
Binary file not shown.
Binary file added anki/03_00_pandas_basic.apkg
Binary file not shown.
Binary file removed anki/03_01_pandas_basic.apkg
Binary file not shown.
Binary file added anki/03_01_pandas_columns.apkg
Binary file not shown.
Binary file removed anki/03_02_pandas_columns.apkg
Binary file not shown.
File renamed without changes.
Binary file added anki/03_03_pandas_filtering.apkg
Binary file not shown.
Binary file removed anki/03_04_pandas_filtering.apkg
Binary file not shown.
File renamed without changes.
File renamed without changes.
Binary file modified anki/04_sql.apkg
Binary file not shown.
Binary file removed anki/05_01_scraping.apkg
Binary file not shown.
Binary file removed anki/05_02_api.apkg
Binary file not shown.
Binary file added anki/05_scraping.apkg
Binary file not shown.
Binary file added anki/06_stats.apkg
Binary file not shown.
Binary file removed anki/06_summary_stats_plots.apkg
Binary file not shown.
Binary file modified anki/07_modeling.apkg
Binary file not shown.
46 changes: 11 additions & 35 deletions code/02_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@

my_roster_dict['qb']
my_roster_dict['k'] = 'mason crosby'
my_roster_dict

# unpacking
qb, rb = ['tom brady', 'todd gurley']
Expand Down Expand Up @@ -172,6 +173,10 @@
x for x in my_roster_list if x.startswith('a')]
my_roster_a_only

'tom brady'.startswith('a')
'adrian peterson'.startswith('a')
'antonio brown'.startswith('a')

my_roster_a_only_title = [
x.title() for x in my_roster_list if x.startswith('a')]
my_roster_a_only_title
Expand Down Expand Up @@ -220,57 +225,28 @@ def rec_pts_noisy(rec, yds, tds):

rec_pts_noisy(6, 110, 0)

# side effects
def is_player_on_team(player, team):
"""
take a player string and team list and check whether the player is on team
do this by adding the player to the team, then returning True if the player shows up 2 or more times
"""
team.append(player)
return team.count(player) >= 2

my_roster_list = ['tom brady', 'adrian peterson', 'antonio brown']
is_player_on_team('gronk', my_roster_list)

my_roster_list
is_player_on_team('gronk', my_roster_list)

my_roster_list

#############################
# default values in functions
#############################

# error: leaving off a function
# rec_pts(4, 54)

def rec_pts_wdefault(rec=0, yds=0, tds=0):
def rec_pts_wdefault(rec, yds, tds=0):
"""
this function takes number of recieving: yards, receptions and touchdowns
and returns fantasy points scored (ppr scoring)
"""
return yds*0.1 + rec*1 + tds*6

rec_pts_wdefault(4, 54)
rec_pts_wdefault()

def rec_pts2(rec=0, yds=0, tds=0, ppr=1):
"""
takes number of receiving: yards, receptions and touchdowns AND points per
reception and returns fantasy points scored
"""
return yds*0.1 + rec*ppr + tds*6

rec_pts2(4, 54, 0.5) # not doing what we want

54*0.1 + 4*1 + 0.5*6

rec_pts2(4, 54, 0, 0.5) # solution 1
rec_pts2(4, 54, ppr=0.5) # solution 2
# error: leaving off required variable yds
# rec_pts_wdefault(4)

# error: can't put key word argument before positional
# rec_pts2(ppr=0.5, 4, 54)
rec_pts(6, 110, 1)
rec_pts(yds=100, rec=4, tds=2)
rec_pts(4, yds=100, tds=2)

#####################################
# functions that take other functions
Expand Down
5 changes: 2 additions & 3 deletions code/03_00_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

DATA_DIR = '/Users/nathan/fantasybook/data'

adp = pd.read_csv(path.join(DATA_DIR, 'adp_2017.csv')) # adp data

##############
# Loading data
##############
Expand Down Expand Up @@ -41,7 +39,8 @@

type(adp[['name', 'position', 'adp']])

# adp['name', 'position', 'adp'].head() # commented out because it throws an error
# commented out because it throws an error
# adp['name', 'position', 'adp'].head()

##########
# Indexing
Expand Down
2 changes: 1 addition & 1 deletion code/03_01_columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# stored
# on Windows it might be something like 'C:/mydir'

DATA_DIR = '/Users/nathan/fantasybook/data'
DATA_DIR = './data'

# load player-game data
pg = pd.read_csv(path.join(DATA_DIR, 'player_game_2017_sample.csv'))
Expand Down
2 changes: 1 addition & 1 deletion solutions-to-exercises/03_pandas_answers.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
import pandas as pd
from os import path

DATA_DIR = '/Users/nathan/fantasybook/data'
DATA_DIR = './data'
pg = pd.read_csv(path.join(DATA_DIR, 'player_game_2017_sample.csv'))

#######
Expand Down

0 comments on commit 87b5a6e

Please sign in to comment.