Learn and Learn

Learn And Learn - great place for tutorials, references and how-to

Python – Find Data Sample Variance – variance() Function with Examples

variance() function is used to find the the sample variance of data in Python. A large variance indicates that the data is spread out; a small variance indicates it is clustered closely around the mean.


Syntax of variance() Function

The syntax of variance() function in Python is:

If data has fewer then two values StatisticsError raises.


Parameters of variance() Function in Python

data – Where data is array of valid Python numbers including Decimal and Fraction values. This parameter is required.
xbar – Where xbar is the mean of data. This parameter is optional. If this parameter is not given(none) then the mean is automatically calculated.



variance() function is only available and compatible with Python 3.x.


Return Value of variance() Function in Python

variance() function returns the sample variance of data, an iterable of at least two real-valued numbers for the given input.


Python variance() Function Simple Example



Python variance() with both Arguments

Calculate mean first and pass it as an argument.



Python variance() Function Example of Fraction

Use Fraction array as an argument.


LearnAndLearn.com © 2018 - All rights reserved