ZetCode

Pandas Descriptive Statistics

last modified November 17, 2026 Python 3.15

Descriptive statistics summarise a data set with a handful of numbers: a typical value, a measure of spread, the smallest and largest observations, and so on. Pandas makes this very convenient with the describe method, which produces many of these summaries at once, as well as with individual methods for each statistic.

All the examples below were run with pandas 3.1.1. We will use small Series and DataFrames so that every number in the output can be checked by hand.

Describing numeric columns

Calling describe on a DataFrame examines every numeric column. The result is a table whose rows are the statistics and whose columns are the original numeric columns. A numeric column is one that holds numbers, so it can be added, averaged and ordered. Note that std is the standard deviation, a measure of how far the values typically sit from the mean, and the 25%, 50% and 75% rows are quartiles.

describe_basic.py
import pandas as pd

df = pd.DataFrame({
    'age': [23, 27, 31, 35, 39],
    'salary': [40000, 50000, 60000, 70000, 110000]
})
print(df.describe())

For both columns count is 5 because there are five observations and no missing values. The average age is 31 and the average salary is 66000. The 50% row is the median, the middle value once the data is sorted; here it equals the mean for age because those values are evenly spaced.

$ python describe_basic.py
             age         salary
count   5.000000       5.000000
mean   31.000000   66000.000000
std     6.324555   27018.512172
min    23.000000   40000.000000
25%    27.000000   50000.000000
50%    31.000000   60000.000000
75%    35.000000   70000.000000
max    39.000000  110000.000000

Individual statistics

When we need just one summary, each statistic has its own method. The mean is the arithmetic average, the median is the middle value, min and max are the extremes, and sum is the total. These methods work on a single Series and return one number.

describe_numeric_stats.py
import pandas as pd

s = pd.Series([10, 20, 30, 40, 50])
print('mean  ', s.mean())
print('median', s.median())
print('std   ', s.std())
print('min   ', s.min())
print('max   ', s.max())
print('sum   ', s.sum())

The five values add up to 150, so the mean is 30, which is also the median. Pandas computes the sample standard deviation by default, dividing by the number of values minus one; that is why std is about 15.81 rather than 14.14. The methods that return an integer do so here because the input contains integers.

$ python describe_numeric_stats.py
mean   30.0
median 30.0
std    15.811388300841896
min    10
max    50
sum    150

Non-numeric columns

By default describe skips columns that do not hold numbers. Text columns can still be summarised by passing include='object'. Their summary has different rows: count of the non-missing values, unique for the number of distinct values, top for the most common one and freq for how often it appears. To keep this example free of pandas version differences, the text column is created with an explicit object dtype.

describe_object.py
import pandas as pd

df = pd.DataFrame({
    'city': pd.Series(
        ['Bratislava', 'Prague', 'Bratislava', 'Vienna', 'Prague'],
        dtype=object
    ),
    'temperature': [12, 15, 14, 16, 13]
})
print(df.describe(include='object'))

Only the city column is shown, because the numeric temperature column does not match the requested type. There are three distinct cities; Bratislava is the most frequent and it occurs twice.

$ python describe_object.py
              city
count            5
unique           3
top     Bratislava
freq             2

Counting values with value_counts

The value_counts method counts how many times each distinct value occurs and returns a Series sorted from the most common to the least common. It is the go-to tool for a quick frequency table of a categorical column.

describe_value_counts.py
import pandas as pd

s = pd.Series(['apple', 'banana', 'apple', 'orange', 'banana', 'apple'])
print(s.value_counts())

There are three apple entries, two banana entries and one orange. The index of the result holds the distinct values and the values hold their counts; the total, 3 + 2 + 1, is six, the length of the original Series.

$ python describe_value_counts.py
apple     3
banana    2
orange    1
Name: count, dtype: int64

Correlation and covariance

Two methods describe how columns vary together. Covariance measures the direction of a joint relationship: a positive value means the columns tend to rise together. Correlation is covariance scaled to a value between -1 and 1, which makes the strength of the relationship easier to compare. Both return a square table with one row and column per numeric column; the diagonal is 1 for correlation because a column is perfectly correlated with itself.

describe_corr_cov.py
import pandas as pd

df = pd.DataFrame({
    'hours': [1, 2, 3, 4, 5],
    'score': [2, 4, 5, 7, 11]
})
print('corr:')
print(df.corr())
print()
print('cov:')
print(df.cov())

The correlation between hours and score is about 0.97, a strong positive relationship: more hours go with higher scores. The covariance is positive too, at 5.25, but its size depends on the units of the two columns, which is why the correlation is usually easier to interpret.

$ python describe_corr_cov.py
corr:
          hours     score
hours  1.000000  0.970725
score  0.970725  1.000000

cov:
       hours  score
hours   2.50   5.25
score   5.25  11.70

Quantiles

A quantile is a value below which a given fraction of the data falls. Passing a fraction from 0 to 1 to quantile returns that point; the fraction 0.5 is the median. Passing a list of fractions returns one value for each, which is a convenient way to get quartiles at once.

describe_quantile.py
import pandas as pd

s = pd.Series([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
print('median (0.5):', s.quantile(0.5))
print('quartiles:')
print(s.quantile([0.25, 0.5, 0.75]))

There are ten values from 1 to 10, so the middle falls halfway between 5 and 6, giving 5.5. The first quartile is 3.25 and the third quartile is 7.75; these are the same numbers that appear in the 25% and 75% rows of describe.

$ python describe_quantile.py
median (0.5): 5.5
quartiles:
0.25    3.25
0.50    5.50
0.75    7.75
dtype: float64

Selecting columns with include and exclude

The include and exclude arguments choose which column types take part. The special value 'all' includes every column, so we see numeric and non-numeric summaries side by side. Cells that do not apply to a column are shown as NaN, the marker Pandas uses for a missing value. Using exclude drops one type instead.

describe_include_exclude.py
import pandas as pd

df = pd.DataFrame({
    'name': ['A', 'B', 'C'],
    'score': [10, 20, 30],
    'passed': [True, False, True]
})
print(df.describe(include='all'))
print()
print(df.describe(exclude='bool'))

With include='all' all three columns appear. The name column gets the text-style rows and score gets the numeric ones; the boolean passed column gets count, unique, top and freq. With exclude='bool' the passed column disappears and only name and score remain.

$ python describe_include_exclude.py
       name  score passed
count     3    3.0      3
unique    3    NaN      2
top       A    NaN   True
freq      1    NaN      2
mean    NaN   20.0    NaN
std     NaN   10.0    NaN
min     NaN   10.0    NaN
25%     NaN   15.0    NaN
50%     NaN   20.0    NaN
75%     NaN   25.0    NaN
max     NaN   30.0    NaN

       name  score
count     3    3.0
unique    3    NaN
top       A    NaN
freq      1    NaN
mean    NaN   20.0
std     NaN   10.0
min     NaN   10.0
25%     NaN   15.0
50%     NaN   20.0
75%     NaN   25.0
max     NaN   30.0

describe versus agg

Both describe and agg produce summaries, but they serve different purposes. describe is a fixed, ready-made report: it always returns the same set of statistics for the columns it selects, which makes it ideal for a first look at data. agg is a flexible tool where we choose exactly which functions to run, give the results our own names, and can apply different functions to different columns.

In short, reach for describe when exploring and for agg when building a specific result. The Pandas aggregation tutorial covers agg in detail, including named aggregations and its use with groupby.

Source

Pandas DataFrame.describe Documentation, Pandas Series.value_counts Documentation, Pandas DataFrame.corr Documentation, and Pandas Essential Basics Documentation

In this article we have summarised data with describe on numeric and non-numeric columns, computed individual statistics such as mean and std, counted categories with value_counts, measured relationships with corr and cov, found quantile values, selected columns with include and exclude, and compared describe with agg. For building our own summaries see Pandas aggregation, and for grouping rows before summarising see the grouping data tutorial.

Author

I am Jan Bodnar, a programmer and technical writer. I have been writing programming tutorials at ZetCode since 2007 and have published eight e-books. See about the author.

List all Pandas tutorials.