Skip to main content

Outlier Tool logo

PyPI version Python versions MIT license Open in Colab

A beginner-friendly Python package for detecting and handling numeric outliers with the IQR and Z-score methods.


Table of contents

✨ Features

  • 🔍 Find outliers in every numeric column with one call
  • 📏 Two detection methods: IQR and Z-score
  • ✂️ Trim (remove rows), 🧢 cap (clip values) or 🔁 replace (mean / median)
  • 🎯 Choose which columns to check
  • 🛡️ Never changes your original DataFrame, because every method returns a new one

📦 Installation

From PyPI (recommended):

python -m pip install outlier-tool-shashikant

From GitHub (latest code):

python -m pip install git+https://github.com/shashikant-ds636/outlier-tool.git

From a wheel file (offline or another device):

python -m pip install outlier_tool_shashikant-0.1.0-py3-none-any.whl

Upgrade to the newest version:

python -m pip install --upgrade outlier-tool-shashikant

Requires Python 3.9+, numpy and pandas (installed automatically).

🚀 Use it in Google Colab

Colab does not keep installed packages between sessions, so run the install cell at the top of your notebook every time.

Step 1. Install (first cell)

!pip install -q outlier-tool-shashikant

Or install the latest code from GitHub:

!pip install -q git+https://github.com/shashikant-ds636/outlier-tool.git

Step 2. Import and run (next cell)

import pandas as pd
from outlier_tool import Outliers

# Option A: upload your own CSV
from google.colab import files
uploaded = files.upload()
df = pd.read_csv(next(iter(uploaded)))

# Option B: read from Google Drive
# from google.colab import drive
# drive.mount("/content/drive")
# df = pd.read_csv("/content/drive/MyDrive/your_file.csv")

o = Outliers(df)
print(o.find("iqr"))
df_clean = o.iqr_cap()
df_clean.head()

No data handy? Try this copy-paste demo:

import pandas as pd
from outlier_tool import Outliers

df = pd.DataFrame({
    "price": [10, 12, 11, 13, 12, 14, 11, 500],
    "age":   [21, 22, 23, 24, 25, 26, 27, 28],
})

o = Outliers(df)
print(o.find("iqr"))       # shows 1 outlier in "price"
print(o.iqr_cap())         # 500 is capped to the upper limit

If Colab says ModuleNotFoundError, run the install cell again, then Runtime → Restart session and re-run your cells.

⚡ Quick start

import pandas as pd
from outlier_tool import Outliers

df = pd.read_csv("data.csv")
o = Outliers(df)                       # or Outliers(df, columns=["price", "age"])

print(o.find("iqr"))                   # summary table
print(o.find("zscore"))

df1 = o.iqr_trim()                     # remove rows
df2 = o.iqr_cap()                      # cap values
df3 = o.zscore_trim(limit=3)
df4 = o.zscore_cap(limit=2.5)
df5 = o.replace_with_mean("iqr")
df6 = o.replace_with_median("zscore")

For the demo data above, find("iqr") returns:

column method lower upper outliers percent
price iqr 7.625 16.625 1 12.5
age iqr 17.5 31.5 0 0.0

🧰 Methods

Method What it does
Outliers(df, columns=None) Create the tool. columns limits which columns are checked
find(method="iqr", threshold=None) Summary of outliers per column ("iqr" or "zscore")
iqr_trim(factor=1.5) Remove rows with IQR outliers
iqr_cap(factor=1.5) Cap values at the IQR limits
zscore_trim(limit=3) Remove rows with Z-score outliers
zscore_cap(limit=3) Cap values at the Z-score limits
replace_with_mean(method="iqr", threshold=None) Replace outliers with the mean of the non-outliers
replace_with_median(method="iqr", threshold=None) Replace outliers with the median of the non-outliers

📐 How the two methods work

IQR method Z-score method
Idea Uses the middle 50% of the data Uses the mean and standard deviation
Lower limit Q1 - 1.5 × IQR mean - 3 × std
Upper limit Q3 + 1.5 × IQR mean + 3 × std
Best for Skewed data (salary, price, sales) Roughly bell-shaped data
Weakness Can flag many points in small datasets Big outliers inflate the mean and std

Here IQR = Q3 - Q1. A value outside the lower and upper limits is flagged as an outlier.

🧭 Which handling method should I use?

Goal Use Keeps all rows?
Outliers are mistakes and rows are not needed *_trim ❌ No
Real values, but extreme. Keep the rows, limit the impact *_cap ✅ Yes
Want a typical value in place of the outlier replace_with_mean / replace_with_median ✅ Yes

⚠️ Important notes

  • Outliers are not always errors. Look at them before removing them.
  • Trimming removes the whole row if any checked column has an outlier.
  • Every method returns a new DataFrame. Save it, for example df_clean = o.iqr_cap().
  • Missing values (NaN) are never flagged as outliers.
  • Constant columns (std = 0) are skipped by the Z-score method.
  • Skip ID columns and 0/1 flag columns with Outliers(df, columns=[...]).
  • For machine learning, calculate the limits on the training data only to avoid data leakage.

👤 Author and license

Made by Shashikant · GitHub · Portfolio

Found a bug or have an idea? Open an issue.

Released under the MIT License.

Metadata

Release files for outlier-tool-shashikant 0.1.1

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

Source distribution (sdist)

Source distribution for outlier-tool-shashikant 0.1.1
File Size Uploaded Provenance Actions
outlier_tool_shashikant-0.1.1.tar.gz 6.2 kB With provenance Details for outlier_tool_shashikant-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for outlier-tool-shashikant 0.1.1
File Interpreter ABI Platform Actions
outlier_tool_shashikant-0.1.1-py3-none-any.whl Python 3 none any Details for outlier_tool_shashikant-0.1.1-py3-none-any.whl

Total release size: 12.0 kB

Release files / outlier_tool_shashikant-0.1.1.tar.gz

Download URL outlier_tool_shashikant-0.1.1.tar.gz
Size 6.2 kB
Tags Source
SHA-256 checksum
How to use checksums
6b667ece72c0f5f887f5ca54dc623456cc194135a6f741921bc213cbfd578739
BLAKE2b-256 checksum
How to use checksums
0f76808d6c4baf328e495738448429d8e5e043ed8dbde29d03d64a1b5167fd81
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 22, 2026.

Transparency log

Release files / outlier_tool_shashikant-0.1.1-py3-none-any.whl

Download URL outlier_tool_shashikant-0.1.1-py3-none-any.whl
Size 5.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
36e0f0179c3012822060302b3edaf445083e87c38f5e38cc5c0f53679363ae48
BLAKE2b-256 checksum
How to use checksums
e0f2a1b039a9669b47cdff53ac900f32d4ce2ec1ebe68dfb1259a47ab8e9fabd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 22, 2026.

Transparency log

Security for outlier-tool-shashikant 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.

Select from 2 files

Attestation for outlier_tool_shashikant-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 22, 2026.

Transparency log

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.

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