
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Python - Calculate the standard deviation of a column in a Pandas DataFrame
To calculate the standard deviation, use the std() method of the Pandas. At first, import the required Pandas library −
import pandas as pd
Now, create a DataFrame with two columns −
dataFrame1 = pd.DataFrame( { "Car": ['BMW', 'Lexus', 'Audi', 'Tesla', 'Bentley', 'Jaguar'], "Units": [100, 150, 110, 80, 110, 90] } )
Finding the standard deviation of “Units” column value using std() −
print"Standard Deviation of Units column from DataFrame1 = ",dataFrame1['Units'].std()
In the same way, we have calculated the standard deviation from the 2nd DataFrame.
Example
Following is the complete code −
# # Python - Calculate the Standard Deviation of column values of a Pandas DataFrame # import pandas as pd # Create DataFrame1 dataFrame1 = pd.DataFrame( { "Car": ['BMW', 'Lexus', 'Audi', 'Tesla', 'Bentley', 'Jaguar'], "Units": [100, 150, 110, 80, 110, 90] } ) print"DataFrame1 ...\n",dataFrame1 # Finding Standard Deviation of "Units" column values print"Standard Deviation of Units column from DataFrame1 = ",dataFrame1['Units'].std() # Create DataFrame2 dataFrame2 = pd.DataFrame( { "Product": ['TV', 'PenDrive', 'HeadPhone', 'EarPhone', 'HDD', 'SSD'], "Price": [8000, 500, 3000, 1500, 3000, 4000] } ) print"\nDataFrame2 ...\n",dataFrame2 # Finding Standard Deviation of "Price" column values print"Standard Deviation of Price column from DataFrame2 = ",dataFrame2['Price'].std()
Output
This will produce the following output −
DataFrame1 ... Car Units 0 BMW 100 1 Lexus 150 2 Audi 110 3 Tesla 80 4 Bentley 110 5 Jaguar 90 Standard Deviation of Units column from DataFrame1 = 24.2212028328 DataFrame2 ... Price Product 0 8000 TV 1 500 PenDrive 2 3000 HeadPhone 3 1500 EarPhone 4 3000 HDD 5 4000 SSD Standard Deviation of Price column from DataFrame2 = 2601.28173535
- Related Articles
- How to find the standard deviation of specific columns in a dataframe in Pandas Python?
- Python - Calculate the variance of a column in a Pandas DataFrame
- Python - Calculate the mean of column values of a Pandas DataFrame
- Python - Calculate the median of column values of a Pandas DataFrame
- Python - Calculate the count of column values of a Pandas DataFrame
- Python - Calculate the maximum of column values of a Pandas DataFrame
- Python - Calculate the minimum of column values of a Pandas DataFrame
- Python – Group and calculate the sum of column values of a Pandas DataFrame
- Python Program to Calculate Standard Deviation
- Print the standard deviation of Pandas series
- Python – Create a new column in a Pandas dataframe
- Python – Center align column headers of a Pandas DataFrame
- Python Pandas – Display all the column names in a DataFrame
- Python Pandas - Draw a bar plot and show standard deviation of observations with Seaborn
- Python Pandas - Draw a point plot and show standard deviation of observations with Seaborn

Advertisements