Skip to main content

GroupImputer

Tests

Fill missing values using the average of similar rows, instead of one flat value for the entire column.

Standard pandas.fillna(mean) fills every missing value with the same number — even if a "Sales" salary and a "Tech" salary have nothing in common. GroupImputer fills each missing value using the average for its own group (e.g. its department), with a safe fallback when a group has no data at all.

Installation

pip install imputekit

Quick Start

import pandas as pd
from imputekit import GroupImputer

df = pd.DataFrame({
    "Department": ["Sales", "Sales", "Sales", "Tech", "Tech", "Tech"],
    "Salary":     [60000,   45000,   None,    50000,  90000,  None],
})

filler = GroupImputer(group_by="Department", target="Salary")
df_filled = filler.fit_transform(df)

print(df_filled)
print(filler.report())

Output:

Imputation Report
-----------------
Target column          : Salary
Grouped by              : Department
Statistic used          : mean
Missing values filled   : 2
  filled by group avg   : 2
  filled by fallback    : 0
Already present values  : 4

How It Works

  1. fit() groups the data by the column(s) you specify and computes the mean, median, or mode of the target column for each group.
  2. transform() fills each missing value using its group's statistic.
  3. If a group has no valid data at all, it falls back to the overall column statistic instead of leaving the value empty.
  4. report() tells you exactly how many values were filled, and by which method — so nothing happens silently.

API

GroupImputer(group_by, target, strategy="mean")
  • group_by: a column name, or list of column names, to group by
  • target: the column containing missing values to fill
  • strategy: "mean", "median", or "mode"

Methods: .fit(df), .transform(df), .fit_transform(df), .report()

Why not just use df.groupby(...).transform(...)?

You can! For a single quick fix, plain pandas is fine. GroupImputer is useful when you want the fallback safety net, multiple group columns, and a clear report of what was filled and how — without rewriting that logic every time.

License

MIT

Metadata

Release files for imputekit 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for imputekit 0.1.0
File Size Uploaded Provenance
imputekit-0.1.0.tar.gz 6.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for imputekit 0.1.0
File Interpreter ABI Platform
imputekit-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 12.2 kB

Release files / imputekit-0.1.0.tar.gz

Download URL imputekit-0.1.0.tar.gz
Size 6.3 kB
Tags Source
SHA-256 checksum
How to use checksums
36b92114b2b3b23e4fb7b6c0ff644c4c3a91731ceb721a39442d7097a3fdfdcd
BLAKE2b-256 checksum
How to use checksums
adeb5c0653ce76824395969472493f914e4923c1ca2d1fa07d7c79d8845ee92c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.9

Release files / imputekit-0.1.0-py3-none-any.whl

Download URL imputekit-0.1.0-py3-none-any.whl
Size 5.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a632ca20541ce5531919218f549fa6436184c917eb284633f5e841d5f864212a
BLAKE2b-256 checksum
How to use checksums
99d218d1916649557936013528c9c8eaad90a71d5cd783344db42f03e7730456
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.9

Security for imputekit 0.1.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page