The std()
function in pandas obtains the standard deviation of the values of a specified axis of a given DataFrame.
Mathematically, the standard deviation is defined as measuring the dispersion of each value in a dataset from the mean.
The std()
function takes the syntax shown below:
DataFrame.std(axis=NoDefault.no_default, skipna=True, numeric_only=None, **kwargs)
The std()
function takes the following optional parameter values:
axis
: This represents the name for the row (designated as 0
or 'index'
) or the column (designated as 1
or columns
) axis.skipna
: This takes a Boolean value indicating whether NA or null values are to be excluded.ddof
: This takes an int
that represents the delta degrees of freedom. numeric_only
: This takes a Boolean value indicating whether to include only float, int, or Boolean columns.**kwargs
: This is an additional keyword argument that can be passed to the function.# A code to illustrate the std() function in Pandas# Importing the pandas libraryimport pandas as pd# Creating a DataFramedf = pd.DataFrame([[1,2,3,4,5],[1,7,5,9,0.5],[3,11,13,14,12]],columns=list('ABCDE'))# Printing the DataFrameprint(df)# Obtaining the median value vertically across rowsprint(df.std())# Obtaining the median value horizontally over columnsprint(df.std(axis="columns"))
pandas
library.df
.df
.std()
function, we obtain the standard deviation of values that run downwards across the rows (axis 0
). We print the result to the console.std()
function, we obtain the standard deviation of values that run horizontally across the columns (axis 1
). We print the result to the console.