Get startedGet started for free

Explore the baseball data

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 in the editor already includes code to print out informative messages with the different summary statistics and numpy is already loaded as np. Can you finish the job? np_baseball is available.

This exercise is part of the course

Introduction to Python

View Course

Exercise instructions

  • The code to print out the mean height is already included. Complete the code for the median height.
  • Use np.std() on the first column of np_baseball to calculate stddev.
  • 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.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

avg = np.mean(np_baseball[:,0])
print("Average: " + str(avg))

# Print median height
med = ____
print("Median: " + str(med))

# Print out the standard deviation on height
stddev = ____
print("Standard Deviation: " + str(stddev))

# Print out correlation between first and second column
corr = ____
print("Correlation: " + str(corr))
Edit and Run Code