In [1]:
import pandas as pd
import numpy as np
from matplotlib.pyplot import subplots

data = pd.read_csv('nba2013.csv')
data
Out[1]:
Name Position Height Weight Age in 2013
0 DeQuan Jones Guard 80 221 23
1 Darius Miller Guard 80 235 23
2 Trevor Ariza Guard 80 210 28
3 James Jones Guard 80 215 32
4 Wesley Johnson Guard 79 215 26
... ... ... ... ... ...
500 Joel Anthony Center 81 245 31
501 Bismack Biyombo Center 81 229 21
502 Luis Scola Center 81 245 33
503 Lavoy Allen Center 81 225 24
504 Boris Diaw Center 80 235 31

505 rows × 5 columns

In [3]:
mean = data['Weight'].mean()
mean
Out[3]:
np.float64(220.67326732673268)
In [7]:
alpha = 1.2
data[data['Weight'] >= alpha*mean].shape[0]/505
Out[7]:
0.04950495049504951
In [10]:
abs(1/1.2)
Out[10]:
0.8333333333333334
In [9]:
mean = data['Height'].mean()
sd = data['Height'].std()
mean, sd
Out[9]:
(np.float64(79.06534653465347), np.float64(3.454018698179539))
In [12]:
two_sd = (data[abs(data['Height'] - mean) <= 2*sd].shape[0]*100)/data.shape[0]
two_sd
Out[12]:
95.84158415841584
In [14]:
three_sd = (data[abs(data['Height'] - mean) <= 3*sd].shape[0]*100)/data.shape[0]
three_sd
Out[14]:
100.0
In [15]:
one_sd = (data[abs(data['Height'] - mean) <= sd].shape[0]*100)/data.shape[0]
one_sd
Out[15]:
63.56435643564357
In [16]:
data['Height'].hist()
Out[16]:
<Axes: >
No description has been provided for this image
In [17]:
data
Out[17]:
Name Position Height Weight Age in 2013
0 DeQuan Jones Guard 80 221 23
1 Darius Miller Guard 80 235 23
2 Trevor Ariza Guard 80 210 28
3 James Jones Guard 80 215 32
4 Wesley Johnson Guard 79 215 26
... ... ... ... ... ...
500 Joel Anthony Center 81 245 31
501 Bismack Biyombo Center 81 229 21
502 Luis Scola Center 81 245 33
503 Lavoy Allen Center 81 225 24
504 Boris Diaw Center 80 235 31

505 rows × 5 columns

In [19]:
data1 = data.assign(Height_in_std = (data['Height'] - mean)/sd)
data1
Out[19]:
Name Position Height Weight Age in 2013 Height_in_std
0 DeQuan Jones Guard 80 221 23 0.270599
1 Darius Miller Guard 80 235 23 0.270599
2 Trevor Ariza Guard 80 210 28 0.270599
3 James Jones Guard 80 215 32 0.270599
4 Wesley Johnson Guard 79 215 26 -0.018919
... ... ... ... ... ... ...
500 Joel Anthony Center 81 245 31 0.560117
501 Bismack Biyombo Center 81 229 21 0.560117
502 Luis Scola Center 81 245 33 0.560117
503 Lavoy Allen Center 81 225 24 0.560117
504 Boris Diaw Center 80 235 31 0.270599

505 rows × 6 columns

In [21]:
data1['Height_in_std'].hist(density = True)
Out[21]:
<Axes: >
No description has been provided for this image
In [22]:
data = pd.read_csv('united_summer2015.csv')
data
Out[22]:
Date Flight Number Destination Delay
0 6/1/15 73 HNL 257
1 6/1/15 217 EWR 28
2 6/1/15 237 STL -3
3 6/1/15 250 SAN 0
4 6/1/15 267 PHL 64
... ... ... ... ...
13820 8/31/15 1978 LAS -4
13821 8/31/15 1993 IAD 8
13822 8/31/15 1994 ORD 3
13823 8/31/15 2000 PHX -1
13824 8/31/15 2013 EWR -2

13825 rows × 4 columns

In [26]:
data['Delay'].hist(bins = np.arange(-15, 700, 10), density = True)
Out[26]:
<Axes: >
No description has been provided for this image
In [29]:
mean = data['Delay'].mean()
sd = data['Delay'].std()
mean, sd
Out[29]:
(np.float64(16.658155515370705), np.float64(39.48162778440366))
In [ ]:
data1 = data.assign(Delay_in_std = (data['Delay'] - mean)/sd)
data1['Delay_in_std'].hist()
Out[ ]:
<Axes: >
No description has been provided for this image
In [30]:
data = pd.read_csv('baby.csv')
data
Out[30]:
Birth Weight Gestational Days Maternal Age Maternal Height Maternal Pregnancy Weight Maternal Smoker
0 120 284 27 62 100 False
1 113 282 33 64 135 False
2 128 279 28 64 115 True
3 108 282 23 67 125 True
4 136 286 25 62 93 False
... ... ... ... ... ... ...
1169 113 275 27 60 100 False
1170 128 265 24 67 120 False
1171 130 291 30 65 150 True
1172 125 281 21 65 110 False
1173 117 297 38 65 129 False

1174 rows × 6 columns

In [41]:
data['Maternal Height'].hist(bins = np.arange(50, 75, 1), density = True)
Out[41]:
<Axes: >
No description has been provided for this image
In [44]:
from scipy.stats import norm

mean = data['Maternal Height'].mean()
sd = data['Maternal Height'].std()

data1 = data.assign(MH_in_std = (data['Maternal Height'] - mean)/sd)

fig, ax = subplots(figsize = (4, 4))
ax.hist(data1['MH_in_std'], density = True, bins = np.arange(-5, 5, 0.40));
x = np.linspace(-5, 5, 100)
ax.plot(x, norm.pdf(x), 'r-', lw=2)
Out[44]:
[<matplotlib.lines.Line2D at 0x121e21520>]
No description has been provided for this image
In [ ]: