Pandas How To Uncategorized How to calculate skewness in pandas

How to calculate skewness in pandas

Here’s how to calculate skewness in Pandas.

how to calculate skewness of rows

To calculate the skewness of a Pandas Series, you can use the skew method.

import pandas as pd

my_df = pd.DataFrame(
    {'Column1': ['1', '4', '3', '4'],
     'Column2': ['5', '6', '2', '2'],
     'Column3': ['33', '10', '43', '12']})

my_skew = my_df.skew(axis=1)

print(my_skew)

In the above code, my_df.skew returns the skewness of the dataframe my_df.

Output:

0    1.630059
1    0.935220
2    1.728489
3    1.457863
dtype: float64

Process finished with exit code 0

The result indicates that the dataframe has a positive skew, meaning the values are skewed to the right of the mean.

how to calculate skewness of columns

import pandas as pd

my_df = pd.DataFrame(
    {'Column1': ['1', '4', '3', '4'],
     'Column2': ['5', '6', '2', '2'],
     'Column3': ['33', '10', '43', '12']})

my_skew = my_df.skew(axis=0)

print(my_skew)

Output:

Column1   -1.414214
Column2    0.199735
Column3    0.308539
dtype: float64

Process finished with exit code 0

See also:
Link to the skew function documentation.
How to calculate standard error in Pandas
How to calculate variance in Pandas

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post