In [1]:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plot
import matplotlib
matplotlib.style.use("ggplot")
%matplotlib inline

In [2]:
# toronto_data = pd.read_csv("toronto_transposed.csv")
toronto_data = pd.read_csv("normalized_data.csv")

In [3]:
toronto_data.head()


Out[3]:
Toronto 118 296 610 746 1075 1114 1241 1246 1285 ... 5428 5580 5596 5719 5807 6046 6070 6125 6140 6141
0 OPR 2015 1.000000 0.516667 0.889855 0.304348 0.343841 0.999638 0.672826 0.490217 0.860145 ... 0.467029 0.256159 0.272101 0.258333 NaN NaN NaN NaN NaN NaN
1 OPR 2014 0.999236 0.518137 0.989309 0.458572 0.707522 1.000000 0.982054 0.000000 0.837724 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
2 OPR 2013 0.997939 0.202988 0.979907 1.000515 0.320969 1.000000 0.962906 1.000515 1.000515 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
3 OPR 2012 0.994595 0.363514 0.957658 1.002252 0.449099 1.000000 0.917568 0.556757 1.002252 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
4 OPR 2011 0.987418 0.321087 0.966281 1.001007 0.880725 1.000000 0.826371 0.781580 1.001007 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN

5 rows × 53 columns


In [4]:
# toronto
toronto_data[:8]


Out[4]:
Toronto 118 296 610 746 1075 1114 1241 1246 1285 ... 5428 5580 5596 5719 5807 6046 6070 6125 6140 6141
0 OPR 2015 1.000000 0.516667 0.889855 0.304348 0.343841 0.999638 0.672826 0.490217 0.860145 ... 0.467029 0.256159 0.272101 0.258333 NaN NaN NaN NaN NaN NaN
1 OPR 2014 0.999236 0.518137 0.989309 0.458572 0.707522 1.000000 0.982054 0.000000 0.837724 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
2 OPR 2013 0.997939 0.202988 0.979907 1.000515 0.320969 1.000000 0.962906 1.000515 1.000515 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
3 OPR 2012 0.994595 0.363514 0.957658 1.002252 0.449099 1.000000 0.917568 0.556757 1.002252 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
4 OPR 2011 0.987418 0.321087 0.966281 1.001007 0.880725 1.000000 0.826371 0.781580 1.001007 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
5 OPR 2010 0.966543 0.114002 0.899628 1.000620 0.013631 1.000000 0.882280 0.456629 1.000620 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
6 OPR 2009 0.972109 0.376871 0.916327 1.004082 0.451701 0.997279 0.822449 0.007483 1.004082 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
7 OPR 2008 0.929672 0.446752 0.608841 1.000670 0.672472 1.000000 0.838580 0.871400 1.000670 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN

8 rows × 53 columns


In [5]:
toronto_data.iloc[[5]]


Out[5]:
Toronto 118 296 610 746 1075 1114 1241 1246 1285 ... 5428 5580 5596 5719 5807 6046 6070 6125 6140 6141
5 OPR 2010 0.966543 0.114002 0.899628 1.00062 0.013631 1 0.88228 0.456629 1.00062 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN

1 rows × 53 columns


In [6]:
def normalize_data(dataframe, num_row=range(1, 9)):
    master_group = []
    for i in dataframe.iloc:
        group = []
        group.append(dataframe[i])
        master_group.append(group)
    return master_group

In [7]:
toronto_data.iloc[[2]]


Out[7]:
Toronto 118 296 610 746 1075 1114 1241 1246 1285 ... 5428 5580 5596 5719 5807 6046 6070 6125 6140 6141
2 OPR 2013 0.997939 0.202988 0.979907 1.000515 0.320969 1 0.962906 1.000515 1.000515 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN

1 rows × 53 columns


In [8]:
team_numbers = toronto_data[:0]
team_numbers_list = list(team_numbers)
del team_numbers_list[0]
# team_numbers_list = map(int, team_numbers_list)
print team_numbers_list


['118', '296', '610', '746', '1075', '1114', '1241', '1246', '1285', '1305', '1310', '1325', '1547', '2013', '2056', '2185', '2198', '2228', '2340', '2634', '2935', '3117', '3541', '3710', '4015', '4152', '4248', '4252', '4308', '4343', '4476', '4525', '4618', '4704', '4732', '4783', '4939', '4976', '5031', '5036', '5076', '5094', '5428', '5580', '5596', '5719', '5807', '6046', '6070', '6125', '6140', '6141']

In [9]:
team_numbers_lister = list(toronto_data[:0])
del team_numbers_lister[0]
team_numbers_lister


Out[9]:
['118',
 '296',
 '610',
 '746',
 '1075',
 '1114',
 '1241',
 '1246',
 '1285',
 '1305',
 '1310',
 '1325',
 '1547',
 '2013',
 '2056',
 '2185',
 '2198',
 '2228',
 '2340',
 '2634',
 '2935',
 '3117',
 '3541',
 '3710',
 '4015',
 '4152',
 '4248',
 '4252',
 '4308',
 '4343',
 '4476',
 '4525',
 '4618',
 '4704',
 '4732',
 '4783',
 '4939',
 '4976',
 '5031',
 '5036',
 '5076',
 '5094',
 '5428',
 '5580',
 '5596',
 '5719',
 '5807',
 '6046',
 '6070',
 '6125',
 '6140',
 '6141']

In [10]:
def make_data_groups(dataframe, column_names):
    master_group = []
    for i in column_names:
        group = []
        group.append(dataframe[i])
        master_group.append(group)
    return master_group

In [11]:
check_it_out = make_data_groups(toronto_data, team_numbers_list)
print check_it_out


[[0    1.000000
1    0.999236
2    0.997939
3    0.994595
4    0.987418
5    0.966543
6    0.972109
7    0.929672
Name: 118, dtype: float64], [0    0.516667
1    0.518137
2    0.202988
3    0.363514
4    0.321087
5    0.114002
6    0.376871
7    0.446752
Name: 296, dtype: float64], [0    0.889855
1    0.989309
2    0.979907
3    0.957658
4    0.966281
5    0.899628
6    0.916327
7    0.608841
Name: 610, dtype: float64], [0    0.304348
1    0.458572
2    1.000515
3    1.002252
4    1.001007
5    1.000620
6    1.004082
7    1.000670
Name: 746, dtype: float64], [0    0.343841
1    0.707522
2    0.320969
3    0.449099
4    0.880725
5    0.013631
6    0.451701
7    0.672472
Name: 1075, dtype: float64], [0    0.999638
1    1.000000
2    1.000000
3    1.000000
4    1.000000
5    1.000000
6    0.997279
7    1.000000
Name: 1114, dtype: float64], [0    0.672826
1    0.982054
2    0.962906
3    0.917568
4    0.826371
5    0.882280
6    0.822449
7    0.838580
Name: 1241, dtype: float64], [0    0.490217
1    0.000000
2    1.000515
3    0.556757
4    0.781580
5    0.456629
6    0.007483
7    0.871400
Name: 1246, dtype: float64], [0    0.860145
1    0.837724
2    1.000515
3    1.002252
4    1.001007
5    1.000620
6    1.004082
7    1.000670
Name: 1285, dtype: float64], [0    0.906159
1    0.193585
2    0.777950
3    0.706306
4    0.877202
5    0.978315
6    0.412925
7    0.944407
Name: 1305, dtype: float64], [0    0.960507
1    0.946544
2    0.962391
3    0.906306
4    0.925516
5    0.915737
6    0.854422
7    0.947756
Name: 1310, dtype: float64], [0    0.969203
1    0.805651
2    0.334364
3    0.484234
4    0.584801
5    0.807931
6    0.065306
7    0.288681
Name: 1325, dtype: float64], [0    0.432609
1    0.242841
2    0.780010
3    0.652703
4    0.324610
5    0.341388
6    0.229932
7    0.567984
Name: 1547, dtype: float64], [0    0.833333
1    0.970599
2    0.837197
3    0.843694
4    0.845496
5    0.758984
6    0.406122
7    0.450770
Name: 2013, dtype: float64], [0    0.998913
1    0.998855
2    0.999485
3    0.999099
4    0.998490
5    0.998141
6    1.000000
7    0.996651
Name: 2056, dtype: float64], [0    0.733696
1    0.716304
2    0.000000
3    0.751802
4    1.001007
5    0.457249
6    0.525170
7    0.000000
Name: 2185, dtype: float64], [0    0.321377
1    0.764796
2    1.000515
3    0.481532
4    0.386512
5    0.000000
6    0.593878
7    0.633624
Name: 2198, dtype: float64], [0    0.914855
1    0.484154
2    0.784132
3    0.963964
4    0.737292
5    0.802354
6    0.557143
7    0.710650
Name: 2228, dtype: float64], [0    0.028986
1    0.690722
2    0.221535
3    0.426126
4    0.607952
5    0.309789
6    0.000000
7    0.774280
Name: 2340, dtype: float64], [0    0.040217
1    0.481863
2    0.327666
3    0.000000
4    0.337192
5    0.446097
6    0.079592
7    0.172137
Name: 2634, dtype: float64], [0    0.505797
1    0.827033
2    0.346213
3    0.076126
4    0.000000
5    0.583643
6    0.496599
7         NaN
Name: 2935, dtype: float64], [0    0.822464
1    0.898435
2    0.934055
3    0.538288
4    0.801711
5    0.358116
6    0.691837
7         NaN
Name: 3117, dtype: float64], [0    0.009420
1    0.217640
2    0.010819
3    0.282432
4    0.842476
5         NaN
6         NaN
7         NaN
Name: 3541, dtype: float64], [0    0.280072
1    0.804506
2    0.430706
3    0.756306
4    0.140413
5         NaN
6         NaN
7         NaN
Name: 3710, dtype: float64], [0    0.000000
1    0.305842
2    0.132921
3    0.121171
4         NaN
5         NaN
6         NaN
7         NaN
Name: 4015, dtype: float64], [0    0.268116
1    0.398244
2    0.190108
3    0.039640
4         NaN
5         NaN
6         NaN
7         NaN
Name: 4152, dtype: float64], [0    0.011957
1    0.014128
2    1.000515
3    0.137838
4         NaN
5         NaN
6         NaN
7         NaN
Name: 4248, dtype: float64], [0    0.301812
1    0.368843
2    0.063885
3    0.613063
4         NaN
5         NaN
6         NaN
7         NaN
Name: 4252, dtype: float64], [0    0.628623
1    0.738832
2    1.000515
3    0.008559
4         NaN
5         NaN
6         NaN
7         NaN
Name: 4308, dtype: float64], [0    0.797464
1    0.801069
2    0.913962
3    0.642342
4         NaN
5         NaN
6         NaN
7         NaN
Name: 4343, dtype: float64], [0    0.856159
1    0.938144
2    0.640907
3         NaN
4         NaN
5         NaN
6         NaN
7         NaN
Name: 4476, dtype: float64], [0    0.717391
1    0.655976
2    0.347759
3         NaN
4         NaN
5         NaN
6         NaN
7         NaN
Name: 4525, dtype: float64], [0    0.802536
1    0.032455
2    0.647604
3         NaN
4         NaN
5         NaN
6         NaN
7         NaN
Name: 4618, dtype: float64], [0    0.134420
1    0.072165
2    0.252962
3         NaN
4         NaN
5         NaN
6         NaN
7         NaN
Name: 4704, dtype: float64], [0    0.143841
1    0.376861
2    0.022669
3         NaN
4         NaN
5         NaN
6         NaN
7         NaN
Name: 4732, dtype: float64], [0    0.162319
1    0.048874
2    0.285420
3         NaN
4         NaN
5         NaN
6         NaN
7         NaN
Name: 4783, dtype: float64], [0    0.401087
1    0.050401
2         NaN
3         NaN
4         NaN
5         NaN
6         NaN
7         NaN
Name: 4939, dtype: float64], [0    0.859058
1    0.830088
2         NaN
3         NaN
4         NaN
5         NaN
6         NaN
7         NaN
Name: 4976, dtype: float64], [0    0.656522
1    0.254296
2         NaN
3         NaN
4         NaN
5         NaN
6         NaN
7         NaN
Name: 5031, dtype: float64], [0    0.184420
1    0.174112
2         NaN
3         NaN
4         NaN
5         NaN
6         NaN
7         NaN
Name: 5036, dtype: float64], [0    0.332246
1    0.116457
2         NaN
3         NaN
4         NaN
5         NaN
6         NaN
7         NaN
Name: 5076, dtype: float64], [0    0.200362
1    0.003818
2         NaN
3         NaN
4         NaN
5         NaN
6         NaN
7         NaN
Name: 5094, dtype: float64], [0    0.467029
1         NaN
2         NaN
3         NaN
4         NaN
5         NaN
6         NaN
7         NaN
Name: 5428, dtype: float64], [0    0.256159
1         NaN
2         NaN
3         NaN
4         NaN
5         NaN
6         NaN
7         NaN
Name: 5580, dtype: float64], [0    0.272101
1         NaN
2         NaN
3         NaN
4         NaN
5         NaN
6         NaN
7         NaN
Name: 5596, dtype: float64], [0    0.258333
1         NaN
2         NaN
3         NaN
4         NaN
5         NaN
6         NaN
7         NaN
Name: 5719, dtype: float64], [0   NaN
1   NaN
2   NaN
3   NaN
4   NaN
5   NaN
6   NaN
7   NaN
Name: 5807, dtype: float64], [0   NaN
1   NaN
2   NaN
3   NaN
4   NaN
5   NaN
6   NaN
7   NaN
Name: 6046, dtype: float64], [0   NaN
1   NaN
2   NaN
3   NaN
4   NaN
5   NaN
6   NaN
7   NaN
Name: 6070, dtype: float64], [0   NaN
1   NaN
2   NaN
3   NaN
4   NaN
5   NaN
6   NaN
7   NaN
Name: 6125, dtype: float64], [0   NaN
1   NaN
2   NaN
3   NaN
4   NaN
5   NaN
6   NaN
7   NaN
Name: 6140, dtype: float64], [0   NaN
1   NaN
2   NaN
3   NaN
4   NaN
5   NaN
6   NaN
7   NaN
Name: 6141, dtype: float64]]

In [12]:
def create_plots(dataframe, column_names):
    for i in column_names:
        plot.boxplot(dataframe[i])
    plot.show()

In [13]:
create_plots(toronto_data, team_numbers_list)


/Users/dinbecevic/anaconda/lib/python2.7/site-packages/numpy/lib/function_base.py:3403: RuntimeWarning: Invalid value encountered in median
  RuntimeWarning)

In [14]:
def make_plots(dataframe, column_names):
    figure = plot.figure(1, figsize=(9, 6))
    ax = figure.add_subplot(111)
    for i in column_names:
        bp = ax.boxplot(dataframe[i])

In [15]:
figure = plot.boxplot(check_it_out)
fig = matplotlib.pyplot.gcf()
fig.set_size_inches(10, 5)



In [16]:
medians = toronto_data.median()
sorted_medians = medians.sort_values()

In [17]:
sorted_med_list = list(sorted_medians)
median_keys = list(sorted_medians.keys())
real_keys = median_keys.reverse()

In [18]:
median_keys


Out[18]:
['6141',
 '6140',
 '6125',
 '6070',
 '6046',
 '5807',
 '746',
 '1285',
 '1114',
 '2056',
 '118',
 '610',
 '1310',
 '1241',
 '4476',
 '4976',
 '2013',
 '1305',
 '3117',
 '4343',
 '2228',
 '4308',
 '4525',
 '4618',
 '2185',
 '2198',
 '1325',
 '1246',
 '2935',
 '5428',
 '5031',
 '1075',
 '3710',
 '1547',
 '296',
 '2340',
 '4252',
 '5596',
 '5719',
 '5580',
 '2634',
 '4152',
 '4939',
 '5076',
 '3541',
 '5036',
 '4783',
 '4732',
 '4704',
 '4015',
 '5094',
 '4248']

In [19]:
check_it_out = make_data_groups(toronto_data, median_keys)

labels = median_keys

figure = plot.boxplot(check_it_out)
plot.title('Standardized OPR from 2008-2015 (Toronto)', fontsize=32)
plot.ylabel('Adjusted OPR', fontsize=24)
plot.xlabel('Team Number', fontsize=24)
fig = matplotlib.pyplot.gcf()
fig.set_size_inches(20, 10)
plot.xticks(range(52), labels, rotation='vertical')
plot.savefig('opr_boxplots.png')



In [20]:
def make_data_groups(dataframe, column_names):
    master_group = []
    for i in column_names:
        group = []
        group.append(dataframe[i])
        master_group.append(group)
    return master_group

def normalize(data):
    normalized_data = []
    for i in data:
        pass
        
check_it_out[0]


Out[20]:
[0   NaN
 1   NaN
 2   NaN
 3   NaN
 4   NaN
 5   NaN
 6   NaN
 7   NaN
 Name: 6141, dtype: float64]

In [21]:
# type(check_it_out)
# type(check_it_out[0][0])
# help(pd.core.series)
[i for i in check_it_out[0][1]]


---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-21-5da00dd0af1b> in <module>()
      2 # type(check_it_out[0][0])
      3 # help(pd.core.series)
----> 4 [i for i in check_it_out[0][1]]

IndexError: list index out of range