Averager¶
Averager is a simple Python library to calculate averages of values.
>>> import averager
>>> averager.average(1, 2, 3)
2
>>> averager.weighted_average((1, 2), (2, 3))
1.6
>>> averager.median(5, 1, 2)
2
>>> averager.mode(1, 2, 4, 3, 3)
3
Warning
Averager is deprecated, and no new features will be added. Please use the built-in statistics module for similar functionality and more.
Installation¶
Averager is available on PyPI. Install it with your preferred package manager:
$ uv add averager
$ pip install averager
Averager officially supports Python 3.9+.
API reference¶
A simple Python library to calculate averages of values.
- averager.average(*values: float) float | int[source]¶
Calculate an unweighted average.
- Parameters:
values – The values to find the average of
- Returns:
The average of the inputs
Example
>>> average(1, 2, 3) 2
- averager.median(*values: float) float | int[source]¶
Calculate the median, or middle number.
- Parameters:
values – The values to find the median of
- Returns:
The median of the inputs
Examples
>>> median(1, 2, 3) 2
>>> median(1, 2, 3, 4) 2.5
- averager.mode(*values: float) float | int | set[float | int][source]¶
Calculate the mode, or most common value.
- Parameters:
values – The values to find the mode of
- Returns:
The mode(s) of the inputs (returned as a set if more than one)
Examples
>>> mode(1, 2, 2, 3) 2
>>> mode(1, 1, 2, 2) {1, 2}
- averager.weighted_average(*values: Iterable[float | int]) float | int[source]¶
Calculate a weighted average.
- Parameters:
values – The values to find the average as an iterable of
(value, weight)pairs- Returns:
The weighted average of the inputs
- Raises:
ValueError – If any weight is less than zero
Example
>>> weighted_average((1, 2), (2, 3)) 1.6