A lightweight Python package to discretize numeric values into bins, similar to pandas.cut(), but simpler and more intuitive.
Project description
simplebins
simplebins is a lightweight Python utility that makes it easy to bin numeric values into equal-width intervals.
It supports individual numbers, lists, pandas.Series, and pandas.DataFrames.
🔧 Features
- Works with numbers, lists,
pandas.Series, andpandas.DataFrames - Returns either the bin index, floor, ceiling, midpoint, or a human-readable label
- Clean and intuitive API
- Handles missing values gracefully
- Zero dependencies outside of
pandasandnumpy
❓ Why not pandas.cut()?
pandas.cut() is powerful but sometimes overkill.
simplebins simplifies the common use case: fixed-width bins with predictable, numeric output – perfect for quick transformations.
🚀 Installation
pip install simplebins
📦 Usage
from simplebins import cut
Bin a single number
cut(12, binwidth=5)
# Output: 10
Bin a list of numbers
cut([3, 7, 12], binwidth=5)
# Output: [0, 5, 10]
Bin a pandas Series
import pandas as pd
cut(pd.Series([3, 7, 12]), binwidth=5, output="label")
# Output:
# 0 0 <= x < 5
# 1 5 <= x < 10
# 2 10 <= x < 15
# dtype: object
Bin a DataFrame column-wise
df = pd.DataFrame({"age": [21, 34, 65], "income": [2000, 3120, 4190]})
cut(df, binwidth=10)
🛠 Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
x |
number, list, Series, DataFrame | – | Input data to bin |
binwidth |
float |
– | Width of each bin (must be > 0) |
origin |
float |
0 |
Starting point for bins |
output |
str |
"floor" |
One of: "index", "floor", "ceiling", "center", "label" |
Project details
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 simplebins-0.1.0.tar.gz.
File metadata
- Download URL: simplebins-0.1.0.tar.gz
- Upload date:
- Size: 2.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.2 CPython/3.13.3 Darwin/24.4.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bb5624cc79b3745bf253bcc0f5777808aee4f08b220f40fa06aedef88b615825
|
|
| MD5 |
f161431025879f31e2b9b76cef43ac4e
|
|
| BLAKE2b-256 |
3c7b05b985bd8c83f8aaabec7ee241602e72a36de65d76a885bd6964ab848472
|
File details
Details for the file simplebins-0.1.0-py3-none-any.whl.
File metadata
- Download URL: simplebins-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.2 CPython/3.13.3 Darwin/24.4.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3d0cc22c1e92775a87865a465f5fcafa8c27a1954e428ede4dcb2b2bd27d7bad
|
|
| MD5 |
4511de2c13320a0ed9f1c4a228cd3aa4
|
|
| BLAKE2b-256 |
802c77e4c79c16d52dde2eb7d6404ff5e65bb88074fde378572af3e770f53b49
|