Skip to content

Introduction to Python

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


1 hidden cell

Subsetting Lists

List slicing

  • important to know when slicing, first index is inclusive while second is exclusive
  • fam[3:5] will return values of index 3 and 4 because index 3 is inclusive while 5 is exclusive

Manipulating Lists

  • importatnt to remember that when assigning an existing list to a new variable, and if you then changed a value of the list from the new variable, it will change the original list itself:

x = ["a", "b", "c"] y = x y[1] = "z" y Result: ["a", "z", "c"] x Result: ["a", "z","c"]

This is because the variable x and y are simily poininting to a reference of the stored list, they are not storing the list themselves. To avoid x being changed in this situation, use:

y = list(x) OR y = x[:] before doing y[1] = "z"

Add your notes here

# Add your code snippets here

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')?