{"id":25475,"date":"2021-11-16T08:39:38","date_gmt":"2021-11-16T03:09:38","guid":{"rendered":"https:\/\/python-programs.com\/?p=25475"},"modified":"2021-11-16T08:39:38","modified_gmt":"2021-11-16T03:09:38","slug":"python-statistics-pvariance-method-with-examples","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-statistics-pvariance-method-with-examples\/","title":{"rendered":"Python statistics.pvariance() Method with Examples"},"content":{"rendered":"
statistics.pvariance() Method in Python:<\/strong><\/p>\n The statistics.pvariance() method computes the variance of a whole 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 Examine the statistics.variance() method to determine the variance from a sample of data.<\/p>\n Syntax:<\/strong><\/p>\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 (can also be a second moment around a point that is not the mean). If omitted (or set to None), the mean is calculated automatically.<\/p>\n Note:<\/strong> It is important to note that if the data is empty, it returns a StatisticsError.<\/p>\n Return Value:<\/strong><\/p>\n Returns a \u00a0float value representing the given data’s population variance.<\/p>\n Examples:<\/strong><\/p>\n Example1:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Example2:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n statistics.pvariance() Method with Examples in Python<\/span><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n statistics.pvariance() Method in Python: The statistics.pvariance() method computes the variance of a whole population. A high variance indicates that the data is dispersed, whereas a low variance indicates that the data is tightly clustered around the mean. Examine the statistics.variance() method to determine the variance from a sample of data. Syntax: statistics.pvariance(data, xbar) Parameters data: …<\/p>\nstatistics.pvariance(data, xbar)<\/pre>\n
Given list = [10, 20, 40, 15, 30]<\/pre>\n
The variance of the given list items [10, 20, 40, 15, 30] = 116<\/pre>\n
Given list = [1, 6, 9, 7]<\/pre>\n
The variance of the given list items [1, 6, 9, 7] = 8.6875<\/pre>\n
\n
Method #1: Using Built-in Functions (Static Input)<\/h3>\n
\n
# Import statistics module using the import keyword.\r\nimport statistics\r\n# Give the list as static input and store it in a variable.\r\ngvn_lst = [10, 20, 40, 15, 30]\r\n# Pass the given list as an argument to the statistics.pvariance() method that\r\n# computes the variance of a whole population.\r\n# Store it in another variable.\r\nrslt = statistics.pvariance(gvn_lst)\r\n# Print the variance of the given list items.\r\nprint(\"The variance of the given list items\", gvn_lst, \"= \", rslt)\r\n<\/pre>\n
The variance of the given list items [10, 20, 40, 15, 30] = 116<\/pre>\n
Method #2: Using Built-in Functions (User Input)<\/h3>\n
\n
# Import statistics module using the import keyword.\r\nimport statistics\r\n# Give the list as user input using list(),map(),input(),and split() functions.\r\n# Store it in a variable.\r\ngvn_lst = list(map(int, input(\r\n 'Enter some random List Elements separated by spaces = ').split()))\r\n\r\n# Pass the given list as an argument to the statistics.pvariance() method that\r\n# computes the variance of a whole population.\r\n# Store it in another variable.\r\nrslt = statistics.pvariance(gvn_lst)\r\n# Print the variance of the given list items.\r\nprint(\"The variance of the given list items\", gvn_lst, \"= \", rslt)\r\n<\/pre>\n
Enter some random List Elements separated by spaces = 1 6 9 7\r\nThe variance of the given list items [1, 6, 9, 7] = 8.6875<\/pre>\n","protected":false},"excerpt":{"rendered":"