Skip to content
1 hidden cell
Introduction to Python
Introduction to Python
Run the hidden code cell below to import the data used in this course.
1 hidden cell
Take Notes
Add notes about the concepts you've learned and code cells with code you want to keep.
#list()= para modificar una lista sin alterar la anterior
# Add your code snippets hereExplore 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_shootingare decimals. Convert them to whole numbers (e.g., 0.98 becomes 98). - Do taller players get higher ratings? Calculate the correlation between
soccer_ratingsandsoccer_heightsto find out! - What is the average rating for attacking players (
'A')?
# string to experiment with: place
place = "poolhouse"
# Use upper() on place: place_up
place_up=place.upper()
# Print out place and place_up
print(place_up)
# Print out the number of o's in place
print(place.count('o'))
print(place)# Create list areas
areas = [11.25, 18.0, 20.0, 10.75, 9.50]
# Print out the index of the element 20.0
print(areas.index(20))
# Print out how often 9.50 appears in areas
print(areas.count(9.50))
# Create list areas
areas = [11.25, 18.0, 20.0, 10.75, 9.50]
# Use append twice to add poolhouse and garage size
areas.append(24.5)
areas.append(15.45)
# Print out areas
print(areas)
# Reverse the orders of the elements in areas
areas.reverse()
# Print out areas
print(areas)In [7]:
from scipy.linalg import inv as my_inv
In [8]:
my_inv([[1,2], [3,4]])
Out[8]:
array([[-2. , 1. ],
[ 1.5, -0.5]])#nampay --> NumPy
# Import numpy
import numpy as np
# Create a numpy array from height_in: np_height_in
np_height_in = np.array(height_in)
# Print out np_height_in
print(np_height_in)
# Convert np_height_in to m: np_height_m
np_height_m= np_height_in*0.0254
# Print np_height_m
print(np_height_m)# Import numpy
import numpy as np
# Store weight and height lists as numpy arrays
np_weight_lb = np.array(weight_lb)
np_height_in = np.array(height_in)
# Print out the weight at index 50
print(np_weight_lb[50])
# Print out sub-array of np_height_in: index 100 up to and including index 110
print(np_height_in[100:111])# Import numpy
import numpy as np
# Create baseball, a list of lists
baseball = [[180, 78.4],
[215, 102.7],
[210, 98.5],
[188, 75.2]]
# Create a 2D numpy array from baseball: np_baseball
np_baseball= np.array(baseball)
# Print out the type of np_baseball
print(type(np_baseball))
# Print out the shape of np_baseball
print(np_baseball.shape)# Import numpy package
import numpy as np
# Create a 2D numpy array from baseball: np_baseball
np_baseball=np.array(baseball)
# Print out the shape of np_baseball
print(np_baseball.shape)