Skip to main content

A simple package to scrape NFL daily fantasy data.

Project description

nfldfs

codecov Testing Check License: MIT HitCount contributions welcome

nfldfs is a Python package for NFL daily fantasy sports analysis. It provides an easy interface to scrape data for DraftKings, FanDuel, and Yahoo! from rotoguru1 so that you don't have to.

Features

  • Search for data using combinations of season and week
  • Return data only for the daily fantasy sites you care about
  • Work with results as a pandas DataFrame or use the CLI to output results directly to a .csv

Installation

nfldfs is supported for Python 3 can be installed via pip:

pip install nfldfs

or from the repo (which may at times be more up-to-date):

# Clone the repo
git clone https://github.com/BrianDoucet01/nfldfs.git
cd nfldfs
python setup.py install

Usage

If you're just looking for a bulk data download, it's recommended that you use the CLI tool. It exports results directly to the nfldfs/data directory in .csv format. Head over there to see a sample of DraftKings salary and points data for the entire 2017 season.

Here are some quick and dirty examples that illustrate how to work with the package interactively. For more robust examples and a data dictionary, refer to the docs folder.

Working with the package interactively

Several examples to show how you could work with the package directly in IPython or a Jupyter Notebook.

Get DraftKings salary and points data for the entire 2019 season.

from nfldfs import games as games

# Scrape DraftKings salary and points data for the entire 2019 season
g = games.find_games('dk', 2019, 1, 2019, 17)
stats = games.get_game_data(g)

type(stats)
pandas.core.frame.DataFrame

# Confirm there's data for weeks 1-17
stats.week.unique()
array([ 1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17])

# Inspect a random sample of 10 rows
stats.sample(10)

       week year      player_name       position team_name home_or_away  \
gid                                                                    
5588    16  2019      Penny, Elijhaa       RB       nyg            a   
5765    11  2019    Spencer, Diontae       WR       den            a   
5556     3  2019      Samuel, Curtis       WR       car            a   
5790    17  2019    Blake, Christian       WR       atl            a   
5649    16  2019      Foster, Robert       WR       buf            a   
7031    12  2019          Washington      Def       was            h   
4675    14  2019       Henry, Hunter       TE       lac            a   
1403     3  2019        Dalton, Andy       QB       cin            a   
5386     3  2019      Lockett, Tyler       WR       sea            h   
1519     7  2019  Trubisky, Mitchell       QB       chi            h  

      opponent_name  points  salary dfs_site  
gid                                          
5588           was    0.00  3000.0       dk  
5765           min    0.00  3000.0       dk  
5556           ari   16.30  4800.0       dk  
5790           tam    0.00  3000.0       dk  
5649           nwe    0.00  3000.0       dk  
7031           det   21.00  3000.0       dk  
4675           jac   11.90  5100.0       dk  
1403           buf   18.06  5300.0       dk  
5386           nor   35.40  6200.0       dk  
1519           nor   20.04  5100.0       dk  

Get data for DraftKings, FanDuel, and Yahoo! for week 2 of the 2018 season.

# Get Yahoo! data for a single week aross multiple seasons
yh = games.find_games(dfs_site='yh',
                     season_from=2018,
                     week_from=1,
                     season_to=2019)
                     week  year    player_name position team_name home_or_away  \
          year gid                                                               
          2018 7030     1  2018      Tennessee      Def       ten            a   
               1225     1  2018   Manning, Eli       QB       nyg            h   
          2019 1539     1  2019  Jones, Daniel       QB       nyg            a   
               5424     1  2019  Diggs, Stefon       WR       min            h   

                    opponent_name  points  salary dfs_site  
          year gid                                          
          2018 7030           mia   11.00    12.0       yh  
               1225           jac    8.16    23.0       yh  
          2019 1539           dal   -0.82    20.0       yh  
               5424           atl    4.70    25.0       yh  

Using the CLI

The command line interface (CLI) was designed for those who just want to download the raw data to use elsewhere; be it a database, Excel, Google Sheets, or another program.

You run the CLI tool by calling it directly from within the package directory. Results are sent to the nfldfs/data directory. Call python cli.py --help for more information on arguments and options.

Example using the CLI to produce the DraftKings sample

CLI tool

Future Work

This project is being actively worked on. If you'd like to contribute, please Fork the project and submit a Pull Request.

  • Adding more functionality to the CLI tool
    • Options to preview data before output
    • Functions for analysis
  • Incorporating more data:
    • Weather
    • Game schedules and slates (Main, Sunday Night etc...)
  • Scraping points and salary data for the current season
  • Downloading projections that are available from various sites

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nfldfs-0.0.5.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nfldfs-0.0.5-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file nfldfs-0.0.5.tar.gz.

File metadata

  • Download URL: nfldfs-0.0.5.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.7

File hashes

Hashes for nfldfs-0.0.5.tar.gz
Algorithm Hash digest
SHA256 14a8e3b4392aa32fe0e81729c03fafd68bdb5897bee0a038a2480cc7d06550f2
MD5 ef3890fe231547520a8f740b61e97525
BLAKE2b-256 e0443b8c572f005a315b0b55318133b4456910dcde23fc550e35e116c5c3b14c

See more details on using hashes here.

File details

Details for the file nfldfs-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: nfldfs-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.7

File hashes

Hashes for nfldfs-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 10414d9bc324a0cc8ce097e3bd79f31f5a75b77079ae2e6b0db3a8211e90d878
MD5 bd21f9edc8a38a81c2dc0e5ea4c4d220
BLAKE2b-256 ef5e0a3001b8ed3a22a3ef68159efd39e689ac700fd06f81ed9d441a4e85cc1a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page