Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting Play by Play Data #2

Open
theSanchize3 opened this issue Dec 17, 2016 · 4 comments
Open

Getting Play by Play Data #2

theSanchize3 opened this issue Dec 17, 2016 · 4 comments

Comments

@theSanchize3
Copy link

I am interested in trying to predict offensive playcalls for the NFL. Is there a way to get play by play data with info about what type of play was called (run left, run right, run middle, deep pass, short pass, etc). Even just knowing if the play was a run or a pass is enough. If so, can you suggest a script that would do so?

Thanks,
Sanchez

@mdgoldberg
Copy link
Owner

mdgoldberg commented Dec 19, 2016

It is possible, in fact I have done a very similar project already! You can read about it here. To get play by play data, check out the nfl.BoxScore.pbp function, used as so:

from sportsref import nfl
bs = nfl.BoxScore('201602070den')
df = bs.pbp()
# df is a DataFrame of play-by-play data, where each row is a play

It's not perfect, but it will have the main categories. For what purposes are you interested in predicting playcalls?

@theSanchize3
Copy link
Author

theSanchize3 commented Dec 20, 2016

Thanks. That article is very similar what I was planning on doing. When I ran the code you suggested, though, I got this error:

----> 1 from sportsref import nfl
      2 bs = nfl.BoxScore('201602070den')
      3 df = bs.pbp()
      4 # df is a DataFrame of play-by-play data, where each row is a play

C:\Users\Jacob\Anaconda2\lib\site-packages\sportsref\__init__.py in <module>()
     10 import decorators
     11 import utils
---> 12 import nfl
     13 import nba
     14 

C:\Users\Jacob\Anaconda2\lib\site-packages\sportsref\nfl\__init__.py in <module>()
----> 1 import finders
      2 import teams
      3 import players
      4 import boxscores
      5 import winProb

C:\Users\Jacob\Anaconda2\lib\site-packages\sportsref\nfl\finders\__init__.py in <module>()
     13 # Fill in PlayerSeasonFinder docstring
     14 
---> 15 IOD = PSF.inputs_options_defaults()
     16 
     17 paramStr = '\n'.join(

C:\Users\Jacob\Anaconda2\lib\site-packages\sportsref\decorators.pyc in wrapper(*args, **kwargs)
     27             orig_cwd = os.getcwd()
     28             os.chdir(dirPath)
---> 29             ret = func(*args, **kwargs)
     30             os.chdir(orig_cwd)
     31             return ret

C:\Users\Jacob\Anaconda2\lib\site-packages\sportsref\nfl\finders\PSF.pyc in inputs_options_defaults()
    168         print 'Regenerating PSFConstants file'
    169 
--> 170         html = utils.get_html(PSF_URL)
    171         doc = pq(html)
    172 

C:\Users\Jacob\Anaconda2\lib\site-packages\sportsref\decorators.pyc in wrapper(*args, **kwargs)
    197             return ret
    198         except KeyError:
--> 199             cache[key] = fun(*args, **kwargs)
    200             ret = _copy(cache[key])
    201             return ret

C:\Users\Jacob\Anaconda2\lib\site-packages\sportsref\decorators.pyc in wrapper(url)
    147         # otherwise, download html and cache it
    148         else:
--> 149             text = func(url)
    150             with open(filename, 'w+') as f:
    151                 f.write(text.encode('ascii', 'replace'))

C:\Users\Jacob\Anaconda2\lib\site-packages\sportsref\utils.pyc in get_html(url)
     23     start = time.time()
     24     browser = webdriver.PhantomJS(service_args=['--load-images=false'],
---> 25                                   service_log_path='/dev/null')
     26     browser.set_window_size(10000, 10000)
     27     browser.get(url)

C:\Users\Jacob\Anaconda2\lib\site-packages\selenium\webdriver\phantomjs\webdriver.pyc in __init__(self, executable_path, port, desired_capabilities, service_args, service_log_path)
     49             port=port,
     50             service_args=service_args,
---> 51             log_path=service_log_path)
     52         self.service.start()
     53 

C:\Users\Jacob\Anaconda2\lib\site-packages\selenium\webdriver\phantomjs\service.pyc in __init__(self, executable_path, port, service_args, log_path)
     48             self._cookie_temp_file = None
     49 
---> 50         service.Service.__init__(self, executable_path, port=port, log_file=open(log_path, 'w'))
     51 
     52     def _args_contain(self, arg):

IOError: [Errno 2] No such file or directory: '/dev/null'

Do you how to fix this error?

@mdgoldberg
Copy link
Owner

mdgoldberg commented Dec 21, 2016 via email

@theSanchize3
Copy link
Author

I waht to see if I can determine which coaches are the most predictable, and if i can do that, determine if predictability affects success in any way. And thank you, I'll try it again when I get a chance.

abeard1 referenced this issue in abeard1/sportsref Jan 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants