In [2]:
from usau.reports import USAUResults as Results

In [28]:
!readlink -e ../usau/data2/


/c/Users/Dev/Desktop/Python/usau-py/usau/data2

In [22]:
import os
os.path.getcwd()


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-22-29ab7df7925e> in <module>()
      1 import os
----> 2 os.path.getcwd()

AttributeError: module 'ntpath' has no attribute 'getcwd'

In [29]:
results = {}
for year in (2015, 2016, 2017, 2018):
    for gender in ("Men", "Women"):
        res = Results.from_event("d1college", year, gender)
        if year != 2018:
            res.load_from_csvs("../usau/data2")
        else:
            res.load_from_csvs()
        results[year, gender] = res

In [73]:
%matplotlib inline
import matplotlib
import matplotlib.pyplot as plt
import seaborn as sns
sns.set_style("whitegrid")
matplotlib.rcParams.update({'font.size': 14})

In [69]:
import pandas as pd
all_diffs = []
for (year, gender), res in results.items():
    match = res.match_results
    is_game = (match["Score"] + match["Opp Score"] > 10).values
    diffs = pd.DataFrame({"division": "%s %s" % (gender, year),
                          "gender": gender,
                          "year": year,
                          "diff": (match.loc[is_game, "Score"] - match.loc[is_game, "Opp Score"]).abs()})
    all_diffs.append(diffs)
all_diffs = pd.concat(all_diffs).sort_values(["division"]) # .set_index(["gender", "year"])

In [74]:
fig, ax = plt.subplots(figsize=(11, 6))
sns.violinplot(data=all_diffs, x="year", y="diff", hue="gender")
ax.set(ylim=(0, 15))
ax.set_title("Point differential between winning and losing teams, at D-I college nationals")
all_diffs.groupby("division")["diff"].describe()


Out[74]:
count mean std min 25% 50% 75% max
division
Men 2015 106.0 4.132075 2.251245 1.0 3.0 4.0 5.00 11.0
Men 2016 106.0 3.679245 2.459373 1.0 2.0 3.0 5.00 13.0
Men 2017 110.0 4.272727 2.373049 1.0 2.0 4.0 6.75 10.0
Men 2018 92.0 4.739130 2.696638 1.0 2.0 4.0 7.00 11.0
Women 2015 108.0 5.944444 3.191207 1.0 4.0 5.0 8.00 14.0
Women 2016 82.0 5.024390 3.138670 1.0 3.0 5.0 6.00 13.0
Women 2017 110.0 5.345455 3.160642 1.0 3.0 5.0 7.00 13.0
Women 2018 92.0 6.086957 2.896197 1.0 4.0 6.0 8.00 13.0

In [71]:



Out[71]:
count mean std min 25% 50% 75% max
division
Men 2015 106.0 4.132075 2.251245 1.0 3.0 4.0 5.00 11.0
Men 2016 106.0 3.679245 2.459373 1.0 2.0 3.0 5.00 13.0
Men 2017 110.0 4.272727 2.373049 1.0 2.0 4.0 6.75 10.0
Men 2018 92.0 4.739130 2.696638 1.0 2.0 4.0 7.00 11.0
Women 2015 108.0 5.944444 3.191207 1.0 4.0 5.0 8.00 14.0
Women 2016 82.0 5.024390 3.138670 1.0 3.0 5.0 6.00 13.0
Women 2017 110.0 5.345455 3.160642 1.0 3.0 5.0 7.00 13.0
Women 2018 92.0 6.086957 2.896197 1.0 4.0 6.0 8.00 13.0

In [7]:
m2017 = Results.from_event("d1college", 2017, "Men")

In [8]:
m2017.load_from_csvs()


Out[8]:
USAUResults<2017_d1college_nationals_men>

In [10]:
res = m2017.match_results

In [11]:
(res["Score"] - res["Opp Score"]).abs().describe()


Out[11]:
count    110.000000
mean       4.272727
std        2.373049
min        1.000000
25%        2.000000
50%        4.000000
75%        6.750000
max       10.000000
dtype: float64

In [13]:
m2018 = Results.from_event("d1college", 2018, "Men")
m2018.load_from_csvs()


Out[13]:
USAUResults<2018_d1college_nationals_men>

In [14]:
res = m2018.match_results

In [19]:
is_game = (res["Score"] + res["Opp Score"] > 0).values
(res.loc[is_game, "Score"] - res.loc[is_game, "Opp Score"]).abs().describe()


Out[19]:
count    92.000000
mean      4.739130
std       2.696638
min       1.000000
25%       2.000000
50%       4.000000
75%       7.000000
max      11.000000
dtype: float64

In [20]:
%matplotlib inline
import matplotlib.pyplot as plt


---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-20-033ff7115bce> in <module>()
----> 1 get_ipython().run_line_magic('matplotlib', 'inline')
      2 import matplotlib.pyplot as plt

C:\Anaconda\envs\2018_usau\lib\site-packages\IPython\core\interactiveshell.py in run_line_magic(self, magic_name, line, _stack_depth)
   2129                 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals
   2130             with self.builtin_trap:
-> 2131                 result = fn(*args,**kwargs)
   2132             return result
   2133 

<decorator-gen-108> in matplotlib(self, line)

C:\Anaconda\envs\2018_usau\lib\site-packages\IPython\core\magic.py in <lambda>(f, *a, **k)
    185     # but it's overkill for just that one bit of state.
    186     def magic_deco(arg):
--> 187         call = lambda f, *a, **k: f(*a, **k)
    188 
    189         if callable(arg):

C:\Anaconda\envs\2018_usau\lib\site-packages\IPython\core\magics\pylab.py in matplotlib(self, line)
     97             print("Available matplotlib backends: %s" % backends_list)
     98         else:
---> 99             gui, backend = self.shell.enable_matplotlib(args.gui)
    100             self._show_matplotlib_backend(args.gui, backend)
    101 

C:\Anaconda\envs\2018_usau\lib\site-packages\IPython\core\interactiveshell.py in enable_matplotlib(self, gui)
   3037         """
   3038         from IPython.core import pylabtools as pt
-> 3039         gui, backend = pt.find_gui_and_backend(gui, self.pylab_gui_select)
   3040 
   3041         if gui != 'inline':

C:\Anaconda\envs\2018_usau\lib\site-packages\IPython\core\pylabtools.py in find_gui_and_backend(gui, gui_select)
    271     """
    272 
--> 273     import matplotlib
    274 
    275     if gui and gui != 'auto':

ModuleNotFoundError: No module named 'matplotlib'

In [16]:
res[]


Out[16]:
Unnamed: 0 As Ds Gs Opp Score Opp Seed Opponent Score Seed Team Ts url
0 0 15 6 15 9 20 Florida State 15 9 Pittsburgh 9 /teams/events/match_report/?EventGameId=v9pEa1...
1 1 9 3 9 15 9 Pittsburgh 9 20 Florida State 14 /teams/events/match_report/?EventGameId=v9pEa1...
2 0 14 15 14 8 16 Victoria 14 9 Pittsburgh 21 /teams/events/match_report/?EventGameId=Zfd8qU...
3 1 5 2 8 14 9 Pittsburgh 8 16 Victoria 23 /teams/events/match_report/?EventGameId=Zfd8qU...
4 0 0 0 0 11 17 Northwestern 15 4 Brown 0 /teams/events/match_report/?EventGameId=rGOHL%...
5 1 0 0 0 15 4 Brown 11 17 Northwestern 0 /teams/events/match_report/?EventGameId=rGOHL%...
6 0 13 11 13 14 18 Connecticut 13 14 William & Mary 20 /teams/events/match_report/?EventGameId=PFip0a...
7 1 14 4 14 13 14 William & Mary 14 18 Connecticut 18 /teams/events/match_report/?EventGameId=PFip0a...
8 0 15 9 15 6 19 Georgetown 15 3 Oregon 11 /teams/events/match_report/?EventGameId=ee%2fg...
9 1 6 5 6 15 3 Oregon 6 19 Georgetown 17 /teams/events/match_report/?EventGameId=ee%2fg...
10 0 11 12 11 10 15 Maryland 11 10 Wisconsin 33 /teams/events/match_report/?EventGameId=keyqJS...
11 1 10 15 10 11 10 Wisconsin 10 15 Maryland 31 /teams/events/match_report/?EventGameId=keyqJS...
12 0 15 8 15 8 18 Connecticut 15 7 Minnesota 7 /teams/events/match_report/?EventGameId=1i%2b7...
13 1 8 3 8 15 7 Minnesota 8 18 Connecticut 13 /teams/events/match_report/?EventGameId=1i%2b7...
14 0 11 2 11 13 19 Georgetown 11 15 Maryland 13 /teams/events/match_report/?EventGameId=eodYFp...
15 1 13 7 13 11 15 Maryland 13 19 Georgetown 14 /teams/events/match_report/?EventGameId=eodYFp...
16 0 0 0 0 14 6 Georgia 9 11 Texas 0 /teams/events/match_report/?EventGameId=GEyfw9...
17 1 0 0 0 9 11 Texas 14 6 Georgia 0 /teams/events/match_report/?EventGameId=GEyfw9...
18 0 11 8 11 13 11 Texas 10 7 Minnesota 20 /teams/events/match_report/?EventGameId=7uvgrw...
19 1 13 6 13 10 7 Minnesota 13 11 Texas 20 /teams/events/match_report/?EventGameId=7uvgrw...
20 0 11 4 11 15 9 Pittsburgh 11 5 Washington 13 /teams/events/match_report/?EventGameId=VVNuek...
21 1 14 9 14 11 5 Washington 15 9 Pittsburgh 6 /teams/events/match_report/?EventGameId=VVNuek...
22 0 15 7 15 7 12 Stanford 15 8 Massachusetts 4 /teams/events/match_report/?EventGameId=gZ2zmt...
23 1 7 6 7 15 8 Massachusetts 7 12 Stanford 11 /teams/events/match_report/?EventGameId=gZ2zmt...
24 0 11 10 10 13 14 William & Mary 11 2 North Carolina 24 /teams/events/match_report/?EventGameId=7WW3aP...
25 1 13 10 13 11 2 North Carolina 13 14 William & Mary 22 /teams/events/match_report/?EventGameId=7WW3aP...
26 0 15 6 15 8 11 Texas 15 2 North Carolina 7 /teams/events/match_report/?EventGameId=gHKeVM...
27 1 8 3 8 15 2 North Carolina 8 11 Texas 8 /teams/events/match_report/?EventGameId=gHKeVM...
28 0 12 7 12 14 5 Washington 12 4 Brown 10 /teams/events/match_report/?EventGameId=uchWcS...
29 1 14 7 14 12 4 Brown 14 5 Washington 10 /teams/events/match_report/?EventGameId=uchWcS...
... ... ... ... ... ... ... ... ... ... ... ... ...
74 0 10 7 10 15 17 Northwestern 10 12 Stanford 18 /teams/events/match_report/?EventGameId=3aYwjS...
75 1 15 7 15 10 12 Stanford 15 17 Northwestern 16 /teams/events/match_report/?EventGameId=3aYwjS...
76 0 14 10 14 11 20 Florida State 14 5 Washington 12 /teams/events/match_report/?EventGameId=5k0POU...
77 1 11 5 11 14 5 Washington 11 20 Florida State 13 /teams/events/match_report/?EventGameId=5k0POU...
78 0 13 5 13 12 19 Georgetown 13 6 Georgia 12 /teams/events/match_report/?EventGameId=j1cFAp...
79 1 12 5 12 13 6 Georgia 12 19 Georgetown 11 /teams/events/match_report/?EventGameId=j1cFAp...
80 0 15 4 15 8 14 William & Mary 15 7 Minnesota 12 /teams/events/match_report/?EventGameId=Xkp9%2...
81 1 6 4 7 15 7 Minnesota 8 14 William & Mary 16 /teams/events/match_report/?EventGameId=Xkp9%2...
82 0 12 10 12 10 12 Stanford 12 1 Carleton College 11 /teams/events/match_report/?EventGameId=uNqK00...
83 1 10 7 10 12 1 Carleton College 10 12 Stanford 10 /teams/events/match_report/?EventGameId=uNqK00...
84 0 15 5 15 4 7 Minnesota 15 2 North Carolina 4 /teams/events/match_report/?EventGameId=9xMuau...
85 1 4 0 4 15 2 North Carolina 4 7 Minnesota 15 /teams/events/match_report/?EventGameId=9xMuau...
86 0 0 0 0 11 19 Georgetown 15 14 William & Mary 0 /teams/events/match_report/?EventGameId=cQATe4...
87 1 0 0 0 15 14 William & Mary 11 19 Georgetown 0 /teams/events/match_report/?EventGameId=cQATe4...
88 0 0 0 0 0 3 Oregon 0 4 Brown 0 /teams/events/match_report/?EventGameId=sRjKjj...
89 1 0 0 0 0 4 Brown 0 3 Oregon 0 /teams/events/match_report/?EventGameId=sRjKjj...
90 0 15 6 15 11 18 Connecticut 15 11 Texas 8 /teams/events/match_report/?EventGameId=Lz%2bk...
91 1 11 4 11 15 11 Texas 11 18 Connecticut 13 /teams/events/match_report/?EventGameId=Lz%2bk...
92 0 14 9 15 8 18 Connecticut 15 2 North Carolina 9 /teams/events/match_report/?EventGameId=e53zjL...
93 1 7 3 7 15 2 North Carolina 8 18 Connecticut 16 /teams/events/match_report/?EventGameId=e53zjL...
94 0 13 10 15 6 8 Massachusetts 15 1 Carleton College 16 /teams/events/match_report/?EventGameId=eUAs%2...
95 1 6 8 6 15 1 Carleton College 6 8 Massachusetts 25 /teams/events/match_report/?EventGameId=eUAs%2...
96 0 10 10 10 12 17 Northwestern 10 13 Auburn 20 /teams/events/match_report/?EventGameId=xsOfkq...
97 1 12 10 12 10 13 Auburn 12 17 Northwestern 20 /teams/events/match_report/?EventGameId=xsOfkq...
98 0 15 6 15 8 16 Victoria 15 4 Brown 10 /teams/events/match_report/?EventGameId=7qScwA...
99 1 8 7 8 15 4 Brown 8 16 Victoria 12 /teams/events/match_report/?EventGameId=7qScwA...
100 0 0 0 0 14 12 Stanford 15 20 Florida State 0 /teams/events/match_report/?EventGameId=t%2fSk...
101 1 0 0 0 15 20 Florida State 14 12 Stanford 0 /teams/events/match_report/?EventGameId=t%2fSk...
102 0 0 0 0 12 7 Minnesota 13 10 Wisconsin 0 /teams/events/match_report/?EventGameId=WHhjMS...
103 1 0 0 0 13 10 Wisconsin 12 7 Minnesota 0 /teams/events/match_report/?EventGameId=WHhjMS...

104 rows × 12 columns


In [ ]: