- Home
- DS & Algo. ▾
- Data Structure
- Algorithms
- Coding Problems
- Languages ▾
- C
- C++
- C++ STL
- Java
- Python
- Scala
- Ruby
- C#.Net
- Golang
- Android
- Kotlin
- SQL
- Web. ▾
- JavaScript
- CSS
- jQuery
- PHP
- Node.Js
- AdonisJs
- VueJS
- Ajax
- HTML
- Django
- Programs ▾
- C
- C++
- Data Structure
- Java
- C#.Net
- VB.Net
- Python
- PHP
- Golang
- Scala
- Swift
- Rust
- Ruby
- Kotlin
- C Interview Programs
- Aptitude ▾
- C Aptitude
- C++ Aptitude
- Java Aptitude
- C# Aptitude
- PHP Aptitude
- Linux Aptitude
- DBMS Aptitude
- Networking Aptitude
- AI Aptitude
- More...
- Interview ▾
- Golang
- MIS Executive
- DBMS
- C
- Embedded C
- Java
- SEO
- HR
- Find Output ▾
- C
- C++
- C#.Net
- Java
- Go
- PHP
- More...
- MCQs ▾
- Web Technologie MCQs
- CS Subjects MCQs
- Databases MCQs
- Programming MCQs
- Testing Software MCQs
- Digital Mktg Subjects MCQs
- Cloud Computing S/W MCQs
- Engineering Subjects MCQs
- Commerce MCQs
- More MCQs...
- CS Subjects ▾
- Machine Learning/AI
- Operating System
- Computer Network
- Software Engineering
- Discrete Mathematics
- Digital Electronics
- Data Mining
- MIS
- DBMS
- Embedded Systems
- Cryptography
- CS Fundamental
- More Tutorials...
- More ▾
- Tech Articles
- Puzzles
- Full Forms
- Code Examples
- Blogs
- Guest Post
- Programmer's Calculator
- XML Sitemap Generator
- About
- Contact
Home »Python »Python Programs
Standard deviation in Python: Here, we are going to learn how to find the standard deviation using python program?By Anuj Singh Last updated : January 04, 2024
Problem statement
Given a dataset (list), you have to write a Python program to find the standard deviation based on the given dataset.
Standard deviation in Python
While dealing with a large data, how many samples do we need to look at before we can have justified confidence in our answer? This depends on the variance of the dataset.
Variance tells us about the divergence and the inconsistency of the sample. The standard deviation of a collection of values is the square root of the variance. While it contains the same information as the variance. But Standard deviation is quite more referred. Why? Look at the below statement:
- The mean income of the population is 846000 with a standard deviation of 4000.
- The mean income of the population is 846000 with a variance of 16000000.
Now see which statement is more favorable and therefore we use standard deviation.
So in this article, we are going to build a function for finding the standard deviation.
So the following function can be used while working on a program with big data which is very useful and help you a lot.
So here is the function code:
Python program to find standard deviation
# Code to find standard deviation# Defining the function to find the# standard deviationdef stdv(X): mean = sum(X) / len(X) tot = 0.0 for x in X: tot = tot + (x - mean) ** 2 return (tot / len(X)) ** 0.5# Main code# Simple datasetsample = [1, 2, 3, 4, 5]print("Standard Deviation of the sample is: ", stdv(sample))sample = [1, 2, 3, -4, -5]print("Standard Deviation of the sample is: ", stdv(sample))sample = [10, -20, 30, -40, 50]print("Standard Deviation of the sample is: ", stdv(sample))
Output
The output of the above example is:
Standard Deviation of the sample is: 1.4142135623730951 Standard Deviation of the sample is: 3.2619012860600183 Standard Deviation of the sample is: 32.61901286060018
To understand the above program, you should have the basic knowledge of the following Python topics:
- Python Variables
- Python Data Types
- Python print() Method
- Python Functions
- Python Loops
- Python len() Method
Python Basic Programs »
Python program for Tower of Hanoi
Python program to find the variance
Related Programs
- Python | Find the factorial of a number using recursion
- Python | Declare any variable without assigning any value.
- Python | BMI (Body Mass Index) calculator.
- Python | Program to print Odd and Even numbers from the list of integers.
- Python | Program to print Palindrome numbers from the given list.
- Python | Compute the net amount of a bank account based on the transactions.
- Python | Count total number of bits in a number.
- Python | Generate random number using numpy library.
- Generate random integers between 0 and 9 in Python
- Python | Program to calculate n-th term of a Fibonacci Series
- Python program for sum of square of first N natural numbers
- Python program for sum of cube of first N natural numbers
- Python program to check prime number
- Python program to find the largest prime factor of a number
- Python program to find prime numbers using sieve of Eratosthenes
- Python program to calculate prime numbers (using different algorithms) upto n
- Python program to print all prime numbers in an interval
- Python program to print all positive or negative numbers in a range
- Python program for not None test
- Python program for pass statement
- Python program for Zip, Zap and Zoom game
- Python program to convert temperature from Celsius to Fahrenheit and vice-versa
- Python program to find the number of required bits to represent a number in O(1) complexity
- Python program to count number of trailing zeros in Factorial of number N
- Python program for swapping the value of two integers
- Python program for swapping the value of two integers without third variable
- Python program to find winner of the day
- Python program for Tower of Hanoi
- Python program to find the variance
- Python program Tower of Hanoi (modified)
- Python program to convert Centimeter to Inches
- Python program to convert meters into yards
- Python program to convert yards into meters
- Python program to capitalize the character without using a function
- Python program to lowercase the character without using a function
- Python program to find perfect number
- Python program to print perfect numbers from the given list of integers
- Python program to find greatest integer using floor() method
- Python program to find the maximum EVEN number
- Python program to find the maximum ODD number
- Python program to find the solution of a special sum series
- Python | Convert the binary number to decimal without using library function
- Python | Convert the decimal number to binary without using library function
- Create a stopwatch using Python
- Python program to find the maximum multiple from given N numbers
- Python program to find the least multiple from given N numbers
- Find the root of the quadratic equation in Python
- Python program to check the given Date is valid or not
- Python program to print the calendar of any year
Comments and Discussions!
Load comments ↻