In [1]:
import pandas as pd
import numpy as np
from matplotlib.pyplot import subplots
In [2]:
data = pd.read_csv('united_summer2015.csv')
data
Out[2]:
| 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 [3]:
data['Delay'].hist(bins = np.arange(-15, 600, 20), density = True)
Out[3]:
<Axes: >
In [4]:
mean_delay = data['Delay'].mean()
sd_delay = data['Delay'].std()
mean_delay, sd_delay
Out[4]:
(np.float64(16.658155515370705), np.float64(39.48162778440366))
In [5]:
num_repetitions = 10000
L_100 = []
for i in range(num_repetitions):
sample = data.sample(100, replace = True)
L_100.append(sample['Delay'].mean())
L_400 = []
for i in range(num_repetitions):
sample = data.sample(400, replace = True)
L_400.append(sample['Delay'].mean())
L_625 = []
for i in range(num_repetitions):
sample = data.sample(625, replace = True)
L_625.append(sample['Delay'].mean())
fig, ax = subplots(figsize = (8, 4))
ax.hist(L_100, bins = np.arange(0, 35, 0.5), density = True, alpha = 0.5, label='sample size 100');
ax.hist(L_400, bins = np.arange(0, 35, 0.5), density = True, alpha = 0.5, label='sample size 400');
ax.hist(L_625, bins = np.arange(0, 35, 0.5), density = True, alpha = 0.5, label='sample size 625');
ax.legend()
Out[5]:
<matplotlib.legend.Legend at 0x10dee9970>
In [6]:
print('population mean: ', mean_delay)
print('population sd: ', sd_delay)
print('SD of 100 size sample: ', np.std(L_100), 'population sd/sqrt(n): ', sd_delay/np.sqrt(100))
print('SD of 400 size sample: ', np.std(L_400), 'population sd/sqrt(n): ', sd_delay/np.sqrt(400))
print('SD of 625 size sample: ', np.std(L_625), 'population sd/sqrt(n): ', sd_delay/np.sqrt(625))
population mean: 16.658155515370705 population sd: 39.48162778440366 SD of 100 size sample: 3.9409088987581278 population sd/sqrt(n): 3.9481627784403663 SD of 400 size sample: 1.96880221956649 population sd/sqrt(n): 1.9740813892201832 SD of 625 size sample: 1.5809695898057818 population sd/sqrt(n): 1.5792651113761464
In [7]:
data = pd.read_csv('hybrid.csv')
data
Out[7]:
| vehicle | year | msrp | acceleration | mpg | class | |
|---|---|---|---|---|---|---|
| 0 | Prius (1st Gen) | 1997 | 24509.74 | 7.46 | 41.26 | Compact |
| 1 | Tino | 2000 | 35354.97 | 8.20 | 54.10 | Compact |
| 2 | Prius (2nd Gen) | 2000 | 26832.25 | 7.97 | 45.23 | Compact |
| 3 | Insight | 2000 | 18936.41 | 9.52 | 53.00 | Two Seater |
| 4 | Civic (1st Gen) | 2001 | 25833.38 | 7.04 | 47.04 | Compact |
| ... | ... | ... | ... | ... | ... | ... |
| 148 | S400 | 2013 | 92350.00 | 13.89 | 21.00 | Large |
| 149 | Prius Plug-in | 2013 | 32000.00 | 9.17 | 50.00 | Midsize |
| 150 | C-Max Energi Plug-in | 2013 | 32950.00 | 11.76 | 43.00 | Midsize |
| 151 | Fusion Energi Plug-in | 2013 | 38700.00 | 11.76 | 43.00 | Midsize |
| 152 | Chevrolet Volt | 2013 | 39145.00 | 11.11 | 37.00 | Compact |
153 rows × 6 columns
In [8]:
fig, ax = subplots(figsize = (4,4))
ax.scatter(data['msrp'], data['acceleration']);
In [9]:
fig, ax = subplots(figsize = (4,4))
ax.scatter(data['mpg'], data['acceleration'])
Out[9]:
<matplotlib.collections.PathCollection at 0x10e167280>
In [ ]: