Fill missing values using group-wise statistics instead of one flat column average.
Project description
GroupImputer
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
fit()groups the data by the column(s) you specify and computes the mean, median, or mode of the target column for each group.transform()fills each missing value using its group's statistic.- If a group has no valid data at all, it falls back to the overall column statistic instead of leaving the value empty.
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 bytarget: the column containing missing values to fillstrategy:"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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file imputekit-0.1.0.tar.gz.
File metadata
- Download URL: imputekit-0.1.0.tar.gz
- Upload date:
- Size: 6.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
36b92114b2b3b23e4fb7b6c0ff644c4c3a91731ceb721a39442d7097a3fdfdcd
|
|
| MD5 |
d8a0f3511034ab5eca98682f06cb65d8
|
|
| BLAKE2b-256 |
adeb5c0653ce76824395969472493f914e4923c1ca2d1fa07d7c79d8845ee92c
|
File details
Details for the file imputekit-0.1.0-py3-none-any.whl.
File metadata
- Download URL: imputekit-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a632ca20541ce5531919218f549fa6436184c917eb284633f5e841d5f864212a
|
|
| MD5 |
01262fed44aec9ac92ef8174247dc722
|
|
| BLAKE2b-256 |
99d218d1916649557936013528c9c8eaad90a71d5cd783344db42f03e7730456
|