Compute unbiased skewness for values across Series or DataFrames using the Pandas skew() method. Measure distribution asymmetry, identify positive (right-tailed) or negative (left-tailed) bias, and configure calculation axes.
skew() method calculates the degree of asymmetry of a data distribution around its mean. A value of 0.0 indicates a symmetric distribution, positive values indicate a right-skewed distribution (tail extends right), and negative values indicate a left-skewed distribution.import pandas as pd
s = pd.Series([10, 12, 15, 18, 100], name="VAL")
print(s)
assert s.shape == (5,)
Expected output
0 10
1 12
2 15
3 18
4 100
Name: VAL, dtype: int64
skew() on the Series to measure its directional asymmetry.s_skew = s.skew()
print(f"Skewness: {s_skew:.4f}")
assert s_skew > 2.0
Expected output
Skewness: 2.1554
df = pd.DataFrame({
"RIGHT_SKEW": [1, 2, 2, 3, 10],
"LEFT_SKEW": [1, 8, 9, 9, 10]
})
df_skew = df.skew()
print(df_skew)
assert df_skew["RIGHT_SKEW"] > 0 and df_skew["LEFT_SKEW"] < 0
Expected output
RIGHT_SKEW 1.879442
LEFT_SKEW -1.879442
dtype: float64
scores = pd.Series([100, 95, 90, 85, 20], name="SCORES"), compute its skewness using skew() and verify that it returns a negative value (left-skewed due to low score outlier).skew().scores = pd.Series([100, 95, 90, 85, 20], name="SCORES")
answer = scores.skew()
print(answer)
assert answer < 0
Expected output
-2.0076231908861947
Practice skew() examples interactively directly in your browser:
Reference: Pandas skew() documentation.
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.