{"id":25463,"date":"2021-11-16T08:39:51","date_gmt":"2021-11-16T03:09:51","guid":{"rendered":"https:\/\/python-programs.com\/?p=25463"},"modified":"2021-11-16T08:39:51","modified_gmt":"2021-11-16T03:09:51","slug":"python-statistics-variance-method-with-examples","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-statistics-variance-method-with-examples\/","title":{"rendered":"Python statistics.variance() Method with Examples"},"content":{"rendered":"

statistics.variance() Method in Python:<\/strong><\/p>\n

The statistics.variance() method computes the variance from a data sample (from a population).<\/p>\n

A high variance indicates that the data is dispersed, whereas a low variance indicates that the data is tightly clustered around the mean.<\/p>\n

Look at the statistics.pvariance() method to calculate the variance of an entire population.<\/p>\n

Syntax:<\/strong><\/p>\n

statistics.variance(data, xbar)<\/pre>\n

Parameters<\/strong><\/p>\n

data:<\/strong> This is Required. It is the data values that will be used (it can be any sequence, list, or iterator).<\/p>\n

xbar:<\/strong> This is Optional. The arithmetic mean of the given data. If omitted (or set to None), the mean is calculated automatically.<\/p>\n

Note:<\/strong> It should be noted that if the data has fewer than two values, StatisticsError is returned.<\/p>\n

Return Value:<\/strong><\/p>\n

Returns a\u00a0float value representing the given data’s sample variance.<\/p>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given list = [10, 20, 40, 15, 30]<\/pre>\n

Output:<\/strong><\/p>\n

The variance of the given list items [10, 20, 40, 15, 30] =  145<\/pre>\n

Example2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given list = [3, 2, 5, 6, 1, 1, 3]<\/pre>\n

Output:<\/strong><\/p>\n

The variance of the given list items [3, 2, 5, 6, 1, 1, 3] = 3.6666666666666665<\/pre>\n

statistics.variance() Method with Examples in Python<\/span><\/p>\n