TutorialsPythonDescriptive Statistics in Python

Descriptive Statistics in Python

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

Descriptive statistics summarise a dataset's main characteristics. They are the foundation of any analysis — before you build charts or draw conclusions, you need to understand the central tendency (what is typical) and dispersion (how spread out) of your data. Python with NumPy and Pandas provides all standard descriptive statistics with clean, readable code.

Example

Core descriptive statistics
import pandas as pd
import numpy as np

sales = pd.Series([45000, 18000, 62000, 9000, 51000, 72000, 33000])

# Central tendency
sales.mean()    # arithmetic mean: 41428.6
sales.median()  # middle value: 45000
sales.mode()[0] # most common value

# Dispersion
sales.std()     # standard deviation: 21568.5
sales.var()     # variance
sales.min()     # 9000
sales.max()     # 72000
sales.max() - sales.min()  # range: 63000

# Percentiles
sales.quantile(0.25)   # Q1: 25th percentile
sales.quantile(0.75)   # Q3: 75th percentile
sales.quantile([0.1, 0.5, 0.9])  # multiple at once

# All at once
sales.describe()
# count     7.000000
# mean  41428.571429
# std   21568.484050
# min    9000.000000
# 25%   25500.000000
# 50%   45000.000000
# 75%   56500.000000
# max   72000.000000

# Skewness and kurtosis
sales.skew()    # positive = right-skewed (high-value outliers)
sales.kurt()    # how "peaked" vs "flat" the distribution is

Key Points

  • Mean is sensitive to outliers — use median for skewed data (like income or sales)
  • Standard deviation tells you the typical distance from the mean
  • Coefficient of variation (std/mean × 100) compares spread across different-scale metrics
  • Positive skew: mean > median (few very high values pull the mean up)
  • describe() with percentiles=[0.1, 0.9] shows 10th and 90th percentiles instead of default

Practice Question

A salary dataset has a few extremely high executive salaries. Which measure of central tendency better represents the "typical" salary?

Related Topics

Outlier Detection in PythonIdentify and handle outliers using IQR, z-score and visualisation methodsCorrelation AnalysisFind relationships between variables using Pearson correlation and Seaborn heatmapsgroupby and Pivot TablesAggregate data by category with groupby — the Pandas equivalent of Excel pivot tables