-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathexplore-the-baseball-data.py
More file actions
38 lines (31 loc) · 1.37 KB
/
explore-the-baseball-data.py
File metadata and controls
38 lines (31 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
'''
Explore the baseball data
100xp
Because the mean and median are so far apart, you decide to complain to the MLB.
They find the error and send the corrected data over to you. It's again available
as a 2D Numpy array np_baseball, with three columns.
The Python script on the right already includes code to print out informative messages
with the different summary statistics. Can you finish the job?
Instructions
-The code to print out the mean height is already included. Complete the code for the
median height. Replace None with the correct code.
-Use np.std() on the first column of np_baseball to calculate stddev. Replace None with
the correct code.
-Do big players tend to be heavier? Use np.corrcoef() to store the correlation between
the first and second column of np_baseball in corr. Replace None with the correct code.
'''
# np_baseball is available
# Import numpy
import numpy as np
# Print mean height (first column)
avg = np.mean(np_baseball[:,0])
print("Average: " + str(avg))
# Print median height. Replace 'None'
med = np.median(np_baseball[:,0])
print("Median: " + str(med))
# Print out the standard deviation on height. Replace 'None'
stddev = np.std(np_baseball[:,0])
print("Standard Deviation: " + str(stddev))
# Print out correlation between first and second column. Replace 'None'
corr = np.corrcoef(np_baseball[:,0], np_baseball[:,1])
print("Correlation: " + str(corr))