A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/machine-learning/how-to-conduct-a-one-sample-t-test-in-python/ below:

How to Conduct a One Sample T-Test in Python

How to Conduct a One Sample T-Test in Python

Last Updated : 23 Jul, 2025

In this article, we are going to see how to conduct a one sample T-Test in Python.

One Sample T-Test in Python

The one-sample t-test is a statistical hypothesis test that can be used to see if the mean of an unknown population differs from a given or known value. In this article let's learn how to perform a one-sample t-test.

null hypothesis: the mean of the areas is 5000.

alternative hypothesis: the mean of the areas is not  5000.

CSV Used:

Create a Dataframe for demonestration  Python3
# import packages
import scipy.stats as stats
import pandas as pd

# loading the csv file
data = pd.read_csv('areas.csv')
data.head()

Output:

Conduct a One Sample T-Test in Python

To perform one-sample t-test we will use the scipy.stats.ttest_1samp() function to perform one- sample t-test. The T-test is calculated for the mean of one set of values. The null hypothesis is that the expected mean of a sample of independent observations is equal to the specified population mean, popmean.

Syntax: scipy.stats.ttest_1samp(a, popmean, axis=0).

parameters:

returns : t statistic and two tailed p value.

Python3
# import packages
import scipy.stats as stats
import pandas as pd

# loading the csv file
data = pd.read_csv('areas.csv')

# perform one sample t-test
t_statistic, p_value = stats.ttest_1samp(a=data, popmean=5000)
print(t_statistic , p_value)

Output:

[-0.79248301] [0.44346471]

Here

t_statistic is  -0.79248301

p-value is 0.44346471

As the p_value for the given problem is more than 0.05 which is the alpha value, we accept the null hypothesis and the alternative hypothesis is rejected.



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4