TutorialsPythonDescriptive Statistics in Python

Descriptive Statistics in Python

Calculate mean, median, mode, variance, standard deviation and percentiles with pandas

Descriptive statistics summarise a dataset — central tendency (what is typical?), spread (how varied?), and shape (symmetric or skewed?). Every EDA and analyst report starts with these. pandas and NumPy make these trivial to calculate on any column. Understanding when to use mean vs median — and why standard deviation matters — is what separates analysts from people who just run the formulas.

Example

Central tendency and spread
import pandas as pd
import numpy as np

salaries = pd.Series([35000, 42000, 55000, 58000, 62000, 71000, 85000, 250000])

# Central tendency
salaries.mean()    # 82250.0 — pulled up by the outlier
salaries.median()  # 60000.0 — robust to outlier
salaries.mode()    # no mode (all unique) → returns the full series

# Spread
salaries.std()     # standard deviation
salaries.var()     # variance
salaries.min()     # 35000
salaries.max()     # 250000
salaries.range = salaries.max() - salaries.min()  # 215000

# Percentiles
salaries.quantile(0.25)   # Q1 = 46750
salaries.quantile(0.50)   # Q2 = median = 60000
salaries.quantile(0.75)   # Q3 = 74000
salaries.quantile([0.1, 0.25, 0.5, 0.75, 0.9])  # multiple at once

# Full summary
salaries.describe()
# count      8.0
# mean   82250.0
# std    69977.6
# min    35000.0
# 25%    46750.0
# 50%    60000.0
# 75%    74000.0
# max   250000.0
💡 Mean is pulled by outliers; median is robust. For salary/income data, always report both.

Key Points

  • Use median for skewed data (salary, house price, revenue) — mean is misleading with outliers
  • Standard deviation tells you spread — 68% of normal data falls within 1 std dev of mean
  • df.describe() gives count, mean, std, min, 25%, 50%, 75%, max in one call
  • Skewness: mean > median = right-skewed (tail on right); mean < median = left-skewed
  • For categorical columns: value_counts() is the equivalent of descriptive stats

Practice Question

A dataset of employee salaries has mean ₹85,000 but median ₹55,000. What does this tell you?