
- 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
How to find the standard deviation of specific columns in a dataframe in Pandas Python?
Standard deviation tells about how the values in the dataset are spread. They also tells how far the values in the dataset are from the arithmetic mean of the columns in the dataset.
Sometimes, it may be required to get the standard deviation of a specific column that is numeric in nature. This is where the std() function can be used. The column whose mean needs to be computed can be indexed to the dataframe, and the mean function can be called on this using the dot operator.
The index of the column can also be passed to find the standard deviation.
Let us see a demonstration of the same −
Example
import pandas as pd my_data = {'Name':pd.Series(['Tom','Jane','Vin','Eve','Will']),'Age':pd.Series([45, 67, 89, 12, 23]),'value':pd.Series([8.79,23.24,31.98,78.56,90.20])} print("The dataframe is :") my_df = pd.DataFrame(my_data) print(my_df) print("The standard deviation of column 'Age' is :") print(my_df['Age'].std()) print("The standard deviation of column 'value' is :") print(my_df['value'].std())
Output
The dataframe is : Name Age value 0 Tom 45 8.79 1 Jane 67 23.24 2 Vin 89 31.98 3 Eve 12 78.56 4 Will 23 90.20 The standard deviation of column 'Age' is : 31.499206339207976 The standard deviation of column 'value' is : 35.747101700697364
Explanation
The required libraries are imported, and given alias names for ease of use.
Dictionary of series consisting of key and value is created, wherein a value is actually a series data structure.
This dictionary is later passed as a parameter to the ‘Dataframe’ function present in the ‘pandas’ library
The dataframe is printed on the console.
We are looking at computing the standard deviation of a specific column that contain numeric values in them.
The ‘std’ function is called on the dataframe by specifying the name of the column, using the dot operator.
The standard deviation of numeric column is printed on the console.
- Related Articles
- Python - Calculate the standard deviation of a column in a Pandas DataFrame
- Write a Python program to find the mean absolute deviation of rows and columns in a dataframe
- How to find the row standard deviation of columns having same name in R matrix?
- Python - Grouping columns in Pandas Dataframe
- Python Pandas - Query the columns of a DataFrame
- Print the standard deviation of Pandas series
- How to get the sum of a specific column of a dataframe in Pandas Python?
- How to find the row standard deviation of columns having same name in R data frame?
- How to find the row standard deviation of columns having same name in data.table object in R?
- Python - Name columns explicitly in a Pandas DataFrame
- Python - Renaming the columns of Pandas DataFrame
- Python Pandas – Count the rows and columns in a DataFrame
- How to find the column standard deviation if some columns are categorical in R data frame?
- Python Pandas - Plot multiple data columns in a DataFrame?
- How to sort multiple columns of a Pandas DataFrame?
