Type to search…
Skip to content

Statistics

Describing a whole dataset with a handful of numbers — and knowing which of them is lying to you.

Taught in
Anàlisi de dades amb PythonEstadística, correlació i modelsPYTHONEines computacionals en bioinformàticaAnàlisi de dadesDAW-BIOSistemes de big dataQuadres de comandament i tècniques predictivesIABD

Introducció

A dataset of nine million rows cannot be read.

Statistics is how you describe it with a handful of numbers instead: where it sits, how spread out it is, and which values do not belong.

That is the useful half of the subject and it is what this page teaches.

The other half is the interesting one: every one of those numbers throws information away, and each throws away something different.

A single salary figure can make a country look rich or poor depending on which one you quote — and both figures are correct.

So the page is arranged around that. Each measure, then what it hides.

Entorn de treball

Create the project with uv:

shell
uv init statistics-lab
cd statistics-lab
uv add numpy polars altair vl-convert-python

Arrays does the computing, and Basic draws the results.

Els estadístics són indicadors

Statistical values only mean something applied to a large group; they rarely say anything about an individual.

The average height of men in Spain is 176 cm, and of women 162 cm.

How many people in this class are exactly that tall?

Almost none — and yet most of you are close to it.

A statistic describes the group, not the member. Keep that sentence; the rest of the page keeps testing it.

Tipus de dades

Data comes in kinds, and the kind decides which measures are even legal.

Quantitative data is numeric and measurable: weight, age, height.

Qualitative data you either have or you do not: eye colour, nationality.

You can compute a mean height. You cannot compute a mean eye colour — and Python will not stop you trying, so the check is yours.

Tendència central

Three indicators describe where a dataset sits: the mean, the median and the mode.

Mitjana

The mean can only be used with quantitative data.

Add every value and divide by how many there are.

Ejercicio

Compute the mean of [3, 8, 10, 13, 16, 18] using nothing but built-ins.

Mostra la solució
python
data = [3, 8, 10, 13, 16, 18]

mean = sum(data) / len(data)
print(f"{mean:.2f}")
11.33

Python is a language built for engineers and scientists, so unlike most languages it ships a statistics library in the standard library:

python
import statistics

data = [3, 8, 10, 13, 16, 18]
print(statistics.mean(data))

Keep reading — it's free.

The rest of this page is open to anyone with a free account. Nothing is sold here and nothing is charged for: the account exists so we know who agreed to the terms, and so we can send you the newsletter if you want it.

Create a free account

You will be asked to accept the Terms · Privacy Policy