Skip to main content

No project description provided

Project description


Weightipy is a cut down version of Quantipy for weighting people data using the RIM (raking) algorithm.

Weightipy for Python 3

This repository is a modified version of Quantipy3, that only contains the RIM weighting algorithm of Quantipy3.




pip install weightipy


python3 -m pip install weightipy

Note that the package is called weightipy on pip.

Create a virtual envirionment

If you want to create a virtual environment when using Weightipy:


conda create -n envwp python=3

with venv

python -m venv [your_env_name]

5-minutes to Weightipy

Get started


If your data hasn't been weighted yet, you can use Weightipy's RIM weighting algorithm.

Assuming we have the variables gender and agecat we can weight the dataset with these two variables:

import weightipy as wp

age_targets = {'agecat':{1:5.0, 2:30.0, 3:26.0, 4:19.0, 5:20.0}}
gender_targets = {'gender':{0:49, 1:51}}
scheme = wp.Rim('gender_and_age')
scheme.set_targets(targets=[age_targets, gender_targets])

df_weighted = wp.weight_dataframe(
efficiency = wp.weighting_efficiency(df_weighted["weights"])

Or by using the underlying functions that will give more access to reports etc:


my_df["identity"] = range(len(my_df))
engine = wp.WeightEngine(data=df)
engine.add_scheme(scheme=scheme, key="identity", verbose=False)
df_weighted = engine.dataframe()
col_weights = f"weights_{}"

efficiency = wp.weighting_efficiency(df_weighted[col_weights])


Weight variable       weights_gender_and_age
Weight group                  _default_name_
Weight filter                           None
Total: unweighted                 582.000000
Total: weighted                   582.000000
Weighting efficiency               60.009826
Iterations required                14.000000
Mean weight factor                  1.000000
Minimum weight factor               0.465818
Maximum weight factor               6.187700
Weight factor ratio                13.283522


The test suite for Weightipy can be run with the command

python3 -m pytest tests

But when developing a specific aspect of Weightipy, it might be quicker to run (e.g. for the DataSet)

python3 -m unittest tests.test_rim

Tests for unsupported features are skipped, see here for what tests are supported.

We welcome volunteers and supporters. Please include a test case with any pull request, especially those that run calculations.

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

weightipy-0.1.0.tar.gz (13.6 kB view hashes)

Uploaded source

Built Distribution

weightipy-0.1.0-py3-none-any.whl (12.8 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page