{"id":25473,"date":"2021-11-16T08:39:34","date_gmt":"2021-11-16T03:09:34","guid":{"rendered":"https:\/\/python-programs.com\/?p=25473"},"modified":"2021-11-16T08:39:34","modified_gmt":"2021-11-16T03:09:34","slug":"python-statistics-stdev-method-with-examples","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-statistics-stdev-method-with-examples\/","title":{"rendered":"Python statistics.stdev() Method with Examples"},"content":{"rendered":"
statistics.stdev() Method in Python:<\/strong><\/p>\n Statistics.stdev() computes the standard deviation from a sample of data.<\/p>\n The standard deviation measures how evenly distributed the numbers are.<\/p>\n A high standard deviation indicates that the data is dispersed, whereas a low standard deviation indicates that the data is tightly clustered around the mean.<\/p>\n Tip: Unlike variance, the standard deviation is expressed in the same units as the data.<\/p>\n The standard deviation is equal to the square root of the sample variance.<\/p>\n Look at the statistics.pstdev() method to calculate the standard deviation of an entire population.<\/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. 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 standard deviation.<\/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.stdev() 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.stdev() Method in Python: Statistics.stdev() computes the standard deviation from a sample of data. The standard deviation measures how evenly distributed the numbers are. A high standard deviation indicates that the data is dispersed, whereas a low standard deviation indicates that the data is tightly clustered around the mean. Tip: Unlike variance, the standard deviation …<\/p>\nstatistics.stdev(data, xbar)<\/pre>\n
Given list = [10, 20, 40, 15, 30]<\/pre>\n
The standard deviation of the given list items [10, 20, 40, 15, 30] = 12.041594578792296<\/pre>\n
Given list = [-2, 5, 8, 9, 0, -1]<\/pre>\n
The standard deviation of the given list items [-2, 5, 8, 9, 0, -1] = 4.792355023020171<\/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.stdev() method that\r\n# computes the standard deviation from a sample of data(here given list).\r\n# Store it in another variable.\r\nrslt = statistics.stdev(gvn_lst)\r\n# Print the standard deviation of the given list items.\r\nprint(\"The standard deviation of the given list items\", gvn_lst, \"= \", rslt)\r\n<\/pre>\n
The standard deviation of the given list items [10, 20, 40, 15, 30] = 12.041594578792296<\/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.stdev() method that\r\n# computes the standard deviation from a sample of data(here given list).\r\n# Store it in another variable.\r\nrslt = statistics.stdev(gvn_lst)\r\n# Print the standard deviation of the given list items.\r\nprint(\"The standard deviation of the given list items\", gvn_lst, \"= \", rslt)\r\n<\/pre>\n
Enter some random List Elements separated by spaces = -2 5 8 9 0 -1\r\nThe standard deviation of the given list items [-2, 5, 8, 9, 0, -1] = 4.792355023020171<\/pre>\n","protected":false},"excerpt":{"rendered":"