Skip to content
Introduction to Python
  • AI Chat
  • Code
  • Report
  • Introduction to Python

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

    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')?
    # Print out the weight of the first ten baseball players.
    print(baseball_weights[:10])
    # What is the median weight of all baseball players in the data?
    print(np.median(baseball_weights * 0.453592))
    Hidden code
    # Who is taller on average? Baseball players or soccer players? Keep in mind that baseball heights are stored in inches!
    avg_height_baseball = np.round(np.mean(baseball_heights * 2.54), 2)
    avg_height_soccer = np.round(np.mean(soccer_heights), 2)
    
    print(f'Average height of a baseball player: {avg_height_baseball}')
    print(f'Average height of a soccer player: {avg_height_soccer}')
    # The values in soccer_shooting are decimals. Convert them to whole numbers (e.g., 0.98 becomes 98).
    soccer_shooting = soccer_shooting * 10
    soccer_shooting
    # Do taller players get higher ratings? Calculate the correlation between soccer_ratings and soccer_heights to find out!
    x = soccer_ratings
    y = soccer_heights
    
    print(np.corrcoef(soccer_ratings, soccer_heights))
    
    # Две переменные могут быть связаны таким образом, что при возрастании значений одной из них значения другой убывают. 
    # Это и показывает отрицательный коэффициент корреляции.
    # Про такие переменные говорят, что они отрицательно коррелированы.
    # What is the average rating for attacking players ('A')?
    average_rating_A_players = np.mean(soccer_ratings[soccer_positions == 'A'])
    print(average_rating_A_players)