How to Perform a One-Way ANOVA in Python Last Updated : 23 Jul, 2025 Comments Improve Suggest changes 9 Likes Like Report One-Way ANOVA is a statistical test used to check if there are significant differences between the means of three or more groups i.e analysis of variance. It helps us to find whether the variations in data are due to different treatments or random chance.Hypotheses in One-Way ANOVAOne-way ANOVA has null and alternative hypotheses:H0 (null hypothesis): μ1 = μ2 = μ3 = … = μk i.e it implies that the means of all the population are equal.H1 (null hypothesis): It states that there will be at least one population mean that differs from the rest.Example:Imagine we want to compare the performance of four different engine oils used in cars. The cars drive 100 kilometers with each type of oil and their performance is recorded. We want to check if the performance differs depending on the oil used. Now we will use One-Way ANOVA test in Python with following steps:Step 1: Install Required LibrariesWe need to install the SciPy library in our system. We can install it using below command in terminal:pip3 install scipyStep 2: Create Data GroupsWe create arrays representing the performance of cars with each engine oil. Python performance1 = [89, 89, 88, 78, 79] performance2 = [93, 92, 94, 89, 88] performance3 = [89, 88, 89, 93, 90] performance4 = [81, 78, 81, 92, 82] Step 3: Perform One-Way ANOVANow we use the f_oneway() function from SciPy to conduct the One-Way ANOVA test. Python from scipy.stats import f_oneway f_statistic, p_value = f_oneway(performance1, performance2, performance3, performance4) print(f"F-statistic: {f_statistic}") print(f"P-value: {p_value}") Output:ResultStep 4: Analyze the ResultThe output will provide two important values:F-statistic: It measures the variance between the groups relative to the variance within the groups.P-value: It helps determine if the results are statistically significant.Since p-value is less than 0.05 hence we would reject the null hypothesis. This implies that we have sufficient proof to say that there exists a difference in performance among four different engine oils. Comment B bhuwanesh Follow 9 Improve B bhuwanesh Follow 9 Improve Article Tags : Python Geeks Premier League Geeks-Premier-League-2022 Python-scipy Explore Python FundamentalsPython Introduction 2 min read Input and Output in Python 4 min read Python Variables 5 min read Python Operators 4 min read Python Keywords 2 min read Python Data Types 8 min read Conditional Statements in Python 3 min read Loops in Python - For, While and Nested Loops 5 min read Python Functions 5 min read Recursion in Python 4 min read Python Lambda Functions 5 min read Python Data StructuresPython String 5 min read Python Lists 4 min read Python Tuples 4 min read Python Dictionary 3 min read Python Sets 6 min read Python Arrays 7 min read List Comprehension in Python 4 min read Advanced PythonPython OOP Concepts 11 min read Python Exception Handling 5 min read File Handling in Python 4 min read Python Database Tutorial 4 min read Python MongoDB Tutorial 2 min read Python MySQL 9 min read Python Packages 10 min read Python Modules 7 min read Python DSA Libraries 15 min read List of Python GUI Library and Packages 3 min read Data Science with PythonNumPy Tutorial - Python Library 3 min read Pandas Tutorial 4 min read Matplotlib Tutorial 5 min read Python Seaborn Tutorial 15+ min read StatsModel Library - Tutorial 3 min read Learning Model Building in Scikit-learn 8 min read TensorFlow Tutorial 2 min read PyTorch Tutorial 6 min read Web Development with PythonFlask Tutorial 8 min read Django Tutorial | Learn Django Framework 7 min read Django ORM - Inserting, Updating & Deleting Data 4 min read Templating With Jinja2 in Flask 6 min read Django Templates 7 min read Python | Build a REST API using Flask 3 min read How to Create a basic API using Django Rest Framework ? 4 min read Python PracticePython Quiz 1 min read Python Coding Practice 1 min read Python Interview Questions and Answers 15+ min read Like