Log in from a computer to take this course

You'll need to log in from a computer to start Hypothesis Testing with Python. But you can practice or keep up your coding streak with the Codecademy Go app. Download the app to get started.

apple storegoogle store

In this lesson, we’ll walk through the implementation of a one-sample t-test in Python. One-sample t-tests are used for comparing a sample average to a hypothetical population average. For example, a one-sample t-test might be used to address questions such as:

  • Is the average amount of time that visitors spend on a website different from 5 minutes?
  • Is the average amount of money that customers spend on a purchase more than 10 USD?

As an example, let’s imagine the fictional business BuyPie, which sends ingredients for pies to your household so that you can make them from scratch. Suppose that a product manager wants online BuyPie orders to cost around 1000 Rupees on average. In the past day, 50 people made an online purchase and the average payment per order was less than 1000 Rupees. Are people really spending less than 1000 Rupees on average? Or is this the result of chance and a small sample size?



We have provided a small dataset called prices, representing the purchase prices of customers to BuyPie.com in the past day.

First, print out prices to the console and examine the numbers. How much variation is there in the purchase prices? Can you estimate the mean by looking at these numbers?


Calculate the mean of prices using np.mean(). Store it in a variable called prices_mean and print it out.

What is the average purchase price for these 50 purchases? Is it a lot less than 1000? Or only a little less?

Sign up to start coding

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?