Skip to main content
Help improve PyPI by participating in a 5-minute user interface survey!

Mean, weighted mean, median, weighted median

Project Description

https://travis-ci.org/tinybike/weightedstats.svg?branch=master https://coveralls.io/repos/tinybike/weightedstats/badge.svg?branch=master:target:https://coveralls.io/r/tinybike/weightedstats?branch=master

Python 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.

Release history Release notifications

This version
History Node

0.3

History Node

0.2

History Node

0.1

Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
weightedstats-0.3.tar.gz (3.9 kB) Copy SHA256 hash SHA256 Source None Jan 23, 2015

Supported by

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