Vous êtes sur la page 1sur 3

Name: Docto, Jeloux P.

APPLIED DATA SCIENCE

WORKSHEET #3: PYTHON DATA SCIENCE TOOLBOX

1 Date: March 4, 2020


Refer to the following line of code: np.array([True,1,2]) + np.array([3,4,False])
Which code chunk builds the exact same Python object?
A. np.array([True,1,2,3,4,False])
B. np.array([4,3,0]) + np.array([0,2,2]) B.
C. np.array([1,1,2]) + np.array([3,4,-1])
D. np.array([0,1,2,3,4,5])

2 Date: March 4, 2020


Create a list of lists. The individual lists should contain, in the correct order, the height (in inches), the weight (in pounds) and the
age of the baseball players.

Heights: 74 74 72 72 73 69 69 71 76 71 73 73 74 74 69 70 73 75 78 79
Weights: 180 215 210 210 188 176 209 200 231 180 188 180 185 160 180 185 189 185 219 230
Ages: 23 35 31 36 36 30 31 36 31 28 24 27 24 27 28 35 28 23 23 26

Convert the list of lists into a NumPy array named np_baseball. Using NumPy functionality, convert the unit of height to m and
that of weight to kg. Print the resulting array.

Write the code here and take a snapshot of the output using the Web Note function of the Jupyter notebook. Paste the snapshot
into an MS Word file and submit through Cardinal Edge Worksheet Submission.
Code
height_in=[74,74,72.72,73,69,69,71,76,71,73,73,74,74,69,70,73,75,78,79]
weight_lb=[180,215,210,210,188,176,209,200,231,180,188,180,185,160,180,185,189,185,219,230]
age=[23,35,31,36,36,30,31,36,31,28,24,27,24,27,28,35,28,23,23,26]
import numpy as np
np_height_in=np.array(height_in)
np_weight_lb=np.array(weight_lb)
np_age=np.array(age)
np_height_m =np_height_in * 0.0254
np_weight_kg=np_weight_lb * 0.453592
print (np_height_m)
print (np_weight_kg)

BB Submission

Page 1 of 3
Name: Docto, Jeloux P. APPLIED DATA SCIENCE

WORKSHEET #3: PYTHON DATA SCIENCE TOOLBOX

3 Date:
Write a code that determines the age of the 8th player. The output should be in the following form:
The 8th player is <age> years old.
Code
age=[23,35,31,36,36,30,31,36,31,28,24,27,24,27,28,35,28,23,23,26]
import numpy as np
print ("The 8th player is", age[9], "years old.")

Output

4 Date:
Print out the ages of the young players (those who are 25 years old and below).
Code
age=[23,35,31,36,36,30,31,36,31,28,24,27,24,27,28,35,28,23,23,26]
import numpy as np
np_age=np.array(age)

young = np_age < 25


print (young)
print (np_age[young])

Output

5 Date:
Print out the average weight, median height and median age of the players. The output should be in the following form:
Average Weight: <average weight>
Median Height: <median height>
Median Age: <median age>
Code
height = [74, 74, 72, 72, 73, 69, 69, 71, 76, 71, 73, 73, 74, 74, 69, 70, 73, 75, 78, 79]
weight = [180, 215, 210, 210, 188, 176, 209, 200, 231, 180, 188, 180, 185, 160, 180, 185, 189, 185, 219, 230]
age = [23, 35, 31, 36, 36, 30, 31, 36, 31, 28, 24, 27, 24, 27, 28, 35, 28, 23, 23, 26]
import numpy as np
Page 2 of 3
Name: Docto, Jeloux P. APPLIED DATA SCIENCE

WORKSHEET #3: PYTHON DATA SCIENCE TOOLBOX

import statistics

baseball_players =
[[74,180,23],[74,215,35],[72,210,31],[72,210,36],[73,188,36],[69,176,30],[69,209,31],[71,200,36],[76,231,31],[71,180,28],[73,188,
24],[73,180,27],[74,185,24],[74,160,27],[69,180,28],[70,185,35],[73,189,28],[75,185,23],[78,219,23],[79,230,26]]

np_height = np.array(height)
np_weight = np.array(weight)
np_age = np.array(age)
np_baseball = np.array(baseball_players)

average = sum(np_weight)/len(np_weight)
median_height = statistics.median(np_height)
median_age = statistics.median(np_age)
print ("Average Weight:",average)
print ("Median Height:",median_height)
print ("Median Age:",median_age)

Output

Page 3 of 3

Vous aimerez peut-être aussi