Descriptive Statistics in Data Science: A Complete Guide with Python
// outline
Before you build a model, run a hypothesis test, or write a dashboard, you need to know what your data actually looks like. What is a typical value? How spread out are the numbers? Are there outliers? Is the distribution symmetric? Descriptive statistics answers all of these questions — and gets you ready for everything that comes next.
What Is Descriptive Statistics?
Descriptive statistics is the branch of statistics concerned with summarizing and describing the main features of a dataset. Unlike inferential statistics, which uses sample data to draw conclusions about a larger population, descriptive statistics stays within the boundaries of the data you already have — describing what is there, clearly and accurately.
The output is a set of summary numbers and visualizations that replace an overwhelming list of raw values with a coherent, understandable picture. Instead of handing a stakeholder 50,000 rows of customer ages, you give them a mean, a standard deviation, a histogram, and a box plot — and the story is immediately visible.
Descriptive statistics covers four main categories of measurement, each answering a different question about your data:
Descriptive vs Inferential Statistics
These two branches are often confused, especially by beginners who encounter both in the same course or project. The distinction is the scope of the conclusion you are drawing.
| Feature | Descriptive | Inferential |
|---|---|---|
| Purpose | Summarize the data you have | Draw conclusions about a population |
| Scope | Only what is in the dataset | Beyond the dataset |
| Outputs | Mean, median, charts, tables | p-values, confidence intervals, test statistics |
| Uncertainty | No — you are describing known data | Yes — you are estimating unknown values |
| First step? | Always | After descriptive analysis is done |
In every real data science project, descriptive statistics comes first. You cannot run a meaningful hypothesis test without first understanding the shape, spread, and potential outliers in your data — those properties determine which statistical test is even valid to use.
Types of Variables: What You Can Measure and How
Before applying any descriptive statistic, you need to know what kind of variable you are working with. The type of variable determines which measures and visualizations are appropriate.
Categorical (qualitative) variables represent groups or labels. You can count them, but mathematical operations like averaging are meaningless. Examples: product category, country, customer segment, survey response (yes/no). For these, you use frequency counts, proportions, bar charts, and mode.
Numerical (quantitative) variables represent measurable quantities. These split further into two subtypes. Discrete variables take only specific countable values — number of orders, number of employees, number of page views per session. Continuous variables can take any value within a range — revenue, temperature, time spent on page, customer lifetime value.
Measures of Central Tendency
Central tendency answers one question: what is a typical value in this dataset? Three measures answer it in different ways, and choosing the wrong one distorts your picture of the data.
Measures of Variability (Spread)
Two datasets can share the same mean and still look completely different. Variability measures capture the spread — how tightly clustered or widely scattered the data points are around the center.
Shape of a Distribution: Skewness and Kurtosis
The mean and standard deviation describe the center and spread of a distribution, but they cannot tell you its shape. Two distributions can have identical means and standard deviations but look completely different. Skewness and kurtosis quantify that shape.
Skewness
Skewness measures how asymmetric a distribution is. A perfectly symmetric distribution (like a normal bell curve) has a skewness of zero. A positive skew (right-skewed) means a long tail extends to the right — most values cluster on the left, but a few very high values pull the tail outward. Income is the classic example: most people earn moderate amounts, but a small number of very high earners create a long right tail. A negative skew (left-skewed) is the mirror — a long tail extending to the left.
Skewness matters because it changes which measure of central tendency is most representative. In a positively skewed distribution, the mean is pulled toward the tail and above the median — so the median is a better "typical value." In machine learning, high skewness often signals that a log transformation would improve model performance.
Kurtosis
Kurtosis measures the "tailedness" of a distribution — how heavy or light the tails are compared to a normal distribution. Leptokurtic distributions (high kurtosis) have heavier tails and a sharper central peak, meaning extreme values are more common than a normal distribution predicts. Financial returns are often leptokurtic — crashes and booms happen more often than a normal model would suggest. Platykurtic distributions (low kurtosis) have lighter tails and a flatter peak, meaning extreme values are rare.
Measures of Position: Percentiles and Quartiles
Measures of position tell you where a specific value stands relative to the rest of the dataset. They do not describe the whole distribution — they describe individual data points in context.
Percentiles divide a sorted dataset into 100 equal parts. The 90th percentile is the value below which 90% of the data falls. If a student's test score is at the 85th percentile, they scored higher than 85% of other students — regardless of the actual score. Percentiles are used constantly in reporting: page load time at the 95th percentile (p95), income at the 50th percentile (the median), and growth benchmarks.
Quartiles divide a sorted dataset into four equal parts: Q1 (25th percentile), Q2 (50th percentile — the median), and Q3 (75th percentile). These three values, combined with the minimum and maximum, form the five-number summary that underpins the box plot visualization.
| Measure | Definition | Common use |
|---|---|---|
| Q1 (25th percentile) | 25% of data falls below this value | Lower bound of IQR |
| Q2 (50th percentile) | The median — 50% falls below | Central tendency for skewed data |
| Q3 (75th percentile) | 75% of data falls below this value | Upper bound of IQR |
| p95 / p99 | 95% or 99% of data falls below | Performance monitoring, SLA thresholds |
Frequency Distributions
A frequency distribution shows how often each value (or range of values) appears in a dataset. It turns a raw list of numbers into a structured summary of how the data is distributed across its range.
For categorical data, a frequency table simply counts how many times each category appears and what proportion of the total it represents. For continuous numerical data, the values are grouped into bins — equal-width intervals — and the count within each bin is recorded. The result is a histogram when visualized, which reveals the shape of the distribution at a glance: whether it is symmetric, skewed, bimodal, or uniform.
Frequency distributions are also the starting point for identifying data quality issues. A bin with unexpectedly high frequency might indicate data entry errors. A completely flat distribution where you would expect a peak suggests the data source is unreliable. Checking the frequency distribution is one of the first steps in any serious data cleaning process.
Python: Computing Descriptive Statistics
Python makes descriptive statistics fast with Pandas and NumPy. Here are the patterns you will use in every real project.
Core summary statistics with Pandas
import pandas as pd
import numpy as np
# Sample dataset: daily sales figures
data = {
'sales': [450, 380, 520, 490, 610, 320, 580,
410, 550, 470, 390, 720, 430, 510]
}
df = pd.DataFrame(data)
# One-line summary of all numeric columns
print(df.describe())
# Individual statistics
print(f"Mean: {df['sales'].mean():.2f}")
print(f"Median: {df['sales'].median():.2f}")
print(f"Mode: {df['sales'].mode()[0]}")
print(f"Std: {df['sales'].std():.2f}")
print(f"Var: {df['sales'].var():.2f}")
print(f"Range: {df['sales'].max() - df['sales'].min()}")
# IQR calculation
q1 = df['sales'].quantile(0.25)
q3 = df['sales'].quantile(0.75)
iqr = q3 - q1
print(f"IQR: {iqr:.2f}")
Skewness and kurtosis
from scipy import stats
sales = [450, 380, 520, 490, 610, 320, 580,
410, 550, 470, 390, 720, 430, 510]
skewness = stats.skew(sales)
kurt = stats.kurtosis(sales)
print(f"Skewness: {skewness:.3f}")
print(f"Kurtosis: {kurt:.3f}")
# Interpretation
if abs(skewness) < 0.5:
print("Approximately symmetric — mean is reliable")
elif skewness > 0.5:
print("Right-skewed — consider median over mean")
else:
print("Left-skewed — consider median over mean")
Outlier detection using IQR
import pandas as pd
import numpy as np
df = pd.DataFrame({'sales': [450, 380, 520, 1800,
490, 610, 320, 580]})
q1 = df['sales'].quantile(0.25)
q3 = df['sales'].quantile(0.75)
iqr = q3 - q1
lower_bound = q1 - 1.5 * iqr
upper_bound = q3 + 1.5 * iqr
outliers = df[(df['sales'] < lower_bound) |
(df['sales'] > upper_bound)]
print(f"Lower bound: {lower_bound:.0f}")
print(f"Upper bound: {upper_bound:.0f}")
print(f"Outliers:\n{outliers}")
Python: Visualizing Descriptive Statistics
The right visualization depends on variable type and what aspect of the data you need to show. Here are the four most important plots in descriptive analysis.
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
np.random.seed(42)
data = np.random.normal(loc=500, scale=80, size=200)
df = pd.DataFrame({'sales': data})
fig, axes = plt.subplots(2, 2, figsize=(12, 9))
# 1. Histogram with KDE
sns.histplot(df['sales'], kde=True,
ax=axes[0,0], color='steelblue')
axes[0,0].set_title('Histogram with KDE')
axes[0,0].axvline(df['sales'].mean(), color='red',
linestyle='--', label='Mean')
axes[0,0].axvline(df['sales'].median(), color='green',
linestyle='--', label='Median')
axes[0,0].legend()
# 2. Box plot
sns.boxplot(y=df['sales'], ax=axes[0,1], color='steelblue')
axes[0,1].set_title('Box Plot (IQR & Outliers)')
# 3. Violin plot
sns.violinplot(y=df['sales'], ax=axes[1,0], color='steelblue')
axes[1,0].set_title('Violin Plot (Distribution Shape)')
# 4. ECDF (Empirical Cumulative Distribution)
sns.ecdfplot(df['sales'], ax=axes[1,1], color='steelblue')
axes[1,1].set_title('ECDF (Percentile View)')
plt.tight_layout()
plt.savefig('descriptive_stats_plots.png', dpi=150)
plt.show()
Here is when to use each plot type:
Choosing the Right Measure
| Situation | Central tendency | Spread | Visualization |
|---|---|---|---|
| Symmetric data, no outliers | Mean | Standard deviation | Histogram, violin plot |
| Skewed data or outliers | Median | IQR | Box plot |
| Categorical data | Mode | Frequency / proportion | Bar chart |
| Comparing groups | Mean or median per group | Std or IQR per group | Grouped box plot |
| Finding outliers | Median | IQR (1.5× rule) | Box plot |
Role in Exploratory Data Analysis and Machine Learning
Descriptive statistics is the engine of exploratory data analysis (EDA) — the stage where data scientists get to know a dataset before modeling it. A well-done EDA catches data quality problems, shapes feature engineering decisions, and often reveals the most important patterns before any model is trained.
- Data cleaning — the mean, IQR, and range quickly reveal impossible values (negative ages, 200% conversion rates) and potential entry errors
- Feature engineering — knowing a feature is heavily right-skewed tells you a log transformation might normalize it and improve model performance
- Missing value imputation — whether to impute with mean or median depends on whether the distribution is symmetric or skewed
- Scaling decisions — standard deviation determines the normalization factor in standardization (Z-score scaling)
- Algorithm selection — high kurtosis suggests tree-based models may outperform linear ones, which assume near-normality
- Outlier handling — the IQR rule identifies points to investigate before deciding whether to remove, cap, or keep them
Common Mistakes to Avoid
Using mean on skewed data: Income, house prices, and session duration are almost always right-skewed. Reporting the mean implies a typical value that most people never experience. Use median instead.
Ignoring the standard deviation: Two groups can have the same mean and completely different spreads. Always report spread alongside center — one number without the other tells an incomplete story.
Applying numerical statistics to categorical data: The mean of a column coded as 1=Male, 2=Female is statistically meaningless. Know your variable types before calculating anything.
Skipping skewness checks: Feeding a heavily skewed feature into a linear model without transformation inflates errors. Skewness and kurtosis are quick checks that save significant modeling time.
Treating df.describe() as the whole EDA: Pandas describe() gives mean, std, and quartiles — but not skewness, kurtosis, or the frequency distribution. Always visualize as well.
Frequently Asked Questions
What is descriptive statistics in simple terms?
Descriptive statistics is the process of summarizing and describing the main features of a dataset using numbers and visualizations — things like averages, spread, and frequency distributions — without drawing conclusions beyond the data you already have.
What is the difference between mean, median, and mode?
The mean is the mathematical average of all values. The median is the middle value when data is sorted. The mode is the most frequently occurring value. Use mean for symmetric data without significant outliers, median when outliers or skewness are present, and mode for categorical data.
What is standard deviation in simple words?
Standard deviation measures how spread out data points are from the mean. A small standard deviation means data is clustered closely around the average. A large one means it is widely scattered. In a normal distribution, about 68% of data falls within one standard deviation of the mean.
What is the difference between descriptive and inferential statistics?
Descriptive statistics summarizes the data you already have — no uncertainty or prediction involved. Inferential statistics uses that data to make predictions or test claims about a larger population you did not fully measure, with a calculated degree of uncertainty attached to every conclusion.
Is descriptive statistics used in machine learning?
Yes — throughout the data preparation process. It drives EDA, feature engineering decisions, outlier detection, missing value imputation strategy, normalization choices, and algorithm selection. A well-done descriptive analysis before modeling consistently reduces debugging time later.
Summary: Descriptive Statistics Is Where Every Analysis Starts
Descriptive statistics is not a preliminary step you rush through to get to the "real" work. It is the foundation that every subsequent decision — which model to train, which features to engineer, which outliers to remove, which transformation to apply — is built on.
The core ideas are straightforward: central tendency (mean, median, mode) tells you where the data clusters; variability (range, standard deviation, IQR) tells you how spread it is; skewness and kurtosis describe the shape; percentiles and quartiles tell you how individual values compare to the group. Python makes computing and visualizing all of these fast — but knowing which measure to reach for, and why, is the judgment that separates a good analysis from a misleading one.
Khalid Hussain
Founder of Review Publically. Holds a Master's in Computer Science with professional training in Google Advanced Data Analytics, Python, NumPy, and Seaborn. Writes and maintains the site's Data Science and Statistics learning tracks.
// related reads