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.

 

Compatibility

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


Output:
118763.14285714284

 

Python variance() with both Arguments

Calculate mean first and pass it as an argument.

Output:
2849941.3666666667

 

Python variance() Function Example of Fraction

Use Fraction array as an argument.

Output:
1328.080960666666666666666667

LearnAndLearn.com © 2018 - All rights reserved