Skip to content

Introduction to Python

Run the hidden code cell below to import the data used in this course.


1 hidden cell

Take Notes

  • Lists vs arrays. Arrays are like vectors. You can multiple the whole array with a number and it will be fine but you cannot do that with a list. Also a list can take a combo of types of variables but not an array.
  • In lists if you have a list x=[] and then equate y=x and change something in y then x changes too because behind the scenes y refers to x.
# Add your code snippets here
areas = [11.25, 18.0, 20.0, 10.75, 9.50]

# Print out the index of the element 20.0
print(areas.index(20.0))

# Print out how often 9.50 appears in areas
print(areas.count(9.50))
import numpy as np
bmi = np.array([32,21,16,23,25,27,28])

# Create the light array
light = bmi < 21
#In order to create a new array you don't need to do loops etc. Python is smart and gets the above. Gives you a boolean array.
print(light)

Explore Datasets

Use the arrays imported in the first cell to explore the data and practice your skills!

  • Print out the weight of the first ten baseball players.
  • What is the median weight of all baseball players in the data?
  • Print out the names of all players with a height greater than 80 (heights are in inches).
  • Who is taller on average? Baseball players or soccer players? Keep in mind that baseball heights are stored in inches!
  • The values in soccer_shooting are decimals. Convert them to whole numbers (e.g., 0.98 becomes 98).
  • Do taller players get higher ratings? Calculate the correlation between soccer_ratings and soccer_heights to find out!
  • What is the average rating for attacking players ('A')?