Skew() Function In Pandas

Overview:

  • Skewness is a measure of asymmetry of a distribution. Another measure that describes the shape of a distribution is kurtosis.
  • In a normal distribution, the mean divides the curve symmetrically into two equal parts at the median and the value of skewness is zero.
  • When a distribution is asymmetrical the tail of the distribution is skewed to one side-to the right or to the left.
  • When the value of the skewness is negative, the tail of the distribution is longer towards the left hand side of the curve.
  • When the value of the skewness is positive, the tail of the distribution is longer towards the right hand side of the curve.

skewness()  function in pandas:

  • The DataFrame class of pandas has a method skew() that computes the skewness of the data present in a given axis of the DataFrame object.
  • Skewness is computed for each row or each column of the data present in the DataFrame object.

Example:

import pandas as pd

 

dataVal = [(10,20,30,40,50,60,70),

           (10,10,40,40,50,60,70),

           (10,20,30,50,50,60,80)]

dataFrame = pd.DataFrame(data=dataVal);

skewValue = dataFrame.skew(axis=1)

 

print("DataFrame:")

print(dataFrame)

 

print("Skew:")

print(skewValue)

 

Output:

DataFrame:

    0   1   2   3   4   5   6

0  10  20  30  40  50  60  70

1  10  10  40  40  50  60  70

2  10  20  30  50  50  60  80

Skew:

0    0.000000

1   -0.340998

2    0.121467

dtype: float64

  • A skewness value of 0 in the output denotes a symmetrical distribution of values in row 1.
  • A negative skewness value in the output indicates an asymmetry in the distribution corresponding to row 2 and the tail is larger towards the left hand side of the distribution.
  • A positive skewness value in the output indicates an asymmetry in the distribution corresponding to row 3 and the tail is larger towards the right hand side of the distribution.

Copyright 2022 © pythontic.com