Skip to main content

Mean, weighted mean, median, weighted median

Project description

https://travis-ci.org/tensorjack/weightedstats.svg?branch=master https://coveralls.io/repos/tensorjack/weightedstats/badge.png https://badge.fury.io/py/weightedstats.svg

A small Python module with functions to calculate the mean, weighted mean, median, and weighted median.

Installation

The easiest way to install WeightedStats is to use pip:

$ pip install weightedstats

Usage

WeightedStats includes four functions (mean, weighted_mean, median, weighted_median) which accept lists as arguments, and two functions (numpy_weighted_mean, numpy weighted_median) which accept either lists or numpy arrays.

Example:

import weightedstats as ws

my_data = [1, 2, 3, 4, 5]
my_weights = [10, 1, 1, 1, 9]

# Ordinary (unweighted) mean and median
ws.mean(my_data)    # equivalent to ws.weighted_mean(my_data)
ws.median(my_data)  # equivalent to ws.weighted_median(my_data)

# Weighted mean and median
ws.weighted_mean(my_data, weights=my_weights)
ws.weighted_median(my_data, weights=my_weights)

# Special weighted mean and median functions for use with numpy arrays
ws.numpy_weighted_mean(my_data, weights=my_weights)
ws.numpy_weighted_median(my_data, weights=my_weights)

Tests

Unit tests are in the test/ directory.

Project details


Download files

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

Source Distribution

weightedstats-0.2.tar.gz (3.9 kB view details)

Uploaded Source

File details

Details for the file weightedstats-0.2.tar.gz.

File metadata

  • Download URL: weightedstats-0.2.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for weightedstats-0.2.tar.gz
Algorithm Hash digest
SHA256 a1d8d34d924dd73142af84b4095b6bb8c63681e9511d17074f6979058ebedc84
MD5 72e5194b4d07a90b0cf82b18da0e58e3
BLAKE2b-256 d29285c4033356dc1bca52920cdc2c5a00d79b0e83b8424013def47051f8b488

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page