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 in pandas DataFrames and Series, 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/elements), 🧢 cap (clip values) or 🔁 replace (mean / median)
  • 🎯 Choose which columns to check
  • 🧬 Works on a whole DataFrame or a single Series (e.g. df["price"])
  • 🛡️ Never changes your original data, because every method returns a new DataFrame or Series

📦 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

🧍 Using a single column (Series)

Pass a pandas.Series directly — no need to wrap it in a DataFrame first:

import pandas as pd
from outlier_tool import Outliers

price = df["price"]

o = Outliers(price)
print(o.find("iqr"))              # one-row report for this Series
capped_price = o.iqr_cap()        # -> pandas.Series
trimmed_price = o.iqr_trim()      # -> pandas.Series
zscore_price = o.zscore_cap()     # -> pandas.Series
  • Every detection and handling method works the same way as for a DataFrame.
  • Handling methods return a Series (not a DataFrame), keeping its original name.
  • Trimming keeps the original index labels of the retained elements.
  • The input Series itself is never modified.
  • columns= is not used with Series input (there is only one column).

🧰 Methods

Method What it does
Outliers(data, columns=None) Create the tool from a DataFrame or Series. columns (DataFrame only) 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

Return types: find() always returns a DataFrame (a report). Every handling method (*_trim, *_cap, replace_with_mean, replace_with_median) returns a DataFrame when constructed from a DataFrame, and a Series when constructed from a Series.

🚫 What it does and does not do

This is a small, focused outlier utility — not a general data-cleaning or preprocessing framework. It does:

  • Detect outliers with the IQR or Z-score method.
  • Trim, cap, or replace (mean/median) detected outliers.
  • Work on numeric DataFrame columns or a single numeric Series.

It does not automatically:

  • Impute or report missing values (NaN).
  • Detect or correct skewness.
  • Detect, encode, or drop categorical/non-numeric columns.
  • Scale, normalize, or otherwise preprocess features for machine learning.

Inspect your data, handle missing values, and choose the appropriate numeric columns yourself before using this package.

📐 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 — they can be real, extreme values. Look at them in context before removing them.
  • For a DataFrame, trimming removes the whole row if any checked column has an outlier. For a Series, only the outlier elements are removed.
  • Every method returns a new DataFrame or Series — your original data is never modified. Save the result, 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=[...]), or pick a single Outliers(df["col"]) Series instead.
  • 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.2.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 outlier-tool-shashikant 0.2.0
File Size Uploaded Provenance Actions
outlier_tool_shashikant-0.2.0.tar.gz 8.0 kB With provenance Details for outlier_tool_shashikant-0.2.0.tar.gz

Built distribution (wheel)

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

Total release size: 14.9 kB

Release files / outlier_tool_shashikant-0.2.0.tar.gz

Download URL outlier_tool_shashikant-0.2.0.tar.gz
Size 8.0 kB
Tags Source
SHA-256 checksum
How to use checksums
1b70ebb68010f0ed63b978a53072a18d90539c798af4ea483f6dc4db65b60284
BLAKE2b-256 checksum
How to use checksums
c23276b58172cb6ac42dc38a5a015735b5ee474436df289924a60842fa25284a
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 29, 2026.

Transparency log

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

Download URL outlier_tool_shashikant-0.2.0-py3-none-any.whl
Size 6.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d1679ab0b73852f2809916b810a1101afd40b58f5635fc6d141fb97464a94cd0
BLAKE2b-256 checksum
How to use checksums
3efd6b7079c349ac2ef899c0d013b37baef05f4064e7536564c7ffa0978f08a8
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 29, 2026.

Transparency log

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

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for outlier_tool_shashikant-0.2.0.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 29, 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