Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Write a Python program to quantify the shape of a distribution in a dataframe
Assume, you have a dataframe and the result for quantify shape of a distribution is,
kurtosis is: Column1 -1.526243 Column2 1.948382 dtype: float64 asymmetry distribution - skewness is: Column1 -0.280389 Column2 1.309355 dtype: float64
Solution
To solve this, we will follow the steps given below −
Define a dataframe
Apply df.kurt(axis=0) to calculate the shape of distribution,
df.kurt(axis=0)
Apply df.skew(axis=0) to calculate unbiased skew over axis-0 to find asymmetry distribution,
df.skew(axis=0)
Example
Let’s see the following code to get a better understanding −
import pandas as pd
data = {"Column1":[12,34,56,78,90],
"Column2":[23,30,45,50,90]}
df = pd.DataFrame(data)
print("DataFrame is:\n",df)
kurtosis = df.kurt(axis=0)
print("kurtosis is:\n",kurtosis)
skewness = df.skew(axis=0)
print("asymmetry distribution - skewness is:\n",skewness)
Output
DataFrame is: Column1 Column2 0 12 23 1 34 30 2 56 45 3 78 50 4 90 90 kurtosis is: Column1 -1.526243 Column2 1.948382 dtype: float64 asymmetry distribution - skewness is: Column1 -0.280389 Column2 1.309355 dtype: float64
Advertisements
