WeightedPandas
WeightedPandas extends pandas Series and DataFrame classes to support weighted operations. It provides drop-in replacements for pandas objects that automatically handle weights in statistical operations.
Installation
pip install weightedpandas
Requirements
- Python 3.8+
- pandas 1.4.0+
- numpy 1.20.0+
Features
- Weighted versions of common statistical operations:
sum(),mean(),var(),std()median(),quantile()corr(),cov()
- Preserves weights through arithmetic operations
- Familiar pandas interface
- Supports both Series and DataFrame objects
Usage
import pandas as pd
import numpy as np
from weightedpandas import WeightedSeries, WeightedDataFrame
# Create a weighted series
data = [1, 2, 3, 4, 5]
weights = [5, 4, 3, 2, 1]
ws = WeightedSeries(data, weights=weights)
# Calculate weighted statistics
print(f"Weighted sum: {ws.sum()}")
print(f"Weighted mean: {ws.mean()}")
print(f"Weighted median: {ws.median()}")
print(f"Weighted standard deviation: {ws.std()}")
# Create a weighted dataframe
df_data = {
'A': [1, 2, 3, 4, 5],
'B': [5, 4, 3, 2, 1]
}
wdf = WeightedDataFrame(df_data, weights=weights)
# Calculate weighted statistics
print(wdf.sum())
print(wdf.mean())
print(wdf.corr())
# Weights are preserved through operations
ws2 = ws * 2 + 1
print(ws2.weights) # Same as original weights
How Weights are Applied
In weighted calculations:
sum(): Each value is multiplied by its weight before summingmean(): The weighted sum divided by the sum of weightsvar()andstd(): Each squared deviation is weightedquantile(): The quantile is determined from the weighted cumulative distribution
Helper Functions
For convenience, you can use the following helper functions:
from weightedpandas import weighted_series, weighted_dataframe
# These are equivalent to the constructor calls
ws = weighted_series(data, weights=weights)
wdf = weighted_dataframe(df_data, weights=weights)
License
This project is licensed under the MIT License - see the LICENSE file for details.
Metadata
Release files for weightedpandas 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| weightedpandas-0.1.1.tar.gz | 6.9 kB | With provenance | Details for weightedpandas-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| weightedpandas-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for weightedpandas-0.1.1-py3-none-any.whl |
Total release size: 12.9 kB
Release files / weightedpandas-0.1.1.tar.gz
| Download URL | weightedpandas-0.1.1.tar.gz |
|---|---|
| Size | 6.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e3b740c655694143875b9b1a65e55d7e39b88ba44093c8aacbad289136b0ef00
|
|
BLAKE2b-256 checksum How to use checksums |
f10dd07799016c37120e29cf5de9d9233a85d9c354b68e183c14774e34fee24c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 12, 2026.
Transparency logRelease files / weightedpandas-0.1.1-py3-none-any.whl
| Download URL | weightedpandas-0.1.1-py3-none-any.whl |
|---|---|
| Size | 6.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
978bd6ae295974b058420f94503dd1ac1b3090aa5f78924054ac8154334e9ba8
|
|
BLAKE2b-256 checksum How to use checksums |
e187721a9bee9dbeb04f125ae2f0dc6e062a959b125f14c7125202271246796c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 12, 2026.
Transparency logSecurity for weightedpandas 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for weightedpandas-0.1.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 12, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.