In this article, we will discuss different ways to get the Standard Deviation of numbers in a List in Python.
Table Of Contents
Method 1: Using Custom Function
In this solution, we will create a custom function to calculate the Standard Deviation of a List of Numbers in Python. In side this function, fist we will compute the mean of numbers. Then using the mean, we will calculate the variance of numbers. Once we have the variance, then its square root will give us the standard deviation of numbers. Let’s see an example,
# Get Standard Deviation Of Numbers in a List def GetStandardDeviation(listOfNumbers): # get mean of numbers mean = sum(listOfNumbers) / len(listOfNumbers) # Get variance variance = sum([((num  mean) ** 2) for num in listOfNumbers]) / (len(listOfNumbers)1) return variance ** 0.5 numbers = [940, 898, 635, 208, 804, 873, 553, 825, 346, 189] # Get Standard Deviation Of Numbers in a List stdDeviation = GetStandardDeviation(numbers) print(stdDeviation)
Output:
289.5139413261859
It returned the standard deviation of numbers.
We can modify the above function a little to get the population standard deviation. Let’s see an example,
# Get Population Standard Deviation Of Numbers in a List def GetPopulationStandardDeviation(listOfNumbers): # get mean of numbers mean = sum(listOfNumbers) / len(listOfNumbers) # Get variance variance = sum([((num  mean) ** 2) for num in listOfNumbers]) / len(listOfNumbers) return variance ** 0.5 numbers = [940, 898, 635, 208, 804, 873, 553, 825, 346, 189] # Get Standard Pouplation Deviation Of Numbers in a List stdDeviation = GetPopulationStandardDeviation(numbers) print(stdDeviation)
Output:
274.657040688929
It returned the population standard deviation of numbers.
Method 2: Using statistics module
We can also use the stdev() method of statistics module, to get the Standard Deviation Of Numbers in a List. The stdev() function accepts a list of numbers as argument, and returns the square root of the sample variance. Let’s see an example,
import statistics numbers = [940, 898, 635, 208, 804, 873, 553, 825, 346, 189] # Get Standard Deviation Of Numbers in a List stdDeviation = statistics.stdev(numbers) print(stdDeviation)
Output:
289.51394132618594
It returned the standard deviation of numbers.
We can also use the pstdev() method of the statistics module to get the population standard deviation of numbers in a list. Let’s see an example,
import statistics numbers = [940, 898, 635, 208, 804, 873, 553, 825, 346, 189] # Get Population Standard Deviation Of Numbers in a List stdDeviation = statistics.pstdev(numbers) print(stdDeviation)
Output:
274.657040688929
It returned the population standard deviation of numbers.
Method 3: Using NumPy
We can also use the std() function of NumPy module in Python, to compute the standard deviation along the specified axis of the array. We can pass our list, to the numpy.std() function to get the standard deviation of numbers in list. Let’s see an example,
import numpy as np numbers = [940, 898, 635, 208, 804, 873, 553, 825, 346, 189] # Get Standard Deviation Of Numbers in a List stdDeviation = np.std(numbers, ddof=1) print(stdDeviation)
Output:
289.51394132618594
It returned the standard deviation of numbers.
We can use the numpy.std() method with default value of ddof parameter, to get the population standard deviation of numbers in a list. Let’s see an example,
import numpy as np numbers = [940, 898, 635, 208, 804, 873, 553, 825, 346, 189] # Get Population Standard Deviation Of Numbers in a List stdDeviation = np.std(numbers) print(stdDeviation)
Output:
274.657040688929
It returned the population standard deviation of numbers.
Summary
We learned about three different ways to calculate the standard deviation of numbers in a list in Python. Thanks.
Pandas Tutorials Learn Data Analysis with Python

Pandas Tutorial Part #1  Introduction to Data Analysis with Python

Pandas Tutorial Part #2  Basics of Pandas Series

Pandas Tutorial Part #3  Get & Set Series values

Pandas Tutorial Part #4  Attributes & methods of Pandas Series

Pandas Tutorial Part #5  Add or Remove Pandas Series elements

Pandas Tutorial Part #6  Introduction to DataFrame

Pandas Tutorial Part #7  DataFrame.loc[]  Select Rows / Columns by Indexing

Pandas Tutorial Part #8  DataFrame.iloc[]  Select Rows / Columns by Label Names

Pandas Tutorial Part #9  Filter DataFrame Rows

Pandas Tutorial Part #10  Add/Remove DataFrame Rows & Columns

Pandas Tutorial Part #11  DataFrame attributes & methods

Pandas Tutorial Part #12  Handling Missing Data or NaN values

Pandas Tutorial Part #13  Iterate over Rows & Columns of DataFrame

Pandas Tutorial Part #14  Sorting DataFrame by Rows or Columns

Pandas Tutorial Part #15  Merging or Concatenating DataFrames

Pandas Tutorial Part #16  DataFrame GroupBy explained with examples
Are you looking to make a career in Data Science with Python?
Data Science is the future, and the future is here now. Data Scientists are now the most soughtafter professionals today. To become a good Data Scientist or to make a career switch in Data Science one must possess the right skill set. We have curated a list of Best Professional Certificate in Data Science with Python. These courses will teach you the programming tools for Data Science like Pandas, NumPy, Matplotlib, Seaborn and how to use these libraries to implement Machine learning models.
Checkout the Detailed Review of Best Professional Certificate in Data Science with Python.
Remember, Data Science requires a lot of patience, persistence, and practice. So, start learning today.