Skip to main content

Simple statistics module

Project description

Python 3.7+ Latest version released on PyPI Tests coverage Package license

amtStats is a Python 3 package that provides a very simplistic statistics on a dataset. It does not require the use of Numpy.

The following statistics are available:
  • min
  • max
  • sum
  • count
  • mean
  • median
  • stddev
  • quantile: Q1, Q3, InterQuantile Range (IQR)
  • percentiles: 10th, 30th, 50th, 70th, 90th, 95th, 97th and 99th

Basic Usage

Install with pip:

pip install amtstats

Import the Statistics class in your python code and then instantiate it.

from amtStats import Statistics
myStats = Statistics()

Use update to add numbers (int or float) to the data set.

# add some integer numbers
for i in range(100):
    myStats.update(random.randint(1, 1000))

# and some float
for i in range(50):

Use compute to compute the statistics for the dataset. The result is returned as a Python dictionary (dict).

results = myStats.compute()
mean = results['mean']

The mean, median and percentiles are rounded to the 3rd decimal. The standard deviation (stddev) is rounded to the 7th decimal.


The algorithm used to compute the percentiles is compatible with Numpy. They give the same results over the same dataset.

It uses a Linear Interpolation between adjacent ranks so the results might not be part of the dataset. This is different from the Near Rank algorithm where all the values are part of the dataset. See Wikipedia (Percentiles) for details.

To access the value for a particular percentile, the characters ‘th’ should be added to the value:

# retrieve the 10th and 50th percentiles
x10 = results['10th']
x50 = results['50th']

Changing the percentiles

The list of percentiles can be changed before invoking the compute function.
The function percentiles takes a list of integer values that represents the new values to be calculated at the next call for compute.
It will return the previous list of percentiles in case it has to be reinstated later.
new_list = [5, 15, 25, 35, 45]
old_list = myStats.percentiles(new_list)

results = myStats.compute()


Run tests:

$ tox


This package is released under the Apache License 2.0. See the bundled LICENSE file for details.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for amtStats, version 1.1.0
Filename, size File type Python version Upload date Hashes
Filename, size amtStats-1.1.0-py3-none-any.whl (9.0 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size amtStats-1.1.0.tar.gz (4.9 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page